PPT Slide
Parsing Simple English Sentences
article(a). article(the). adjective(giant). preposition(on). preposition(from). verb(rose). verb(sat). verb(was). noun(cat). noun(rocket). noun(mat). noun(pad).
sentence( X ) :- np( X, R ), vp( R, [ ] ).
np( [X,Y|Z], Z ) :- article( X ), noun( Y ).
vp( [X|Y], R ) :- verb( X ), pp( Y, R ).
pp( [X|Y], Z ) :- preposition( X ), np( Y, Z ).
|?- sentence( [the, cat, sat, on, the, mat] ).
|?- sentence( [the, rocket, was, on, the, pad] ).
|?- sentence( [the, mat, was, on, the, cat] ).
|?- sentence( [the, rocket, rose] ).
|?- sentence( [the, giant, cat, rose, from, the, mat]).