【问题标题】:Some doubts related DCG grammar and parse tree relation in PrologProlog中有关DCG语法和解析树关系的一些疑惑
【发布时间】: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语法而不是自动转换的规则阅读是不是一件好事?

所以我是这样读的:

sentencenoun_phraseverb_phrase 组成,因此在 DCG 语法的第一个“规则”中,我指定 sentence 是我的树的根(代表我的自然语言子集中的一个句子),它有一个 noun_phrase 作为左孩子,一个 verb_phrase 作为右孩子

那么 noun_phrase 被定义为 determiner 后跟 noun 所以 noun_phrase 是另一棵树的根determiner 作为左孩子,名词 作为右孩子

那么确定器是由单个节点组成的树:determiner(a) 如果找到的确定器是“a”为 TRUE,或者 **determiner(the) 如果它是 TRUE 则找到的限定词是“the”

我的 *verb_phrase** 的推理相同

对吗?

【问题讨论】:

    标签: prolog dcg


    【解决方案1】:

    DCG 形式的全部意义在于您不需要查看规范化形式,就是这样。

    因此,使用 DCG,您最终会得到一个表示,对于人类来说是相当直接的解释。

    是的,您的解释是正确的。 Prolog 似乎同意你的看法,因为它可以让你得到你所期望的。假设您没有看到任何警告,那么您应该一切顺利。也许尝试解析一些边缘情况,看看会发生什么?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 2012-01-29
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多