From 7588d51146bfce89b827fb661c3591144bc1297d Mon Sep 17 00:00:00 2001 From: Michael Wayne Goodman Date: Tue, 14 Jan 2020 17:07:59 +0800 Subject: [PATCH] Better deal with bad MRSs in conversion There are two separate issues that are fixed here: * When multiple non-quantifier EPs share an ARG0 it caused problems with mapping variables to quantifiers * When the INDEX was not used by any EP it caused a lookup error Fixes #267 --- CHANGELOG.md | 5 +++++ delphin/dmrs/_operations.py | 6 +++++- delphin/mrs/_mrs.py | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52835370..ed2dd955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ these changes are prefixed with "**BREAKING**" * `delphin.codecs.edspenman` now properly reads predicate names * `delphin.codecs.edspenman` and `delphin.codecs.dmrspenman` now wrap `PenmanError` in `PyDelphinException` ([#266][]) +* `delphin.mrs.MRS.quantification_pairs()` detects and ignores when + quantifier(s) are shared by multiple EPs ([#267][]) +* `delphin.dmrs.from_mrs()` detects when an INDEX is specified but is + not the intrinsic argument of any EP ([#267][]) ### Changed @@ -1248,4 +1252,5 @@ information about changes, except for [#263]: https://github.com/delph-in/pydelphin/issues/263 [#264]: https://github.com/delph-in/pydelphin/issues/264 [#266]: https://github.com/delph-in/pydelphin/issues/266 +[#267]: https://github.com/delph-in/pydelphin/issues/267 [#268]: https://github.com/delph-in/pydelphin/issues/268 diff --git a/delphin/dmrs/_operations.py b/delphin/dmrs/_operations.py index 9e5c5910..8858b87a 100644 --- a/delphin/dmrs/_operations.py +++ b/delphin/dmrs/_operations.py @@ -33,7 +33,11 @@ def from_mrs(m, representative_priority=None): for ep in m.rels if not ep.is_quantifier()} top = _mrs_get_top(m.top, hcmap, reps, id_to_nid) - index = iv_to_nid[m.index] if m.index else None + # some bad MRSs have an INDEX that isn't the ARG0 of any EP, so + # make sure it exists first + index = None + if m.index and m.index in iv_to_nid: + index = iv_to_nid[m.index] nodes = _mrs_to_nodes(m, id_to_nid) links = _mrs_to_links(m, hcmap, reps, iv_to_nid, id_to_nid) diff --git a/delphin/mrs/_mrs.py b/delphin/mrs/_mrs.py index ad132204..305078f5 100644 --- a/delphin/mrs/_mrs.py +++ b/delphin/mrs/_mrs.py @@ -290,7 +290,9 @@ def quantification_pairs(self): pairs.append((ep, qmap.get(ep.iv))) # then unpaired quantifiers, if any for _, q in pairs: - if q is not None: + # some bad MRSs have multiple EPs share an ARG0; avoid the + # KeyError by checking if they are still in qmap + if q is not None and q.iv in qmap: del qmap[q.iv] for q in qmap.values(): pairs.append((None, q))