本文整理匯總了Python中rule.Rule.setup方法的典型用法代碼示例。如果您正苦於以下問題:Python Rule.setup方法的具體用法?Python Rule.setup怎麽用?Python Rule.setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rule.Rule
的用法示例。
在下文中一共展示了Rule.setup方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: treeToDeriv
# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import setup [as 別名]
def treeToDeriv(tree):
if type(tree[1]) is not tuple:
r = Rule()
r.setup(tree[0], [tree[1],], 1.0)
return [r,]
else:
r = Rule()
rhs = [x[0] for x in tree[1:]]
assert(len(rhs) <= 2), "Non-binary rule: %s" % str(rhs)
r.setup(tree[0], rhs, 1.0)
res = [r,]
for subt in tree[1:]:
res += treeToDeriv(subt)
return res
示例2: parseFail
# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import setup [as 別名]
def parseFail(self, sentence):
top = self.top
topBar = "@%s" % top
lhs = top
ana = self.makeAnalysis(top=top, initial=self.grammar.depth())
for word in sentence:
posInsRule = Rule()
posInsRule.setup(lhs, ["FW", topBar], 1.0)
lhs = topBar
posInsRule.terminal = False
ana = ana.extend(posInsRule, None, None, self, doFOM=False)
wordInsRule = Rule()
wordInsRule.setup("FW", [word,], 1.0)
wordInsRule.terminal = True
ana = ana.extend(wordInsRule, None, None, self, doFOM=False)
endRule = Rule()
endRule.setup(topBar, [], 1.0)
endRule.terminal = True
ana = ana.extend(endRule, None, None, self, doFOM=False)
return ana