15 Natural Languages II
Write a Prolog parser according to the method of the Definite Clause Grammar. The following sentences should be recognizes as grammatically correct:
- A man arrived.
- Every woman dances.
- John likes Mary.
- Every man loves a woman.
- Jack is a man.
The top-level predicate is s(Sentence, Tree), where Sentence is a list of words and Tree is the created syntax tree. E.g.
?- s([ a, man, arrived], Tree). ⇒ Tree = . . .
Write a program for a pretty representation of the syntax tree and test it, e.g.:
?- s([ a, man, arrived], Tree), write_tree( Tree).
Extend the parser by an additional semantics component. The semantics of the above mentioned sentences should be correctly generated, e.g.:
s(Sentence, Tree, Sem) :- … ?- s([ a, man, arrived], Tree, Sem). ⇒ Sem = exists(X, man(X), arrived(X))
Implement the predicate declare(Semantics), that stores the generated semantics in the Prolog database under the functor kb/1. You will also need to write a procedure to generate "Discourse Referents (Markers)". Example:
declare(exists(X, man(X), arrived(X))) :- /* generate next marker, e.g. f(3), */ assert(kb(man(f(3))), assert(arrived(f(3))).
Implement the predicate solve(Semantics), that uses the stored semantical facts kb/1 to prove the validity of statements. Example:
?- solve(exists(X, man(X), arrived(X)). ⇒ man(f(3)) arrived(f(3)) X = f(3)
Implement an intelligent dialog with the computer:
If Sentence starts with Who/Does/Did, then it is a question that is passed (without the first word) to the procedure solve for proving.
Otherwise the Sentence is a statement that is passed to the procedure declare that stores it in the Prolog database.
The conversation should look as follows:
?- chat([john, loved, mary]). ?- chat([who, loved, mary]). ⇒ john ?- chat([who, did, john, love]). ⇒ mary ?- chat([every, man, likes, mary]). ?- chat([jack, is, a, man]). ?- chat([mary, is, a, woman]). ?- chat([does, jack, likes, mary]). ⇒ yes