-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-trees.lp
140 lines (98 loc) · 2.59 KB
/
parse-trees.lp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
%% Relating sequences of words to parse trees %%
split(nil, nil, nil).
split(seq(W, Rest), seq(W, Seq1), Seq2)
:- word(W), sequence(Rest), split(Rest, Seq1, Seq2).
split(S, nil, S)
:- sequence(S).
%% Some rules to only consider problems that are subproblems of our input.
sequence(S) :- sequence(seq(W, S)), word(W).
relevant_word(W) :- sequence(seq(W,S)).
% input example:
sequence(seq(they, seq(transform, seq(the, seq(cloud, nil))))).
%% SYNTAX TREES
% Trees are either:
% - expr(nil_pos, leaf)
% - expr(POS, Word)
% - expr(POS, pair(Tree1, Tree2))
%% parse(seq, tree)
% needed?
% parse(nil, expr(nil_pos, leaf)).
parse(seq(Word,nil), expr(POS, Word))
:- relevant_word(Word), pos(Word, POS).
% Parsing determined and undetermined subjects
parse(Seq, expr(dsubj, Expr))
:- parse(Seq, expr(pronoun_subj, Expr)).
parse(Seq, expr(dsubj, pair(expr(det, Det), expr(usubj,Usubj))))
:- split(Seq, DetSeq, UsubjSeq),
parse(DetSeq, expr(det, Det)),
parse(UsubjSeq, expr(usubj, Usubj)).
parse(Seq, expr(usubj, Noun))
:- parse(Seq, expr(noun, Noun)).
% Parsing determined and undetermined objects
parse(Seq, expr(uobj, Noun))
:- parse(Seq, expr(noun, Noun)).
parse(Seq, expr(dobj, Pronoun))
:- parse(Seq, expr(pronoun_obj, Pronoun)).
parse(Seq, expr(dobj, pair(expr(det,Det), expr(uobj,Uobj))))
:- split(Seq, DetSeq, UobjSeq),
parse(DetSeq, expr(det, Det)),
parse(UobjSeq, expr(uobj, Uobj)).
% Parsing verb phrases
parse(Seq, expr(vp, Verb))
:- parse(Seq, expr(vi, Verb)).
parse(Seq, expr(vp, pair(expr(vt,VT), expr(dobj,Dobj))))
:- split(Seq, VTSeq, DobjSeq),
parse(VTSeq, expr(vt, VT)),
parse(DobjSeq, expr(dobj, Dobj)).
% Parsing sentences
parse(Seq, expr(sentence, pair(expr(dsubj,NP),expr(vp,VP))))
:- split(Seq, NPSeq, VPSeq),
parse(NPSeq, expr(dsubj, NP)),
parse(VPSeq, expr(vp, VP)).
% #show sequence/1.
#show parse/2.
#show relevant_word/1.
% #show split/3.
%%%% Word Library %%%%
% Pronouns
word(they).
word(them).
word(their).
pos(they, pronoun_subj).
pos(them, pronoun_obj).
pos(their, det).
% Nouns
word(transformation).
pos(transformation, noun).
word(self).
pos(self, noun).
plural(self, selves).
word(limb).
pos(limb, noun).
plural(limb, limbs).
word(eye).
pos(eye,noun).
plural(eye, eyes).
word(cloud).
pos(cloud, noun).
plural(cloud, clouds).
% Verbs
word(transform).
pos(transform, vt).
word(unfurl).
pos(unfurl, vi).
word(touch).
pos(touch, vt).
word(glow).
pos(glow, vi).
word(flail).
pos(flail, vi).
% Determiners and prepositions
word(the).
pos(the, det).
word(a).
pos(a, det).
word(every).
pos(every, det).
word(into).
pos(into, prep).