【发布时间】:2013-02-07 05:07:33
【问题描述】:
我有一个(大)已解析句子列表(使用斯坦福解析器解析),例如,句子“现在你可以被娱乐”具有以下树:
(ROOT
(S
(ADVP (RB Now))
(, ,)
(NP (PRP you))
(VP (MD can)
(VP (VB be)
(VP (VBN entertained))))
(. .)))
我正在使用一组句子树来使用 nltk 归纳语法:
import nltk
# ... for each sentence tree t, add its production to allProductions
allProductions += t.productions()
# Induce the grammar
S = nltk.Nonterminal('S')
grammar = nltk.induce_pcfg(S, allProductions)
现在我想使用grammar 生成新的随机句子。我的希望是,由于语法是从一组特定的输入示例中学习的,因此生成的句子在语义上将是相似的。我可以在 nltk 中执行此操作吗?
如果我不能使用 nltk 来执行此操作,是否还有其他工具可以获取(可能重新格式化)grammar 并生成句子?
【问题讨论】: