Wednesday, May 4, 2011

PARSER IN PROLOG

% IT WORKS FOR THE PARTICULAR SENTENCE  " The, dog, barked , at ,the,cow" (give it in list).
% you can write in your own facts to implements the rules given by me.

sentence(A,C):-nounphrase(A,B),verbphrase(B,C).
nounphrase(A,C):-article(A,B),noun(B,C).
verbphrase(A,C):-verb(A,B),prepositionphrase(B,C).
prepositionphrase(A,C):-preposition(A,B),nounphrase(B,C).

preposition([at|X],X).
article([a|X],X).
article([the|X],X).
noun([dog|X],X).
noun([cow|X],X).
noun([moon|X],X).
verb([barked|X],X).
verb([wrinked|X],X).

No comments:

Post a Comment