我正在研究使用Prolog进行自然语言处理的DCG语法,我对是否正确理解它或者是否缺少某些东西有疑问 .
这是我的DCG语法:
sentence2(VP) --> noun_phrase2(Actor),
verb_phrase2(Actor, VP).
/* A noun phrase is a proper name of a person (that is unified in the Name variable) */
noun_phrase2(Name) --> properName(Name).
/* A verb_phrase can be an intransitive verb */
verb_phrase2(Actor, VP) --> intrans_verb(Actor, VP).
/* A verb_phrase can be a transitive verb followed by an object complement
verb_phrase2(Somebody, VP) --> trans_verb(Somebody, Something, VP),
noun_phrase2(Something).
/* The meaning of a proper name john is john
The meaning of a proper name mary is mary */
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)
[john paints] 这是我的 final sentence ,我必须评估并说它是否属于我的语言 .
必须以下列方式形成一个句子:
sentence2(VP) --> noun_phrase2(Actor),
verb_phrase2(Actor, VP).
(通过 noun phrase 后跟 verb phrase 的东西 .
noun phrase 以这种方式组成:
noun_phrase2(Name) --> properName(Name).
所以 noun phrase 是 proper name
proper name 的含义很简单,因为通过这一行:
properName(john) --> [john].
我只是说 john is a proper name 和我正在为DCG语法添加一个指定其含义的参数 . 所以: the semantic meaning of the proper name john is john
所以, noun phrase 的 meaning 是 proper name 的 same meaning (因为变量 Name 统一)
所以在前一种情况下, meaning 谓的 noun_phrase2 谓词是 john ,我原始句子的第一个评估步骤结束 .
现在我必须通过谓词评估第二部分是 verbal phrase : verb_phrase2(Actor, VP)
在这种情况下, verbal phrase 可能是 intransitive verb :
verb_phrase2(Actor, VP) --> intrans_verb(Actor, VP).
以这种方式定义不及物动词:
intrans_verb(Actor, paints(Actor)) --> [paints].
所以单词 paints 是一个不及物动词,它的含义是 paints(Actor) ,其中 Actor 是一个依赖于上下文的变量(在本例中为 Actor rappresent who do the action, who paints )
所以,它回溯到 verb_phrase2(Actor, VP) 以验证 verb_phrase2(Actor, VP)
现在Actor仍然是一个尚未统一的变量,其含义是 VP = paints(Actor)
因此,验证 paints 是不及物动词,其含义是 paints(Actor)
因此,执行回溯到原始的 sentence2(VP) 谓词,我刚刚验证了 noun_phrase2(Actor) 谓词,其中 Actor = john
所以我有类似这样的情况:
sentence2(VP) --> noun_phrase2(john),
verb_phrase2(john, paints(john)).
所以决赛 VP is unified to paints(john)
这是我的推理是正确的还是我错过了什么?这是以Prolog方式推理的好方法吗?
1 回答
请问一个具体的简短问题 . 包含相关代码而不会有过多评论 .
这是如何做 .
鉴于DCG规则
以下如何实现其结果?
回答:
以上规则相当于
特别是,