From ff8e342b220324a7b2bd0e09788d6c3247f33e16 Mon Sep 17 00:00:00 2001 From: Michael Wayne Goodman Date: Fri, 1 Nov 2024 21:34:26 -0700 Subject: [PATCH] Fix #215 Look at dc:type when validating relations --- CHANGELOG.md | 2 ++ wn/validate.py | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef2d3da..fcacfe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Follow redirects with `httpx.Client` in `wn._download` ([#211]) * Remove reverse relations for `pertainym` and `also` ([#213]) +* Validate redundant relations considering `dc:type` ([#215]) ## [v0.10.0] @@ -680,3 +681,4 @@ abandoned, but this is an entirely new codebase. [#207]: https://github.com/goodmami/wn/issues/207 [#211]: https://github.com/goodmami/wn/issues/211 [#213]: https://github.com/goodmami/wn/issues/213 +[#215]: https://github.com/goodmami/wn/issues/215 diff --git a/wn/validate.py b/wn/validate.py index cba02f5..c5d387c 100644 --- a/wn/validate.py +++ b/wn/validate.py @@ -153,10 +153,19 @@ def _invalid_relation_type(lex: lmf.Lexicon, ids: _Ids) -> _Result: def _redundant_relation(lex: lmf.Lexicon, ids: _Ids) -> _Result: """redundant relation between source and target""" redundant = _multiples(chain( - ((s['id'], r['relType'], r['target']) for s, r in _sense_relations(lex)), - ((ss['id'], r['relType'], r['target']) for ss, r in _synset_relations(lex)), + ( + (s['id'], r['relType'], r['target'], _get_dc_type(r)) + for s, r in _sense_relations(lex) + ), + ( + (ss['id'], r['relType'], r['target'], _get_dc_type(r)) + for ss, r in _synset_relations(lex) + ), )) - return {src: {'type': typ, 'target': tgt} for src, typ, tgt in redundant} + return { + src: ({'type': typ, 'target': tgt} | ({'dc:type': dctyp} if dctyp else {})) + for src, typ, tgt, dctyp in redundant + } def _missing_reverse_relation(lex: lmf.Lexicon, ids: _Ids) -> _Result: @@ -215,6 +224,10 @@ def _synset_relations(lex: lmf.Lexicon) -> Iterator[tuple[lmf.Synset, lmf.Relati yield (ss, r) +def _get_dc_type(r: lmf.Relation) -> Optional[str]: + return (r.get('meta') or {}).get('type') + + # Check codes and messages # # categories: