delph-in / pydelphin

Python libraries for DELPH-IN
https://pydelphin.readthedocs.io/
MIT License
79 stars 27 forks source link

DMRSWarning: broken handle constraint #328

Closed arademaker closed 3 years ago

arademaker commented 3 years ago

The conversion from MRS to DMRS fails with errors. It seems the error is the same of #319

Sentence MRS 1434

[ TOP: h0
  INDEX: e2 [ e SF: prop TENSE: pres MOOD: indicative PROG: - PERF: - ]
  RELS: < [ _a_q<0:1> LBL: h4 ARG0: x3 [ x PERS: 3 NUM: sg IND: + ] RSTR: h5 BODY: h6 ]
          [ _man_n_1<2:5> LBL: h7 ARG0: x3 ]
          [ _be_v_id<6:8> LBL: h1 ARG0: e2 ARG1: x3 ARG2: x8 [ x PERS: 3 NUM: sg GEND: n IND: - ] ]
          [ udef_q<9:24> LBL: h9 ARG0: x8 RSTR: h10 BODY: h11 ]
          [ _spread_v_1<9:18> LBL: h12 ARG0: e13 [ e SF: prop TENSE: untensed MOOD: indicative PROG: + PERF: - ] ARG1: x8 ARG2: p14 ARG3: h15 ]
          [ _dough_n_1<19:24> LBL: h12 ARG0: x8 ] >
  HCONS: < h0 qeq h1 h5 qeq h7 h10 qeq h12 h15 qeq h16 > ]
/Users/ar/venv/lib/python3.8/site-packages/delphin/dmrs/_operations.py:140: DMRSWarning: broken handle constraint: <HCons object (h15 qeq h16) at 4317271840>
  warnings.warn(
Sentence DMRS 1434

<dmrs cfrom="-1" cto="-1" top="10002" index="10002">
<node nodeid="10000" cfrom="0" cto="1"><realpred lemma="a" pos="q" /><sortinfo /></node>
<node nodeid="10001" cfrom="2" cto="5"><realpred lemma="man" pos="n" sense="1" /><sortinfo PERS="3" NUM="sg" IND="+" cvarsort="x" /></node>
<node nodeid="10002" cfrom="6" cto="8"><realpred lemma="be" pos="v" sense="id" /><sortinfo SF="prop" TENSE="pres" MOOD="indicative" PROG="-" PERF="-" cvarsort="e" /></node>
<node nodeid="10003" cfrom="9" cto="24"><gpred>udef_q</gpred><sortinfo /></node>
<node nodeid="10004" cfrom="9" cto="18"><realpred lemma="spread" pos="v" sense="1" /><sortinfo SF="prop" TENSE="untensed" MOOD="indicative" PROG="+" PERF="-" cvarsort="e" /></node>
<node nodeid="10005" cfrom="19" cto="24"><realpred lemma="dough" pos="n" sense="1" /><sortinfo PERS="3" NUM="sg" GEND="n" IND="-" cvarsort="x" /></node>
<link from="10000" to="10001"><rargname>RSTR</rargname><post>H</post></link>
<link from="10002" to="10001"><rargname>ARG1</rargname><post>NEQ</post></link>
<link from="10002" to="10005"><rargname>ARG2</rargname><post>NEQ</post></link>
<link from="10003" to="10005"><rargname>RSTR</rargname><post>H</post></link>
<link from="10004" to="10005"><rargname>ARG1</rargname><post>EQ</post></link>
</dmrs>

The profiles are https://www.dropbox.com/s/pbs1qgb8ih2uywl/profiles.zip?dl=0. The code for reproducing is

from delphin import ace
from delphin import itsdb
from delphin import tsql
from delphin import dmrs, eds
from delphin.codecs import eds as edsnative
from delphin.codecs import simplemrs
from delphin.codecs import dmrx

ts = itsdb.TestSuite('sentences-ap')
for row in tsql.select('i-id mrs', ts):

    m = simplemrs.decode(row[1])
    print("Sentence MRS %s\n" % row[0])
    print(simplemrs.encode(m, indent=True))

    d = dmrs.from_mrs(m)
    print("Sentence DMRS %s\n" % row[0])
    print(dmrx.encode(d, indent=True))

Can we make the transformation more robust? In the MRS above, the error is that h16 does not occurs in the predications, right? In such case, we could just ignore the this specific constraint h15 qeq h16?

Should we open an issue in the ERG repo?

arademaker commented 3 years ago

Moreover, the warn message is confusing. The warnings.warn( is not closed! Maybe it is mixing the STDERR and STDOUT outputs?

arademaker commented 3 years ago

Maybe it is already doing the right thing, just ignoring one edge in the DMRS.. but the warning is strange.

arademaker commented 3 years ago

After @goodmami directions, we maybe @yfaria @FredsoNerd

goodmami commented 3 years ago

The warnings.warn( thing is a Python thing that shows the line that issued the warning. It looks better when the full warning fits on one line:

$ cat warns.py 
import warnings
warnings.warn('caution!')
warnings.warn(
    'caution on the next line'
)
$ python3 warns.py 
warns.py:2: UserWarning: caution!
  warnings.warn('caution!')
warns.py:3: UserWarning: caution on the next line
  warnings.warn(

I don't think there's anything practical that I can do about that. The warnings should be printed to stderr:

$ cat z.mrs 
[ TOP: h0 INDEX: e3 [ e TENSE: past ]
  RELS: < [ _rain_v_1 LBL: h2 ARG0: e3 ] >
  HCONS: < > ]
$ delphin convert -t dmrx z.mrs 
/home/goodmami/delphin/pydelphin/delphin/dmrs/_operations.py:81: DMRSWarning: unusable TOP: h0
  warnings.warn(f'unusable TOP: {top_var}', dmrs.DMRSWarning)
<dmrs-list>
<dmrs cfrom="-1" cto="-1" index="10000">
<node nodeid="10000" cfrom="-1" cto="-1"><realpred lemma="rain" pos="v" sense="1" /><sortinfo TENSE="past" cvarsort="e" /></node>
</dmrs>
</dmrs-list>
$ delphin convert -t dmrx z.mrs 2>/dev/null
<dmrs-list>
<dmrs cfrom="-1" cto="-1" index="10000">
<node nodeid="10000" cfrom="-1" cto="-1"><realpred lemma="rain" pos="v" sense="1" /><sortinfo TENSE="past" cvarsort="e" /></node>
</dmrs>
</dmrs-list>

Is that not the case for you?

goodmami commented 3 years ago

It looks like there's nothing wrong with PyDelphin here, so I'm closing the issue as invalid.