quarta-feira, 8 de agosto de 2012

Programa em Prolog fsm05.pl



/* Capítulo 1, pp. 57 e 58.
Programa fsm05.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/2.
:- discontiguous network/1.
:- discontiguous arc/4.
:- discontiguous final/2.
:- discontiguous initial/2.


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(Network,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