【发布时间】:2013-05-16 11:02:33
【问题描述】:
我正在使用 Ivan Bratko 的书:“人工智能编程”在 Prolog 中研究 DCG 语法和 解析树
我对我对生成解析树的 DCG 语法的解释有些怀疑:
sentence(Number, sentence(NP, VP)) --> noun_phrase(Number, NP),
verb_phrase(Number, VP).
verb_phrase(Number, verb_phrase(Verb, NP)) --> verb(Number, Verb),
noun_phrase(_, NP).
noun_phrase(Number, noun_phrase(Det, Noun)) --> determiner(Number, Det),
noun(Number, Noun).
determiner(singular, determiner(a)) --> [a].
determiner(_,determiner(the)) --> [the].
noun(singular, noun(cat)) --> [cat].
noun(singular, noun(mouse)) --> [mouse].
noun(plural, noun(cats)) --> [cats].
noun(plural, noun(mice)) --> [mice].
verb(singular, verb(scares)) --> [scares].
verb(singular, verb(hates)) --> [hates].
verb(plural, verb(scare)) --> [scare].
verb(plural, verb(hate)) --> [hate].
例如,如果我可以执行以下查询:
[debug] ?- sentence(singular, Tree, [a, cat, scares, the, mice],[]).
Tree = sentence(noun_phrase(determiner(a), noun(cat)), verb_phrase(verb(scares), noun_phrase(determiner(the), noun(mice))))
这是 TRUE 并且生成一个 解析树,其中 sentence 作为根
我试图解释如何仅使用以前的 DCG 语法形式构建解析树,而不是关于 Prolog 如何将此语法转换为一组规则(因为,对我来说这件事很困难,也许是因为这样做我将添加进一步的步骤)
用DCG语法而不是自动转换的规则阅读是不是一件好事?
所以我是这样读的:
sentence 由 noun_phrase 和 verb_phrase 组成,因此在 DCG 语法的第一个“规则”中,我指定 sentence 是我的树的根(代表我的自然语言子集中的一个句子),它有一个 noun_phrase 作为左孩子,一个 verb_phrase 作为右孩子
那么 noun_phrase 被定义为 determiner 后跟 noun 所以 noun_phrase 是另一棵树的根determiner 作为左孩子,名词 作为右孩子
那么确定器是由单个节点组成的树:determiner(a) 如果找到的确定器是“a”为 TRUE,或者 **determiner(the) 如果它是 TRUE 则找到的限定词是“the”
我的 *verb_phrase** 的推理相同
对吗?
【问题讨论】: