我有这个DCG语法,可以理解并同意以下短语:[john, paints]和[john, likes, mary]通过使用参数将语义直接管理到 DCG 语法中
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].
例如,短语[john, paints]的意思是:paints(john),实际上这是查询的结果:
?- sentence2(Meaning, [john,paints],[]).
Meaning = paints(john)
好的,所以这可以在不构建解析树的情况下处理含义。
我有一个练习,要求我修改以前的语法,以从句子的句法树中获取平均值。所以我的查询必须返回解析树,以及句子的含义
但我发现这样做有一些问题......我正在尝试这样的事情,但不工作:
/** 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].