prolog – 是否存在带有非终端符号参数的BNF?

在使用Prolog DCG来解析输入时,有一个语法的伴随BNF是很好的.

例如:

BNF

<Sentence> ::= <Noun_phrase> <Verb_phrase>
<Noun_phrase> ::= <Determiner> <Noun>
<Verb_phrase> ::= <Verb> <Phrase>
<Determiner> ::= a
<Determiner> ::= the
<Noun> ::= cat
<Noun> ::= mouse
<Verb> ::= scares
<Verb> ::= hates

作为Prolog DCG

sentence --> noun_phrase, verb_phrase.
verb_phrase --> verb, noun_phrase.
noun_phrase --> determiner, noun.
determiner --> [a].
determiner --> [the].
noun --> [cat].
noun --> [mouse].
verb --> [scares].
verb --> [hates].

然而,Prolog DCG也可以作为参数
在此示例中为单数或复数的数字

sentence(Number) --> noun_phrase(Number), verb_phrase(Number).
verb_phrase(Number) --> verb(Number), noun_phrase(Number).
noun_phrase(Number) --> determiner(Number), noun(Number).
determiner(singular) --> [a].
determiner(singular) --> [the].
determiner(plural) --> [the].
noun(singular) --> [cat].
noun(plural) --> [cats].
noun(singular) --> [mouse].
noun(plural) --> [mice].
verb(singular) --> [scares].
verb(plural) --> [scare].
verb(singular) --> [hates].
verb(plural) --> [hate].

BNF是否有标准或接受的扩展,包括非终端的参数?

如果是这样,我需要一个链接.

我怀疑ATN(增强过渡网络)是在球场,可能是唯一的标准答案,但我希望有一些线性文本,而不是某些形式的顶点/边缘图.

最佳答案 我认为
feature structures的概念正是您所期待的;您在示例中显示的参数共享是更一般的特征结构统一方法的特例.

我没有特别注意BNF的特征结构扩展,但是有合理的接受符号可以将它们添加到其他语法形式中. NLTK(一个Python自然语言处理库)的文档有他们使用的符号an example here.以下是他们的一些规则,大致对应于您示例中的前几个产品:

S -> NP[CASE=nom, AGR=?a] VP[AGR=?a]
VP[AGR=?a] -> TV[OBJCASE=?c, AGR=?a] NP[CASE=?c]
NP[CASE=?c, AGR=?a] -> Det[CASE=?c, AGR=?a] N[CASE=?c, AGR=?a]

?x是逻辑变量的表示法. NLTK手册的整个章节包含对特征结构的一般描述,并包括一些参考文献.

点赞