/* NFST1.PL	 A nondeterministic finite-state transducer 		*/
/*		 to relate English-like phoneme strings to spellings	*/

accept(OrthString,PhonString):- 
	move(s1,OrthString,PhonString,[],[]), 
	write(OrthString), write(' '), write(PhonString), nl.

move(State1,Orth,Phon,[],[]):-
	transition(State1,Orth:Phon,end).
move(State1,Orth,Phon,OrthRem,PhonRem):-
	transition(State1,OrthSym:PhonSym,State2),
	append(OrthSym,OrthRest,Orth),
	append(PhonSym,PhonRest,Phon),
	move(State2,OrthRest,PhonRest,OrthRem,PhonRem).

/* Enumerate all acceptable strings */

loop:- accept(A,B), fail.	

transition(s1,[s]:[s],s2).
transition(s1,[p]:[p],s3).
transition(s1,[t]:[t],s3).
transition(s1,[c]:[k],s3).
transition(s1,[b]:[b],s3).
transition(s1,[d]:[d],s3).
transition(s1,[g]:[g],s3).
transition(s1,[f]:[f],s3).
transition(s1,[p,h]:[f],s3).
transition(s1,[t,h]:['T'],s3).
transition(s1,[s,h]:['S'],s3).
transition(s1,[p]:[p],s4).
transition(s1,[t]:[t],s4).
transition(s1,[c]:[k],s4).
transition(s1,[k]:[k],s4).
transition(s1,[b]:[b],s4).
transition(s1,[d]:[d],s4).
transition(s1,[g]:[g],s4).
transition(s1,[g,u]:[g],s4).
transition(s1,[f]:[f],s4).
transition(s1,[p,h]:[f],s4).
transition(s1,[v]:[v],s4).
transition(s1,[s]:[s],s4).
transition(s1,[c]:[s],s4).
transition(s1,[p,s]:[s],s4).
transition(s1,[t,h]:['T'],s4).
transition(s1,[t,h]:['D'],s4).
transition(s1,[s,h]:['S'],s4).
transition(s1,[h]:[h],s4).
transition(s1,[c,h]:['C'],s4).
transition(s1,[j]:['J'],s4).
transition(s1,[g]:['J'],s4).
transition(s1,[r]:[r],s4).
transition(s1,[w,r]:[r],s4).
transition(s1,[l]:[l],s4).
transition(s1,[w]:[w],s4).
transition(s1,[w,h]:[w],s4).
transition(s1,[y]:[j],s4).
transition(s1,[m]:[m],s4).
transition(s1,[n]:[n],s4).
transition(s1,[k,n]:[n],s4).
transition(s1,[q,u]:[k,w],s4).
transition(s1,[]:[],s4).
transition(s2,[p]:[p],s3).
transition(s2,[t]:[t],s3).
transition(s2,[c]:[k],s3).
transition(s2,[k]:[k],s3).
transition(s2,[p]:[p],s4).
transition(s2,[t]:[t],s4).
transition(s2,[c]:[k],s4).
transition(s2,[k]:[k],s4).
transition(s2,[m]:[m],s4).
transition(s2,[n]:[n],s4).
transition(s2,[l]:[l],s4).
transition(s2,[w]:[w],s4).
transition(s2,[p,h]:[f],s4).
transition(s2,[q,u]:[k,w],s4).
transition(s3,[r]:[r],s4).
transition(s3,[l]:[l],s4).
transition(s3,[w]:[w],s4).
transition(s3,[]:[],s4).
transition(s3,[u,e]:[j,u],s7).
transition(s4,[i]:['I'],s5).
transition(s4,[e]:[e],s5).
transition(s4,[a]:['&'],s5).
transition(s4,[u]:['V'],s5).
transition(s4,[o]:['0'],s5).
transition(s4,[u]:['U'],s5).
transition(s4,[o,o]:['U'],s5).
transition(s4,[a,i]:[e,'I'],s7).
transition(s4,[a,y]:[e,'I'],s7).
transition(s4,[a]:[e,'I'],s7).
transition(s4,[a,r]:['A'],s7).
transition(s4,[a,i,r]:[e,'@'],s7).
transition(s4,[e,a]:[i],s7).
transition(s4,[e,e]:[i],s7).
transition(s4,[e,a,r]:['I','@'],s7).
transition(s4,[e,e,r]:['I','@'],s7).
transition(s4,[e,r]:['3'],s7).
transition(s4,[i,r]:['3'],s7).
transition(s4,[u,r]:['3'],s7).
transition(s4,[o,r]:['O'],s7).
transition(s4,[a,u]:['O'],s7).
transition(s4,[a,w]:['O'],s7).
transition(s4,[u]:[u],s7).
transition(s4,[o,o]:[u],s7).
transition(s4,[o]:['@','U'],s7).
transition(s4,[o,a]:['@','U'],s7).
transition(s4,[o,w]:['@','U'],s7).
transition(s4,[o,u]:[a,'U'],s7).
transition(s4,[o,w]:[a,'U'],s7).
transition(s4,[o,u,r]:['U','@'],s7).
transition(s4,[o,y]:[o,'I'],s7).
transition(s4,[o,i]:[o,'I'],s7).
transition(s4,[i,e]:[a,'I'],s7).
transition(s4,[y]:[a,'I'],s7).
transition(s4,[e,w]:[j,u],s7).
transition(s5,[d]:[d],s6).
transition(s5,[l]:[l],s8).
transition(s5,[m]:[m],s8).
transition(s5,[n]:[n],s8).
transition(s5,[n,g]:['N'],s8).
transition(s5,[b]:[b],s9).
transition(s5,[g]:[g],s9).
transition(s5,[t,h]:['D'],s9).
transition(s5,[v,e]:[v],s9).
transition(s5,[l,l]:[l],s9).
transition(s5,[d,g,e]:['J'],s10).
transition(s5,[z]:[z],s10).
transition(s5,[s]:[z],s10).
transition(s5,[p]:[p],s11).
transition(s5,[t]:[t],s11).
transition(s5,[c,k]:[k],s11).
transition(s5,[f]:[f],s11).
transition(s5,[f,f]:[f],s11).
transition(s5,[d]:[d],s11).
transition(s5,[l]:[l],s11).
transition(s5,[n]:[n],s11).
transition(s5,[t,c,h]:['C'],s12).
transition(s5,[s,s]:[s],s12).
transition(s5,[s,h]:['S'],s12).
transition(s5,[x]:[k,s],s12).
transition(s6,[]:[],s9).
transition(s6,[t,h]:['T'],s13).
/* State 7 is an end state if there are no more letters left */
transition(s7,[]:[],end).	
transition(s7,[l]:[l],s8).
transition(s7,[m]:[m],s8).
transition(s7,[n]:[n],s8).
transition(s7,[b]:[b],s9).
transition(s7,[d,e]:[d],s9).
transition(s7,[e,d]:[d],s9).
transition(s7,[d]:[d],s9).
transition(s7,[g,u,e]:[g],s9).
transition(s7,[v,e]:[v],s9).
transition(s7,[t,h,e]:['D'],s9).
transition(s7,[g,e]:['J'],s10).
transition(s7,[s,e]:[z],s10).
transition(s7,[e,s]:[z],s10).
transition(s7,[z,e]:[z],s10).
transition(s7,[g,e]:['Z'],s10).
transition(s7,[p]:[p],s11).
transition(s7,[t]:[t],s11).
transition(s7,[k]:[k],s11).
transition(s7,[f]:[f],s11).
transition(s7,[c,h]:['C'],s12).
transition(s7,[c,e]:[s],s12).
transition(s7,[s,h]:['S'],s12).
transition(s7,[t,h]:['T'],s13).
/* State 8 is an end state if there are no more letters left */
transition(s8,[]:[],end).	
transition(s8,[b]:[b],s9).
transition(s8,[d]:[d],s9).
transition(s8,[v,e]:[v],s9).
transition(s8,[]:[],s9).
transition(s8,[g,e]:['J'],s10).
transition(s8,[p]:[p],s11).
transition(s8,[t]:[t],s11).
transition(s8,[k]:[k],s11).
transition(s8,[f]:[f],s11).
transition(s8,[]:[],s11).
transition(s8,[c,h]:['C'],s12).
transition(s8,[s]:[s],s12).
transition(s8,[s,h]:['S'],s12). 
/* State 9 is an end state if there are no more letters left */

transition(s9,[]:[],end).	
transition(s9,[s]:[z],s10).
transition(s9,[]:[],s10).
/* State 10 is an end state if there are no more letters left */
transition(s10,[]:[],end).	
transition(s10,[d]:[d],s14).
/* State 11 is an end state if there are no more letters left */
transition(s11,[]:[],end).	
transition(s11,[s]:[s],s12).
transition(s11,[]:[],s12).
/* State 12 is an end state if there are no more letters left */
transition(s12,[]:[],end).	
transition(s12,[t]:[t],s13).
transition(s12,[t,h]:['T'],s13).
/* State 13 is an end state if there are no more letters left */
transition(s13,[]:[],end).	
transition(s13,[s]:[s],s14).
/* State 14 is an end state if there are no more letters left */
transition(s14,[]:[],end).	

