当前位置: 首页>>代码示例>>Python>>正文


Python compat.unicode_repr方法代码示例

本文整理汇总了Python中nltk.compat.unicode_repr方法的典型用法代码示例。如果您正苦于以下问题:Python compat.unicode_repr方法的具体用法?Python compat.unicode_repr怎么用?Python compat.unicode_repr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nltk.compat的用法示例。


在下文中一共展示了compat.unicode_repr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _trace_apply

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def _trace_apply(self, chunkstr, verbose):
        """
        Apply each rule of this ``RegexpChunkParser`` to ``chunkstr``, in
        turn.  Generate trace output between each rule.  If ``verbose``
        is true, then generate verbose output.

        :type chunkstr: ChunkString
        :param chunkstr: The chunk string to which each rule should be
            applied.
        :type verbose: bool
        :param verbose: Whether output should be verbose.
        :rtype: None
        """
        print('# Input:')
        print(chunkstr)
        for rule in self._rules:
            rule.apply(chunkstr)
            if verbose:
                print('#', rule.descr()+' ('+unicode_repr(rule)+'):')
            else:
                print('#', rule.descr()+':')
            print(chunkstr) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:24,代码来源:regexp.py

示例2: __str__

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def __str__(self):
        """
        :return: a verbose string representation of this ``RegexpChunkParser``.
        :rtype: str
        """
        s = "RegexpChunkParser with %d rules:\n" % len(self._rules)
        margin = 0
        for rule in self._rules:
            margin = max(margin, len(rule.descr()))
        if margin < 35:
            format = "    %" + repr(-(margin+3)) + "s%s\n"
        else:
            format = "    %s\n      %s\n"
        for rule in self._rules:
            s += format % (rule.descr(), unicode_repr(rule))
        return s[:-1]

##//////////////////////////////////////////////////////
##  Chunk Grammar
##////////////////////////////////////////////////////// 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:22,代码来源:regexp.py

示例3: _pformat_flat

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def _pformat_flat(self, nodesep, parens, quotes):
        childstrs = []
        for child in self:
            if isinstance(child, Tree):
                childstrs.append(child._pformat_flat(nodesep, parens, quotes))
            elif isinstance(child, tuple):
                childstrs.append("/".join(child))
            elif isinstance(child, string_types) and not quotes:
                childstrs.append('%s' % child)
            else:
                childstrs.append(unicode_repr(child))
        if isinstance(self._label, string_types):
            return '%s%s%s %s%s' % (parens[0], self._label, nodesep,
                                    " ".join(childstrs), parens[1])
        else:
            return '%s%s%s %s%s' % (parens[0], unicode_repr(self._label), nodesep,
                                    " ".join(childstrs), parens[1]) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:19,代码来源:tree.py

示例4: _trace_fringe

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def _trace_fringe(self, tree, treeloc=None):
        """
        Print trace output displaying the fringe of ``tree``.  The
        fringe of ``tree`` consists of all of its leaves and all of
        its childless subtrees.

        :rtype: None
        """

        if treeloc == (): print("*", end=' ')
        if isinstance(tree, Tree):
            if len(tree) == 0:
                print(unicode_repr(Nonterminal(tree.label())), end=' ')
            for i in range(len(tree)):
                if treeloc is not None and i == treeloc[0]:
                    self._trace_fringe(tree[i], treeloc[1:])
                else:
                    self._trace_fringe(tree[i])
        else:
            print(unicode_repr(tree), end=' ') 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:22,代码来源:recursivedescent.py

示例5: __repr__

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def __repr__(self):
        # Cache the repr (justified by profiling -- this is used as
        # a sort key when deterministic=True.)
        try:
            return self.__repr
        except AttributeError:
            self.__repr = (
                "{0}('{1}', {2}, {3}, [{4}])".format(
                    self.__class__.__name__,
                    self.templateid,
                    unicode_repr(self.original_tag),
                    unicode_repr(self.replacement_tag),

                    # list(self._conditions) would be simpler but will not generate
                    # the same Rule.__repr__ in python 2 and 3 and thus break some tests
                    ', '.join("({0},{1})".format(f, unicode_repr(v)) for (f, v) in self._conditions)
                )
            )

            return self.__repr 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:22,代码来源:rule.py

示例6: __repr__

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def __repr__(self):
        """
        A string representation of the token that can reproduce it
        with eval(), which lists all the token's non-default
        annotations.
        """
        typestr = (' type=%s,' % unicode_repr(self.type)
                   if self.type != self.tok else '')

        propvals = ', '.join(
            '%s=%s' % (p, unicode_repr(getattr(self, p)))
            for p in self._properties
            if getattr(self, p)
        )

        return '%s(%s,%s %s)' % (self.__class__.__name__,
            unicode_repr(self.tok), typestr, propvals) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:19,代码来源:punkt.py

示例7: __repr__

# 需要导入模块: from nltk import compat [as 别名]
# 或者: from nltk.compat import unicode_repr [as 别名]
def __repr__(self):
        """
        Return a string representation of this ``ChunkString``.
        It has the form::

            <ChunkString: '{<DT><JJ><NN>}<VBN><IN>{<DT><NN>}'>

        :rtype: str
        """
        return '<ChunkString: %s>' % unicode_repr(self._str) 
开发者ID:Thejas-1,项目名称:Price-Comparator,代码行数:12,代码来源:regexp.py


注:本文中的nltk.compat.unicode_repr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。