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


Python compat.binary_type方法代碼示例

本文整理匯總了Python中nltk.compat.binary_type方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.binary_type方法的具體用法?Python compat.binary_type怎麽用?Python compat.binary_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nltk.compat的用法示例。


在下文中一共展示了compat.binary_type方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tgrep_positions

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import binary_type [as 別名]
def tgrep_positions(pattern, trees, search_leaves=True):
    """
    Return the tree positions in the trees which match the given pattern.

    :param pattern: a tgrep search pattern
    :type pattern: str or output of tgrep_compile()
    :param trees: a sequence of NLTK trees (usually ParentedTrees)
    :type trees: iter(ParentedTree) or iter(Tree)
    :param search_leaves: whether ot return matching leaf nodes
    :type search_leaves: bool
    :rtype: iter(tree positions)
    """

    if isinstance(pattern, (binary_type, text_type)):
        pattern = tgrep_compile(pattern)

    for tree in trees:
        try:
            if search_leaves:
                positions = tree.treepositions()
            else:
                positions = treepositions_no_leaves(tree)
            yield [position for position in positions
                      if pattern(tree[position])]
        except AttributeError:
            yield [] 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:28,代碼來源:tgrep.py

示例2: tgrep_nodes

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import binary_type [as 別名]
def tgrep_nodes(pattern, trees, search_leaves=True):
    """
    Return the tree nodes in the trees which match the given pattern.

    :param pattern: a tgrep search pattern
    :type pattern: str or output of tgrep_compile()
    :param trees: a sequence of NLTK trees (usually ParentedTrees)
    :type trees: iter(ParentedTree) or iter(Tree)
    :param search_leaves: whether ot return matching leaf nodes
    :type search_leaves: bool
    :rtype: iter(tree nodes)
    """

    if isinstance(pattern, (binary_type, text_type)):
        pattern = tgrep_compile(pattern)

    for tree in trees:
        try:
            if search_leaves:
                positions = tree.treepositions()
            else:
                positions = treepositions_no_leaves(tree)
            yield [tree[position] for position in positions
                      if pattern(tree[position])]
        except AttributeError:
            yield [] 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:28,代碼來源:tgrep.py

示例3: tgrep_tokenize

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import binary_type [as 別名]
def tgrep_tokenize(tgrep_string):
    '''
    Tokenizes a TGrep search string into separate tokens.
    '''
    parser = _build_tgrep_parser(False)
    if isinstance(tgrep_string, binary_type):
        tgrep_string = tgrep_string.decode()
    return list(parser.parseString(tgrep_string)) 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:10,代碼來源:tgrep.py

示例4: tgrep_compile

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import binary_type [as 別名]
def tgrep_compile(tgrep_string):
    '''
    Parses (and tokenizes, if necessary) a TGrep search string into a
    lambda function.
    '''
    parser = _build_tgrep_parser(True)
    if isinstance(tgrep_string, binary_type):
        tgrep_string = tgrep_string.decode()
    return list(parser.parseString(tgrep_string, parseAll=True))[0] 
開發者ID:Thejas-1,項目名稱:Price-Comparator,代碼行數:11,代碼來源:tgrep.py

示例5: tgrep_nodes

# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import binary_type [as 別名]
def tgrep_nodes(pattern, trees, search_leaves=True):
    """
    Return the tree nodes in the trees which match the given pattern.

    :param pattern: a tgrep search pattern
    :type pattern: str or output of tgrep_compile()
    :param trees: a sequence of NLTK trees (usually ParentedTrees)
    :type trees: iter(ParentedTree) or iter(Tree)
    :param search_leaves: whether ot return matching leaf nodes
    :type search_leaves: bool
    :rtype: iter(tree nodes)
    """

    if isinstance(pattern, (binary_type, text_type)):
        pattern = tgrep_compile(pattern)

    for tree in trees:
        try:
            if search_leaves:
                positions = tree.treepositions()
            else:
                positions = treepositions_no_leaves(tree)
            yield [tree[position] for position in positions
                      if pattern(tree[position])]
        except AttributeError:
            yield []


# run module doctests 
開發者ID:EastonLee,項目名稱:FancyWord,代碼行數:31,代碼來源:tgrep.py


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