Skip to content

Commit cadcd17

Browse files
Do LPN chapter 8 exercise
1 parent 4d34929 commit cadcd17

File tree

1 file changed

+69
-0
lines changed
  • second-year/CS262-Logic-and-Verification/Prolog/LPN

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
% vim :set ft=prolog:
2+
3+
:- module(ch8, []).
4+
5+
s(s(Np, Vp)) --> np(Np, subject, Plur), vp(Vp, Plur).
6+
7+
np(np(Det, N), _Pos, Plur) --> det(Det, Plur), n(N, Plur).
8+
np(np(Pro), Pos, Plur) --> pro(Pro, Pos, Plur).
9+
10+
vp(vp(V, NP), Plur) --> v(V, Plur), np(NP, object, _).
11+
vp(vp(V), Plur) --> v(V, Plur).
12+
13+
det(det(Word), Plur) -->
14+
[Word],
15+
{lex(Word, det, _, Plur)}.
16+
17+
n(n(Word), Plur) -->
18+
[Word],
19+
{lex(Word, noun, _, Plur)}.
20+
21+
pro(pro(Word), Pos, Plur) -->
22+
[Word],
23+
{lex(Word, pronoun, Pos, Plur)}.
24+
25+
v(v(Word), Plur) -->
26+
[Word],
27+
{lex(Word, verb, _, Plur)}.
28+
29+
lex(the, det, _, _).
30+
lex(a, det, _, singular).
31+
32+
lex(man, noun, _, singular).
33+
lex(woman, noun, _, singular).
34+
lex(men, noun, _, plural).
35+
lex(women, noun, _, plural).
36+
lex(apple, noun, _, singular).
37+
lex(apples, noun, _, plural).
38+
lex(pear, noun, _, singular).
39+
lex(pears, noun, _, plural).
40+
41+
lex(he, pronoun, subject, singular).
42+
lex(she, pronoun, subject, singular).
43+
lex(they, pronoun, subject, plural).
44+
lex(it, pronoun, _, singular).
45+
lex(him, pronoun, object, singular).
46+
lex(her, pronoun, object, singular).
47+
lex(them, pronoun, object, plural).
48+
49+
% Plurality applies to subject
50+
lex(shoot, verb, _, plural).
51+
lex(shoots, verb, _, singular).
52+
lex(eat, verb, _, plural).
53+
lex(eats, verb, _, singular).
54+
55+
:- begin_tests(ch8).
56+
57+
test(dcg_plurals, [nondet]) :- s(_, [the, men, eat], []).
58+
test(dcg_plurals, [nondet]) :- s(_, [the, man, eats], []).
59+
test(dcg_plurals, [nondet]) :- s(_, [a, woman, shoots, him], []).
60+
test(dcg_plurals, [nondet]) :- s(_, [they, eat, the, women], []).
61+
test(dcg_plurals, [nondet]) :- s(_, [it, eats], []).
62+
63+
test(dcg_plurals, [fail]) :- s(_, [the, man, eat], []).
64+
test(dcg_plurals, [fail]) :- s(_, [the, men, eats], []).
65+
test(dcg_plurals, [fail]) :- s(_, [a, women, shoots, him], []).
66+
test(dcg_plurals, [fail]) :- s(_, [them, eats, the, women], []).
67+
test(dcg_plurals, [fail]) :- s(_, [it, eat], []).
68+
69+
:- end_tests(ch8).

0 commit comments

Comments
 (0)