本文整理汇总了Python中nltk.compat.xrange方法的典型用法代码示例。如果您正苦于以下问题:Python compat.xrange方法的具体用法?Python compat.xrange怎么用?Python compat.xrange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.compat
的用法示例。
在下文中一共展示了compat.xrange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import xrange [as 别名]
def apply(self, chart, grammar):
for prod in grammar.productions(empty=True):
for index in compat.xrange(chart.num_leaves() + 1):
new_edge = TreeEdge.from_production(prod, index)
if chart.insert(new_edge, ()):
yield new_edge
########################################################################
## Filtered Bottom Up
########################################################################
示例2: apply
# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import xrange [as 别名]
def apply(self, chart, grammar):
for prod in grammar.productions(empty=True):
for index in xrange(chart.num_leaves() + 1):
new_edge = FeatureTreeEdge.from_production(prod, index)
if chart.insert(new_edge, ()):
yield new_edge
#////////////////////////////////////////////////////////////
# Feature Chart Parser
#////////////////////////////////////////////////////////////
示例3: _positions
# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import xrange [as 别名]
def _positions(self):
return xrange(self.num_leaves() + 1)
示例4: pk
# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import xrange [as 别名]
def pk(ref, hyp, k=None, boundary='1'):
"""
Compute the Pk metric for a pair of segmentations A segmentation
is any sequence over a vocabulary of two items (e.g. "0", "1"),
where the specified boundary value is used to mark the edge of a
segmentation.
>>> '%.2f' % pk('0100'*100, '1'*400, 2)
'0.50'
>>> '%.2f' % pk('0100'*100, '0'*400, 2)
'0.50'
>>> '%.2f' % pk('0100'*100, '0100'*100, 2)
'0.00'
:param ref: the reference segmentation
:type ref: str or list
:param hyp: the segmentation to evaluate
:type hyp: str or list
:param k: window size, if None, set to half of the average reference segment length
:type boundary: str or int or bool
:param boundary: boundary value
:type boundary: str or int or bool
:rtype: float
"""
if k is None:
k = int(round(len(ref) / (ref.count(boundary) * 2.)))
err = 0
for i in xrange(len(ref)-k +1):
r = ref[i:i+k].count(boundary) > 0
h = hyp[i:i+k].count(boundary) > 0
if r != h:
err += 1
return err / (len(ref)-k +1.)
# skip doctests if numpy is not installed