예제 #1
0
    def iterparse(self, lines: Union[Iterable[str], str]) -> Iterator[Tree]:
        """
        Yield trees parsed from *lines*.

        Args:
            lines: a string or open file with PENMAN-serialized graphs
        Returns:
            The :class:`Tree` object described in *lines*.
        """
        tokens = lex(lines, pattern=PENMAN_RE)
        while tokens and tokens.peek().type in ('COMMENT', 'LPAREN'):
            yield self._parse(tokens)
예제 #2
0
    def parse(self, s: str) -> Tree:
        """
        Parse PENMAN-notation string *s* into its tree structure.

        Args:
            s: a string containing a single PENMAN-serialized graph
        Returns:
            The tree structure described by *s*.
        Example:
            >>> codec = PENMANCodec()
            >>> codec.parse('(b / bark-01 :ARG0 (d / dog))')  # noqa
            Tree(('b', [('/', 'bark-01'), ('ARG0', ('d', [('/', 'dog')]))]))
        """
        tokens = lex(s, pattern=PENMAN_RE)
        return self._parse(tokens)
예제 #3
0
 def _lex(s):
     return [tok.type for tok in lexer.lex(s)]
예제 #4
0
 def parse_triples(self, s: str) -> List[BasicTriple]:
     """ Parse a triple conjunction from *s*."""
     tokens = lex(s, pattern=TRIPLE_RE)
     return self._parse_triples(tokens)
예제 #5
0
 def _lex(s):
     return [tok.type for tok in lexer.lex(s, pattern=lexer.TRIPLE_RE)]