当前位置: 首页>>代码示例>>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;未经允许,请勿转载。