First Order Logic with Lambda Calculus
The main task in this lab is to develop and implement a simple context-free grammar coupled with rules for semantic interpretation. An example program looks like this:
s(VP) --> np(NP),vp(NP^VP).
vp(NP^VP) -->v(NP^VP).
np(tom) --> [tom].
np(mary) --> [mary].
v(X^slept(X)) --> [slept].
This grammar basically converts a sentence into its semantic representation which is encoded in first-order logic, e.g. tom slept will become slept(tom). Let us consider the first rule. Syntactically, it says that a sentence (s) may consist of a noun phrase (np) followed by a verb phrase (vp). Each of the syntactic category labels has an argument for the semantic representation associated with the given constituent. Semantically speaking, it indicates that the semantic representation of a sentence is obtained by combining the semantic representation of the noun phrase (NP) with the semantic representation of the verb phrase (VP). The meaning of a proper noun is obvious. The meanings of verbs are represented using lambda expressions. Here, we use the symbol ^ to represent the application of a lambda term to an argument.
In order to test the program, enter the above grammars into a text file, load it to the prolog interpreter and try the following query:
s(R, [tom, slept], []).
Now, change the first example of this tutorial as follows-
test (Q):-
s(R,Q,[]).
s(VP) --> np(NP),vp(NP^VP).
vp(NP^VP) -->v(NP^VP).
np(tom) --> [tom].
np(mary) --> [mary].
v(X^slept(X)) --> [slept].
This will work in the same way. We only changed the way to query our knowledgebase. With this grammar, we have to query as
test(tom,slept).
Try to add more words e.g. talked, barked, ran, fido and max. Generate a semantic representation for fido barked and mary ran.
Extend the above grammar so that it can generate semantic representation for transitive verbs, e.g. mary saw tom, max chased fido.
s(VP)-->np(NP),vp(NP^VP^NP2),np(NP2).
np(tom)-->[tom].
np(mary)-->[mary].
vp(NP^VP^NP2)-->v(NP^VP^NP2).
v(NP^saw(NP,NP2)^NP2)-->[saw].
2. The grammar in part (1) above can be slightly changed so that the simple Yes/NO questions can be parsed. To do this, we replace the sentence rule,
s(VP) --> np(NP),vp(NP^VP).
with one for questions:
s(VP) --> [did],np(NP),vp(NP^VP).
and we add the following ‘plain’ forms of the verbs:
v(X^sleep(X)) --> [sleep].
Now, the question ‘did mary sleep’ can be answered by posing the query:
s(R, [did, mary, sleep], []).
Write a program which will accept and answer the question: Did tom see mary?
s(X)-->[did],np(NP),vp(NP^VP^NP2),np(NP2).
np(tom)-->[tom].
np(mary)-->[mary].
vp(NP^VP^NP2)-->v(NP^VP^NP2).
v(NP^see(NP,NP2)^NP2)-->[see].
No comments:
Post a Comment