-
Notifications
You must be signed in to change notification settings - Fork 0
/
charlow_2014.pl
88 lines (70 loc) · 1.96 KB
/
charlow_2014.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
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
% static semantics
beta_reduce(lambda(Var: InType, Scope: OutType): (InType->OutType),
Var: InType,
Scope: OutType).
denotes(pn(Name), Name: e).
denotes(n(Noun), lambda(X: e, NofX: t): (e->t)) :- NofX =.. [Noun, X].
denotes(vi(Verb), lambda(X: e, VofX: t): (e->t)) :- VofX =.. [Verb, X].
denotes(vt(Verb), lambda(Y: e, lambda(X: e, Scope: t): (e->t)): (e->(e->t))) :- Scope =.. [Verb, X, Y].
% alternative semantics
denotes(indef(Pred), A:IT) :-
denotes(Pred, lambda(X:IT, Scope:OT): (IT->OT)),
findall(X, Scope, Alts),
member(A, Alts).
% dynamic semantics
denotes_s(Node, Denot) --> {denotes(Node, Denot)}.
denotes_s(dref(Node), Denot, S0, [Denot|S1]) :- denotes_s(Node, Denot, S0, S1).
denotes_s(pro(Index), X, S, S) :- nth0(Index, S, X).
denotes_s(s(L, and, R), (DL, DR):t) --> {L =.. [s|_], R =.. [s|_]}, denotes_s(L, DL:t), denotes_s(R, DR:t).
denotes_s(Node, Denot) -->
{Node =.. [Root, L, R]},
denotes_s(L, DL),
denotes_s(R, DR),
{(beta_reduce(DL, DR, Denot) ; beta_reduce(DR, DL, Denot))}.
% model
man(X) :- member(X, [john, bill]).
woman(X) :- member(X, [mary, sally]).
came_in(X) :- member(X, [john, bill, mary]).
sat_down(X) :- member(X, [john, sally]).
saw(john, mary).
saw(bill, mary).
saw(mary, john).
greeted(john, mary).
% check if true/false on the model
truth(D:t) :- call(D).
% sample queries
q0(D, S) :- denotes_s(s(dref(pn(john)), vp(vt(saw), pro(1))), Denot, [mary:e], S).
q1(D, S) :- denotes_s(
s(
s(
dref(pn(john)),
vp(
vt(saw),
dref(pn(mary)))),
and,
s(
pro(1),
vp(
vt(greeted),
pro(0)))),
D, [], S).
q2(D, S) :- denotes_s(
s(
s(
dref(indef(n(man))),
vi(came_in)),
and,
s(
pro(0),
vi(sat_down))),
D, [], S).
q3(D, S) :- denotes_s(
s(
s(
dref(indef(n(woman))),
vi(came_in)),
and,
s(
pro(0),
vi(sat_down))),
D, [], S).