Transcript lex—1
Problem 1
The following two slides contain part of the
definition of a data base of English word
forms using the lex/4 predicate. With this
data base as part of your program, answer
questions 1.1 and 1.2.
Martin Kay
Introduction to Prolog
1
lex—1
lex(love, love, n, sing).
lex(love, love, v, base).
lex(loves, love, v, pres(sg, 3)).
lex(loves, love, n, plur).
lex(loving, love, v, pres_part).
lex(loved, love, v, past).
lex(grind, grind, v, base).
lex(grinds, grind, v, pres(sg, 3)).
lex(grinding, grind, v, pres_part).
lex(ground, grind, v, past).
lex(ground, ground, n, sing).
lex(grounds, ground, n, plur).
lex(see, see, v, base).
lex(sees, see, v, pres(sg, 3)).
Martin Kay
Introduction to Prolog
2
lex—2
lex(seeing, see, v, pres_part).
lex(saw, see, v, past_tense(_, _)).
lex(seen, see, v, past_part).
lex(hit, hit, v, short).
lex(hits, hit, v, pres(sg, 3)).
lex(hitting, hit, v, pres_part).
lex(sheep, sheep, n, _).
lex(X, X, v, inf) :lex(X, X, v, base).
lex(X, X, v, base) :lex(X, X, v, pres(sg, 1)) :lex(X, X, v, short).
lex(X, X, v, base).
lex(X, X, v, past) :lex(X, X, v, pres(sg, 3)) :lex(X, X, v, short).
lex(X, X, v, base).
lex(X, X, v, pres(pl, _)) :lex(X, X, v, base).
Martin Kay
Introduction to Prolog
3
Question 1.1
Write a predicate ambiguous(X) that is true just in case X is
a word that can be both a noun and a verb. It should allow
you to do this:
| ?- ambiguous(ground).
yes
| ?- ambiguous(see).
no
| ?- ambiguous(X).
X=love
yes
| ?Martin Kay
Introduction to Prolog
4
Question 1.2
Notice that the verb “see” has a past_tense and a
“past_part” form. The other verbs have only a “past”
form, because there is no difference between their pasttense and past-participle forms. Write two new clauses
which when applied to any verb with a “past” entry in the
data base, will enable the past_tense and past_part forms
to be found. They should make it possible to do at least
this:
| ?- lex(loved, love, v, past_tense).
yes
| ?lex(loved, love, v, past_part).
yes
| ?Martin Kay
Introduction to Prolog
5
Problem 2
reverse([], []).
reverse([H|T], Rev) :reverse(T, RT),
append(RT, [H], Rev).
There is a much more efficient way of
reversing a list than the one given in class.
The trick is to use another predicate, with
three arguments, to do the work, so that
reverse itself is defined like this:
reverse(A, B) :rev (A, [], B).
Write the two-clause definition of rev/3.
Martin Kay
Introduction to Prolog
6
Problem 3
Write a predicate
delete(List1, Member, List2).
which is true just in case List2 is the result
of deleting Member from List1. The
predicate should fail if Member is not a
member of List1.
| ?- delete([a,b,a,c,a,d,a,e], a, X).
X = [b,a,c,a,d,a,e] ? ;
X = [a,b,c,a,d,a,e] ? ;
X = [a,b,a,c,d,a,e] ? ;
X = [a,b,a,c,a,d,e] ? ;
no
| ?Martin Kay
Introduction to Prolog
7