I have this DCG grammar that understand and agree phrases like: [john, paints] and [john, likes, mary] managing the semantic meaning directly into the DCG grammar by the use of parameters
sentence2(VP) --> noun_phrase2(Actor),
verb_phrase2(Actor, VP).
noun_phrase2(Name) --> properName(Name).
verb_phrase2(Actor, VP) --> intrans_verb(Actor, VP).
verb_phrase2(Somebody, VP) --> trans_verb(Somebody, Something, VP),
noun_phrase2(Something).
properName(john) --> [john].
properName(mary) --> [mary].
intrans_verb(Actor, paints(Actor)) --> [paints].
trans_verb(Somebody, Something, likes(Somebody, Something)) --> [likes].
For example the mean of the phrase [john, paints] will be: paints(john), infact this is the result of the query:
?- sentence2(Meaning, [john,paints],[]).
Meaning = paints(john)
Ok, so this handle the meaning without build a parse tree.
I have an exercise that ask me to modify the previous grammar to obtain the mean from the syntattic tree of my sentence. So my queries have to return the parse tree, and also the meaning of the sentence
But I am finding some problem doing it...I was trying something like this, but don't work:
/** Adding the meaning into the Parse Tree: */
sentence2(sentence(Name, VerbPhrase)) --> noun_phrase2(Name),
verb_phrase2(VerbPhrase).
noun_phrase2(noun_phrase(Name)) --> properName2(Name).
verb_phrase2(verb_phrase(IntransVerb)) --> intrans_verb2(IntransVerb).
verb_phrase2(verb_phras(TransVerb, ProperName)) --> trans_verb2(TransVerb),
noun_phrase2(ProperName).
/* properName, intrans_verb ant trans_verb are LEAVES: */
properName2(properName(john)) --> [john].
properName2(properName(mary)) --> [mary].
intrans_verb2(Actor, intrans_verb2(paints(Actor))) --> [paints].
trans_verb2(Somebody, Something, trans_verb2(likes(Somebody, Something))) --> [likes].