Part 2

advertisement
CS4025 Practical 4 – hints and answers
Some students got most of this done, but many were quite slow and didn’t get very
far. Issues that arose:


the notation for rules with empty RHSs
how to debug a grammar if a sentence fails to parse? (answer: use prp/2 to try
the individual phrases that should have worked)
Part 1: Hand parsing
1.
(S (NP (Name John))
(VP
(Verb deletes)
(NP
(Det his)
(Noun directory)
)
)
)
2.
(S (NP (Name Peter))
(VP
(Verb renames)
(NP
(Det the)
(Noun file)
)
(PP
(Prep to)
(NP (Name test.dat))
)
)
)
3.
(S (NP (Name John))
(VP
(Verb prints)
(NP
(Det the)
(Noun file)
(Name important.txt)
)
)
)
4-8. Example sentences might be:
Susan deletes the file
John deletes the applet
John lists the directory
John deletes many file
(NB the grammar accepts this. The grammar needs
some plural nouns for a good example)
John deletes the file for Peter
9. The grammar does not allow a VP consisting of just a verb
10. Every sentence must start with an NP, which cannot be empty
11. “sends” is not in the lexicon
Part 2
Students may need to be reminded about the need to call clearrules.
Part 3
The answers are all in soln3.pl, but here they are again:
%% CHANGE (3a): allow adjs after the determiner
np(Number) ---> det(Number), adj, noun(Number).
np(Number) ---> det(Number), adj, noun(Number), name.
%% CHANGE (3b): allow a PP after an NP
%% This will cause an infinite loop if left_corner parsing is not
enabled!
np(Number) ---> np(Number), pp.
%% CHANGE (3c): NP and VP must agree in number
s ---> np(Number), vp(Number).
%% NPs can be names or Det Noun sequences
%% CHANGE (3c): names are always singular in number
np(singular) ---> name.
%% CHANGE (3c): make determiner and noun agree in number
np(Number) ---> det(Number), noun(Number).
np(Number) ---> det(Number), noun(Number), name.
%% CHANGE (3c): VP number comes from verb number
vp(Number) ---> tran_verb(Number,_), np(_).
vp(Number) ---> tran_verb(Number,_), np(_), pp.
vp(Number) ---> bitran_verb(Number,_), np(_).
vp(Number) ---> bitran_verb(Number,_), np(_), pp.
vp(Number) ---> bitran_verb(Number,_), np(_),np(_).
vp(Number) ---> bitran_verb(Number,_), np(_),np(_), pp.
%% VPs are verbs plus NP
(ie, all verbs are assumed to be
transitive)
%% A PP is optional at the end of the VP.
%% CHANGE (3d): distinguish between bitransitive and transitive verbs
%% (change made in the answer to 3c)
Part 4
Answers are in soln4.pl, but here they are again:
4a.
%% CHANGE: replace (bi)tran_verb by (bi)tran_verbgroup
vp(Number) ---> tran_verbgroup(Number), np(_).
vp(Number) ---> tran_verbgroup(Number), np(_), pp.
vp(Number) ---> bitran_verbgroup(Number), np(_).
vp(Number) ---> bitran_verbgroup(Number), np(_), pp.
vp(Number) ---> bitran_verbgroup(Number), np(_),np(_).
vp(Number) ---> bitran_verbgroup(Number), np(_),np(_), pp.
%% CHANGE: Define (bi)tran_verbgroup
%% Different possibilities for a tran_verbgroup
tran_verbgroup(Number) ---> tran_verb(Number, present).
tran_verbgroup(Number) ---> tran_verb(Number, past).
tran_verbgroup(_) ---> [will], tran_verb(infinitive).
%%
%% Different possibilities for a bitran_verbgroup
bitran_verbgroup(Number) ---> bitran_verb(Number, present).
bitran_verbgroup(Number) ---> bitran_verb(Number, past).
bitran_verbgroup(_) ---> [will], bitran_verb(infinitive).
4b.
%% CHANGE: Add "be"
%% "be"
tran_verb(singular, present) --->
tran_verb(plural, present) --->
tran_verb(singular, past) --->
tran_verb(plural, past) --->
tran_verb(infinitive) --->
[is].
[are].
[was].
[were].
[be].
Download