H

ICS 361, Artificial Intelligence Programming

Assignment 8

In Prolog, write a natural language parser that can parse sentences like "Mary sold John a car", "John sold Mary a computer", "Mary bought a car from John", or "John bought a computer from Mary" into a Conceptual Dependency Prolog list meaning representation. Your program should produde a Prolog list for each of the above sentences. For example, utterance([mary, sold, john, a, car], Meaning) should produce: Meaning = [action([atrans(_1794)]), actor([woman(mary)]), object([car(_1866)]), recipient([man(john)]), donor([woman(mary)])] where the _1794 and _1866 will probably be different numbers. Also utterance([john, bought, a, computer, from, Mary], Meaning) should produce: Meaning = [action([atrans(_5022)]), actor([man(john)]), object([computer(_5033)]), recipient([man(john)]), donor([woman(mary)])].

Include a test run of your program with the test inputs:

test1(Meaning) :- utterance([mary, sold, john, a, car], Meaning).
test2(Meaning) :- utterance([john, sold, mary, a, car], Meaning).
test3(Meaning) :- utterance([john, sold, mary, a, computer], Meaning).
test4(Meaning) :- utterance([mary, sold, john, a, computer], Meaning).
test5(Meaning) :- utterance([mary, bought, a, car, from, john], Meaning).
test6(Meaning) :- utterance([mary, bought, a, computer, from, john], Meaning).
test7(Meaning) :- utterance([john , bought, a, car, from, mary], Meaning).
test8(Meaning) :- utterance([john , bought, a, computer, from, mary], Meaning).

Hints

You should look at the textbook's recursive descent semantic net parser (Chapter 8.6). For "X sold Y Z", try a new verbphrase rule with an extra nounphrase (the left-over words from the first nounphrase is the input words for the second nounphrase and the left-over words from the second nounphrase is the left-over words for the parent verbphrase (the variable End). You will need two join's, one for the object and another for the recipient. For "X bought Y from Z", try a new verbphrase rule that is a verbphrase followed by a prepphrase. Then add a prepphrase rule that is a preposition (prep for short) followed by a nounphrase. It should join the meaning of the preposition, [donor(Noun_phrase_graph)], with the graph from the prepphrase. You can use =.. to create the functor donor(Noun_phrase_graph).

If you borrow code from the textbook, be sure to acknowledge the source of the code with comments marking the start and end of the borrowed code and any changes you made to the borrowed code.

My solution (code only, not including comments or the above test functors) is only 26 lines long, not including the utterance, sentence, nounphrase, verphrase, join, join_frames, join_slot_to_frame, join_slots, isframe, is_slot, match_with_inheritance, and article code taken directly from the textbook.

To save a log of your Prolog session to a file, use the protocol('mylog.txt'). predicate followed by noprotocol.

Submitting

Submit by zipping together your source code file (e.g., a8.pl) and your typescript file (e.g., typescript.txt) into a8.zip and then upload a8.zip to Assignment 8 on Laulima.


David N. Chin / Chin@Hawaii.Edu