/* Capítulo 1, exemplo (35), pp. 48-49.
Programa fsm03.pl, adaptado do programa recognize1.pl,
de autoria de Patrick Blackburn e Kristina Striegnitz,
disponível na seguinte URL:
http://cs.union.edu/~striegnk/courses/nlp-with-prolog/html/recognize1.pl
*/
:- multifile network/1.
:- multifile arc/4.
:- multifile final/2.
:- multifile initial/1.
:- discontiguous network/1.
:- discontiguous arc/4.
:- discontiguous final/2.
:- discontiguous initial/1.
initial(0).
recognize1(Network,Node,[]) :-
final(Network,Node).
recognize1(Network,Node1,String) :-
arc(Network,Node1,Node2,Label1),
atom_codes(Label2,Label1),
traverse1(Network,Label2,String,NewString),
recognize1(Network,Node2,NewString).
traverse1(Network,Label,[Label|Symbols],Symbols):-
network(Network).
test1(Network,Symbols) :-
initial(Node),
recognize1(Network,Node,Symbols).
generate1(Network,X) :-
test1(Network,X).
testa(Rede,Palavra):- atom_chars(Palavra,Lista),test1(Rede,Lista).
gera(Rede,Palavra) :- generate1(Rede,Lista),atom_chars(Palavra,Lista).
gera2(N):- gera(N,Palavra),write(Palavra),nl,fail.
Nenhum comentário:
Postar um comentário