Information Technology Reference
In-Depth Information
Figure 8.14.
A parser for yes/no questions
yesno.pl
yes_no(String) :-
split_words(String,Words), % Get the list of words.
yn(Words).
% Use yn on the words.
yn([Verb|Rest]) :-
Verb=is,
% The first word must be "is".
append(W1,W2,Rest),
% Break the rest into two parts.
np(W1,Ref),
% The first part must be an NP.
np_or_pp(W2,Ref).
% The second part must be an NP or a PP.
np_or_pp(W,Ref) :- np(W,Ref).
np_or_pp(W,Ref) :- pp(W,Ref).
list of words that forms a yes/no question and whose answer is yes. (A predicate for
wh questions is not discussed here.)
A Prolog program for the yn predicate is shown in figure 8.14. It uses append to split
the list of words after the word is into two groups, where the first must be a noun
phrase, and the second is either a noun phrase or a prepositional phrase. It works by
finding a referent for the first group and checking that it can also be a referent for the
second group. The yes_no predicate is similar, except that it takes a quoted string as
its argument. Here are some examples of its use:
?- yes_no('is mary in a park with linda').
Yes
?- yes_no('is the man with the blue hat john').
No
?- yes_no('is the big red hat on the woman beside mary').
Yes
?- yes_no('is a red with a woman hat').
% Ungrammatical
No
Note that this predicate returns success only if the object described by the first noun
phrase is the same as the object described by the second (noun or prepositional)
phrase. So with this predicate one cannot distinguish between a failure (a question
that is ungrammatical or where no referent can be found) and a well-formed question
to which the answer happens to be no.
Search WWH ::




Custom Search