當前位置: 首頁>>代碼示例>>Python>>正文


Python compat.xrange方法代碼示例

本文整理匯總了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
######################################################################## 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:13,代碼來源:chart.py

示例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
#//////////////////////////////////////////////////////////// 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:13,代碼來源:featurechart.py

示例3: _positions

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import xrange [as 別名]
def _positions(self):
        return xrange(self.num_leaves() + 1) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:4,代碼來源:earleychart.py

示例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 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:40,代碼來源:segmentation.py


注:本文中的nltk.compat.xrange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。