Yes, I think I see the problem. The HCons
class is, for some reason, a subclass of tuple
, which allows you to subscript and unpack hcons objects:
>>> from delphin.codecs import simplemrs
>>> m = simplemrs.decode('[TOP: h0 INDEX: e2 RELS: < [ _rain_v_1 LBL: h1 ARG0: e2 [ e TENSE: pres ] ] > HCONS: < h0 qeq h1 > ]')
>>> hi, rel, lo = m.hcons[0]
>>> hi == m.hcons[0][0] == m.hcons[0].hi
True
The problem is that the tuple
parent class probably implements __deepcopy__()
to determine the behavior during copy.deepcopy()
, and tuples have different instantiation signatures than HCons
. HCons take 3 positional arguments, but tuples take a single iterable argument:
>>> from delphin import mrs
>>> mrs.HCons('h0', 'qeq', 'h1') # 3 positional arguments
hi='h0' relation='qeq' lo='h1'
<HCons object (h0 qeq h1) at 125837875857984>
>>> tuple(['h0', 'qeq', 'h1']) # single iterable argument
('h0', 'qeq', 'h1')
Giving HCons
a single iterable argument (or tuples multiple arguments) results in an error:
>>> mrs.HCons(['h0', 'qeq', 'h1'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: HCons.__new__() missing 2 required positional arguments: 'relation' and 'lo'
To fix the issue, we could do one of the following:
- Implement
__deepcopy__()
on the HCons
(or _Constraint
in PyDelphin) class
- Make
HCons
no longer be a subclass of tuple
- Find another way to copy the MRS, such as a serialization round-trip
For (3) above, you can try replacing the deepcopy lines with these:
s1_ = simplemrs.decode(simplemrs.encode(s1))
s2_ = simplemrs.decode(simplemrs.encode(s2))
It’s a bit inefficient, but it should give the intended result.