goodmami / penman

PENMAN notation (e.g. AMR) in Python
https://penman.readthedocs.io/
MIT License
139 stars 27 forks source link

:ARG1 and :ARG1-of both display as :ARG1 when returning graph triples #105

Closed brandonbell11 closed 2 years ago

brandonbell11 commented 2 years ago

Example sentence: He found a loophole in her request

Has an AMR of:

(f0 / find-01
      :ARG0 (h0 / he)
      :ARG1 (l0 / loophole
            :ARG1-of (r0 / request-01
                  :ARG0 (s0 / she))))

steps to reproduce:

AMR = '(f0 / find-01 :ARG0 (h0 / he) :ARG1 (l0 / loophole :ARG1-of (r0 / request-01 :ARG0 (s0 / she))))' 
g = penman.decode(AMR)
g.triples

This returns

[('f0', ':instance', 'find-01'),
 ('f0', ':ARG0', 'h0'),
 ('h0', ':instance', 'he'),
 ('f0', ':ARG1', 'l0'),
 ('l0', ':instance', 'loophole'),
 ('r0', ':ARG1', 'l0'),
 ('r0', ':instance', 'request-01'),
 ('r0', ':ARG0', 's0'),
 ('s0', ':instance', 'she')]

I am trying to comb through the source code to try and correct this but I am very new to the project. So any assistance would be helpful

goodmami commented 2 years ago

Since you closed this I assume you've figured it out, but in case anybody else has a similar issue later, I'll explain a bit. Something like (a / alpha :ARG0-of (b / beta)) is a serialization of the graph with an :ARG0 edge from b to a:

>>> import penman
>>> g = penman.decode('(a / alpha :ARG0-of (b / beta))')
>>> g.triples
[('a', ':instance', 'alpha'), ('b', ':ARG0', 'a'), ('b', ':instance', 'beta')]

Users of AMR data have a tendency to prefer the tree-like graph where :ARG0-of is the branch label from a to b. If you fall into this group, you have two options in the Penman library. You can either work with the tree, e.g., as returned by penman.parse() (instead of the graph from penman.decode()):

>>> t = penman.parse('(a / alpha :ARG0-of (b / beta))')
>>> t
Tree(('a', [('/', 'alpha'), (':ARG0-of', ('b', [('/', 'beta')]))]))

... or decode the graph with a model that pretends that no edges are inverted and all edge labels are canonical, namely the NoOpModel:

>>> from penman.models import noop
>>> g = penman.decode('(a / alpha :ARG0-of (b / beta))', model=noop.model)
>>> g.triples
[('a', ':instance', 'alpha'), ('a', ':ARG0-of', 'b'), ('b', ':instance', 'beta')]