delph-in / pydelphin

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

scopes and documentation #394

Closed arademaker closed 1 month ago

arademaker commented 2 months ago

https://pydelphin.readthedocs.io/en/latest/_modules/delphin/mrs/_mrs.html#MRS.scopes

""" Return a tuple containing the top label and the scope map.

    Note that the top label is different from :attr:`top`, which
    is the handle that is qeq to the top scope's label. If
    :attr:`top` does not select a top scope, the `None` is
    returned for the top label.

    The scope map is a dictionary mapping scope labels to the
    lists of predications sharing a scope.

"""

I am struggling with which is the handle that is qeq to the top scope's label. Maybe which is the handle that is qeq to one of the scope's label??

goodmami commented 1 month ago

By scope, I mean the conjunction of EPs that share a position in the scope tree, so the top scope would be the scope that is highest in the (still underspecified) scope tree. The top scope's label is thus the value of LBL shared by the EPs in that scope.

Consider: The dog barked loudly.

[ "The dog barked loudly."
  TOP: h0
  INDEX: e2 [ e SF: prop TENSE: past MOOD: indicative PROG: - PERF: - ]
  RELS: < [ _the_q<0:3> LBL: h4 ARG0: x3 [ x PERS: 3 NUM: sg IND: + ] RSTR: h5 BODY: h6 ]
          [ _dog_n_1<4:7> LBL: h7 ARG0: x3 ]
          [ _bark_v_1<8:14> LBL: h1 ARG0: e2 ARG1: x3 ]
          [ _loud_a_1<15:22> LBL: h1 ARG0: e8 [ e SF: prop TENSE: untensed MOOD: indicative PROG: - PERF: - ] ARG1: e2 ] >
  HCONS: < h0 qeq h1 h5 qeq h7 > ]

The top attribute would point to the value of TOP in the MRS:

>>> m.top
'h0'

The top label in the scope tree would be h1, since h0 qeq h1 in the HCONS.

>>> from delphin import ace
>>> m = ace.parse("../erg-2018-x86-64-0.9.34.dat", "The dog barked loudly.").result(0).mrs()
NOTE: parsed 1 / 1 sentences, avg 1802k, time 0.00661s
>>> top_label, scope_map = m.scopes()
>>> print(top_label)
h1
>>> for label, scopes in scope_map.items():
...     print(label, scopes)
... 
h4 [<EP object (h4:_the_q(ARG0 x3, RSTR h5, BODY h6)) at 140373746374624>]
h7 [<EP object (h7:_dog_n_1(ARG0 x3)) at 140373746374432>]
h1 [<EP object (h1:_bark_v_1(ARG0 e2, ARG1 x3)) at 140373746374720>, <EP object (h1:_loud_a_1(ARG0 e8, ARG1 e2)) at 140373746374912>]

The scope pointed to by h1 is _bark_v_1 ^ _loud_a_1. However the fully-specified scope tree works out, those two EPs should be on top.