-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfig23_6.pl
63 lines (38 loc) · 1.32 KB
/
fig23_6.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
58
59
60
61
62
63
% Figure 23.6 A DCG handling the syntax and meaning of a small
% subset of natural language.
:- op( 100, xfy, and).
:- op( 150, xfy, =>).
sentence( S) -->
noun_phrase( X, P, S), verb_phrase( X, P).
noun_phrase( X, P, S) -->
determiner( X, P12, P, S), noun( X, P1), rel_clause( X, P1, P12).
noun_phrase( X, P, P) -->
proper_noun( X).
verb_phrase( X, P) -->
trans_verb( X, Y, P1), noun_phrase( Y, P1, P).
verb_phrase( X, P) -->
intrans_verb( X, P).
rel_clause( X, P1, P1 and P2) -->
[that], verb_phrase( X, P2).
rel_clause( X, P1, P1) --> [].
determiner( X, P1, P, all( X, P1 => P)) --> [every].
determiner( X, P1, P, exists( X, P1 and P)) --> [a].
noun( X, man(X)) --> [man].
noun( X, woman(X)) --> [woman].
proper_noun( john) --> [john].
proper_noun( annie) --> [annie].
proper_noun( monet) --> [monet].
trans_verb( X, Y, likes( X, Y)) --> [ likes].
trans_verb( X, Y, admires( X, Y)) --> [admires].
intrans_verb( X, paints(X)) --> [paints].
% Some tests
test1( M) :-
sentence( M, [john,paints],[]).
test2( M) :-
sentence( M, [a, man, paints], []).
test3( M) :-
sentence( M, [every,man,that,paints,admires,monet],[]).
test4( M) :-
sentence( M, [annie,admires,every,man,that,paints],[]).
test5( M) :-
sentence( M, [every,woman,that,admires,a,man,that,paints,likes,monet],[]).