我试图将一个句子转换成lambda函数表示法,比如在4.2节中看到的http://www.nltk.org/book/ch10.html。使用代码,我可以将句子转换成语义值,并使用上下文无关语法分析句子,但是有哪些方法可以将句子转换成lambda符号。在
import nltk
grammar = nltk.CFG.fromstring("""
S -> NP VP
VP -> V NP
V -> "is"
Adj -> "Chewing"
Coj -> "and"
Nom -> Adj Nom | N
NP -> Nom Coj NP | N
Det -> "a" | "an" | "the" | "my"
N -> "gum" | "candy" | "thrilling"
P -> "in" | "on" | "by" | "with"
""")
sent = "Chewing gum and candy is thrilling".split()
rd_parser = nltk.RecursiveDescentParser(grammar, )
for tree in rd_parser.parse(sent):
print (tree)
简答:你必须编写自己的语义语法。要将CFG映射到lambda演算,没有简单的方法。在
较长的答案:
在CFG中,最接近语义树的是为非终端指定语义特性,sqlcfg示例是如何实现这一点的一个很好的指南,请参见第1.1节。来自http://www.nltk.org/book/ch10.html:
将CFG映射到lambda演算,反之亦然,或者从文本中学习两者仍然是一项值得研究的工作,因此目前还没有明确的方法来做。在
见http://dl.acm.org/citation.cfm?id=2052254和 http://www.computer.org/csdl/proceedings/ictai/2008/3440/02/3440b135-abs.html
相关问题 更多 >
编程相关推荐