# Expanding the pydelphin isomorphism check

**URL:** <https://delphinqa.ling.washington.edu/t/expanding-the-pydelphin-isomorphism-check/1098>\
**Category:** PyDelphin Tools\
**Created:** [February 12, 2025, 10:17pm UTC](https://delphinqa.ling.washington.edu/t/expanding-the-pydelphin-isomorphism-check/1098 "2025-02-12T22:17:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![goodmami](https://delphinqa.ling.washington.edu/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@goodmami](https://delphinqa.ling.washington.edu/u/goodmami)\
**Post date:** [February 15, 2025, 7:08pm UTC](https://delphinqa.ling.washington.edu/t/expanding-the-pydelphin-isomorphism-check/1098/2 "2025-02-15T19:08:57Z")

</div>

> [@ecconrad](#):
>
> I wrote a subclass of PyDelphin’s MRS called SEMENT that adds `ltop` so I can work with them compositionally.

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?

> [@ecconrad](#):
>
> […] the isomorphism check just ignores it (I think).

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.

> [@ecconrad](#):
>
> What would be involved in having the isomorphism check also consider the LTOP?

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:

> <https://github.com/delph-in/pydelphin/blob/77893cbdb5448fb3eb5224a375ea241ea15e9b94/delphin/mrs/_operations.py#L168-L171>

by inserting something like:

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

```

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

```python
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.

---

_[View the full topic](https://delphinqa.ling.washington.edu/t/expanding-the-pydelphin-isomorphism-check/1098)._
