Expanding the pydelphin isomorphism check

The MRS class already has a top attribute. In an MRS for a full sentence, this is the GTOP that is qeq to the graph’s top handle, but in principle it could also serve as an LTOP handle during MRS construction. Does this not work for you?

Well, yes, but it also ignores the existing top as well. I didn’t include it previously because it wasn’t necessary as the h0 qeq hX constraint on HCONS was enough to identify the top, but if top is only an EP’s label I can see why it might need to be included explicitly.

Before checking isomorphism, PyDelphin transforms the MRS into what it calls an “isograph”, which is a simplified form of the MRS graph of the form g[source][target] = edge_label. You can modify the _make_mrs_isograph() function after these lines:

by inserting something like:

    g["*top*"][x.top] = "TOP"

or if you want to use the code as-is, you could insert an ad hoc qeq like this:

from copy import deepcopy

def is_sement_isomorphic(s1: MRS, s2: MRS) -> bool:
    s1_ = deepcopy(s1)  # don't modify the original
    s2_ = deepcopy(s2)
    s1_.hcons.append(HCons.qeq("*top*", s1_.top))
    s2_.hcons.append(HCons.qeq("*top*", s2_.top))
    return is_isomorphic(s1_, s2_)

I haven’t tested the above, but the idea is that the explicit qeq will be picked up by the _make_mrs_isograph() function.