Exemple #1
0
def test_issue_92():
    # https://github.com/goodmami/penman/issues/92
    g = codec.decode('(a / alpha :ARG0~e.0 (b / beta))')
    assert configure(g) == Tree(('a', [('/', 'alpha'),
                                       (':ARG0~e.0', ('b', [('/', 'beta')]))]))
    assert configure(g, top='b') == Tree(
        ('b', [('/', 'beta'), (':ARG0-of~e.0', ('a', [('/', 'alpha')]))]))
Exemple #2
0
    def encode(self,
               g: Graph,
               top: Variable = None,
               indent: Union[int, None] = -1,
               compact: bool = False) -> str:
        """
        Serialize the graph *g* into PENMAN notation.

        Args:
            g: the Graph object
            top: if given, the node to use as the top in serialization
            indent: how to indent formatted strings
            compact: if ``True``, put initial attributes on the first line
        Returns:
            the PENMAN-serialized string of the Graph *g*
        Example:
            >>> from penman.graph import Graph
            >>> from penman.codec import PENMANCodec
            >>> codec = PENMANCodec()
            >>> codec.encode(Graph([('h', 'instance', 'hi')]))
            '(h / hi)'

        """
        tree = layout.configure(g, top=top, model=self.model)
        return self.format(tree, indent=indent, compact=compact)
Exemple #3
0
def _process_out(g, model, normalize_options):
    if normalize_options['reconfigure']:
        key, kwargs = normalize_options['reconfigure']
        t = layout.reconfigure(g, key=key, **kwargs)
        g = layout.interpret(t, model)
    else:
        t = layout.configure(g, model=model)
    if normalize_options['rearrange']:
        key, kwargs = normalize_options['rearrange']
        layout.rearrange(t, key=key, **kwargs)
    if normalize_options['make_variables']:
        t.reset_variables(normalize_options['make_variables'])

    return t
Exemple #4
0
def test_issue_34():
    # https://github.com/goodmami/penman/issues/34
    g = codec.decode('''
        # ::snt I think you failed to not not act.
        (t / think
           :ARG0 (i / i)
           :ARG1 (f / fail
              :ARG0 (y / you)
              :ARG1 (a / act
                 :polarity -
                 :polarity -)))''')
    assert configure(g) == Tree(
        ('t', [('/', 'think'), (':ARG0', ('i', [('/', 'i')])),
               (':ARG1', ('f', [('/', 'fail'),
                                (':ARG0', ('y', [('/', 'you')])),
                                (':ARG1', ('a', [('/', 'act'),
                                                 (':polarity', '-'),
                                                 (':polarity', '-')]))]))]))
Exemple #5
0
def test_configure(amr_model):
    g = codec.decode('(a / A)')
    assert configure(g) == Tree(('a', [('/', 'A')]))
    with pytest.raises(LayoutError):
        configure(g, top='A')

    g = codec.decode('(a / A :consist-of (b / B))')
    assert configure(g) == Tree(('a', [('/', 'A'),
                                       (':consist-of', ('b', [('/', 'B')]))]))
    assert configure(g, top='b') == Tree(
        ('b', [('/', 'B'), (':consist', ('a', [('/', 'A')]))]))

    amr_codec = PENMANCodec(model=amr_model)
    g = amr_codec.decode('(a / A :consist-of (b / B))')
    assert configure(g, model=amr_model) == Tree(
        ('a', [('/', 'A'), (':consist-of', ('b', [('/', 'B')]))]))
    assert configure(g, top='b', model=amr_model) == Tree(
        ('b', [('/', 'B'), (':consist-of-of', ('a', [('/', 'A')]))]))
Exemple #6
0
def test_issue_93():
    # https://github.com/goodmami/penman/issues/93
    g = codec.decode('(a / alpha :ARG0 b~1)')
    g.triples.append(('b', ':instance', 'beta'))
    assert configure(g) == Tree(('a', [('/', 'alpha'),
                                       (':ARG0', ('b', [('/', 'beta')]))]))