-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbottom_up_example.pl
57 lines (52 loc) · 1.16 KB
/
bottom_up_example.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Taken from NLP with prolog from https://cs.union.edu/~striegnk/courses/nlp-with-prolog/html/node94.html#l14.sec.topdown */
/* ?- op(255,xfx,--->). required */
/*lex(robber,N) :- N = [cat:n,num:sg|_].
lex(him,N) :- N = [cat:pro,num:sg,case:acc|_].*/
s ---> [np,vp].
np ---> [pn].
np ---> [pn,rel].
np ---> [det, nbar].
nbar ---> [n].
nbar ---> [n,rel].
rel ---> [wh,vp].
vp ---> [iv].
vp ---> [tv,np].
vp ---> [dv,np,pp].
vp ---> [sv,s].
pp ---> [p,np].
lex(vincent,pn).
lex(mia,pn).
lex(marsellus,pn).
lex(jules,pn).
lex(a,det).
lex(the,det).
lex(her,det).
lex(his,det).
lex(gun,n).
lex(robber,n).
lex(man,n).
lex(woman,n).
lex(who,wh).
lex(that,wh).
lex(to,p).
lex(died,iv).
lex(fell,iv).
lex(loved,tv).
lex(shot,tv).
lex(knew,tv).
lex(gave,dv).
lex(handed,dv).
lex(knew,sv).
lex(believed,sv).
recognize_bottomup([s]).
recognize_bottomup(String) :-
split(String,Front,Middle,Back),
( Cat ---> Middle
;
(Middle = [Word], lex(Word,Cat))
),
append(Front,[Cat|Back],NewString),
recognize_bottomup(NewString).
split(ABC, A, B, C) :-
append(A, BC, ABC),
append(B, C, BC).