コード例 #1
0
    def __str__(self):
        """
        Return a verbose string representation of the ``Production``.

        :rtype: str
        """
        result = '%s -> ' % unicode_repr(self._lhs)
        result += " ".join(unicode_repr(el) for el in self._rhs)
        return result
コード例 #2
0
 def _trace_stack(self, stack, remaining_text, marker=' '):
     """
     Print trace output displaying the given stack and text.
     :rtype: None
     :param marker: A character that is printed to the left of the
         stack.  This is used with trace level 2 to print 'S'
         before shifted stacks and 'R' before reduced stacks.
     """
     s = '  ' + marker + ' [ '
     for elt in stack:
         if isinstance(elt, Tree):
             s += unicode_repr(Nonterminal(elt.label())) + ' '
         else:
             s += unicode_repr(elt) + ' '
     s += '* ' + ' '.join(remaining_text) + ']'
     print(s)
コード例 #3
0
    def _trace_stack(self, stack, remaining_text, marker=' '):
        """
        Print trace output displaying the given stack and text.

        :rtype: None
        :param marker: A character that is printed to the left of the
            stack.  This is used with trace level 2 to print 'S'
            before shifted stacks and 'R' before reduced stacks.
        """
        s = '  '+marker+' [ '
        for elt in stack:
            if isinstance(elt, Tree):
                s += unicode_repr(Nonterminal(elt.label())) + ' '
            else:
                s += unicode_repr(elt) + ' '
        s += '* ' + ' '.join(remaining_text) + ']'
        print(s)
コード例 #4
0
    def __repr__(self):
        # Cache the repr (justified by profiling -- this is used as
        # a sort key when deterministic=True.)
        try:
            return self.__repr
        except:
            self.__repr = ('%s(%r, %s, %s, [%s])' % (
                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:s},{1:s})".format(f,unicode_repr(v)) for (f,v) in self._conditions)))

            return self.__repr
コード例 #5
0
    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
コード例 #6
0
    def __str__(self):
        """
        Return a string representation for this ``Nonterminal``.

        :rtype: str
        """
        if isinstance(self._symbol, string_types):
            return '%s' % self._symbol
        else:
            return '%s' % unicode_repr(self._symbol)
コード例 #7
0
    def __repr__(self):
        # Cache the repr (justified by profiling -- this is used as
        # a sort key when deterministic=True.)
        try:
            return self.__repr
        except:
            self.__repr = (
                '%s(%r, %s, %s, [%s])' % (
                    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:s},{1:s})".format(f, unicode_repr(v))
                              for (f, v) in self._conditions)))

            return self.__repr
コード例 #8
0
ファイル: rule.py プロジェクト: CaptainAL/Spyder
    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
コード例 #9
0
    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=' ')
コード例 #10
0
ファイル: rd.py プロジェクト: BohanHsu/developer
    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=' ')
コード例 #11
0
ファイル: parser.py プロジェクト: TCBpenta8/ifcc-1
 def _format(cls, tree):
     childstrs = []
     for child in tree:
         if isinstance(child, Tree):
             childstrs.append(cls._format(child))
         elif isinstance(child, tuple):
             childstrs.append("/".join(child))
         elif isinstance(child, string_types):
             childstrs.append('%s' % child)
         else:
             childstrs.append(unicode_repr(child))
     if len(childstrs) > 1:
         return '( %s )' % ' '.join(childstrs)
     else:
         return childstrs[0]
コード例 #12
0
ファイル: api.py プロジェクト: rfbonett/tribehacks
 def __str__(self):
     if self._restrs == []:
         return "%s" % self._categ
     restrictions = "[%s]" % ",".join(unicode_repr(r) for r in self._restrs)
     return "%s%s" % (self._categ, restrictions)
コード例 #13
0
ファイル: api.py プロジェクト: wardbradt/nltk
 def __str__(self):
     if self._restrs == []:
         return "%s" % self._categ
     restrictions = "[%s]" % ",".join(unicode_repr(r) for r in self._restrs)
     return "%s%s" % (self._categ, restrictions)