Download code

Jump to: navigation, search

Back to Parser_(Prolog)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

parser.pl

 1 
 2 
 3 s   --> np, vp.
 4 np  --> det, n.
 5 vp  --> v, np.
 6 vp  --> v.
 7 det --> [the].
 8 det --> [a].
 9 det --> [dry].
10 n   --> [agent].
11 n   --> [hero].
12 n   --> [martinis].
13 v   --> [likes].
14 v   --> [drinks].
15 
16 
17 recognize(Input) :- s(Input,[]).
18 
19 generate(Sentence) :- s(Sentence,[]).
20 
21 s(s(NP, VP))   --> np(NP), vp(VP).
22 np(np(DET, N)) --> det(DET), n(N).
23 vp(vp(V, NP))  --> v(V), np(NP).
24 vp(vp(V))      --> v(V).
25 det(the)       --> [the].
26 det(a)         --> [a].
27 det(dry)       --> [dry].
28 n(agent)       --> [agent].
29 n(hero)        --> [hero].
30 n(martinis)    --> [martinis].
31 v(likes)       --> [likes].
32 v(drinks)      --> [drinks].
33 
34 parse(Structure, Input) :- s(Structure, Input, []).
35 
36 generate(Structure, Sentence) :- s(Structure, Sentence, []).


hijacker
hijacker
hijacker
hijacker