From 7921233ca6bf8c4ebf7fbbf38250cfd5f3a9c650 Mon Sep 17 00:00:00 2001 From: Michael Wayne Goodman Date: Wed, 11 Dec 2024 11:30:59 -0800 Subject: [PATCH 1/2] Enumerate entry/sense/synset ids for validation Fixes #228 --- CHANGELOG.md | 5 +++++ tests/data/E101-0.xml | 28 ++++++++++++++++++++++++++++ tests/data/E101-1.xml | 25 +++++++++++++++++++++++++ tests/data/E101-2.xml | 24 ++++++++++++++++++++++++ tests/data/E101-3.xml | 23 +++++++++++++++++++++++ tests/validate_test.py | 19 +++++++++++++++++++ wn/validate.py | 6 +++--- 7 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 tests/data/E101-0.xml create mode 100644 tests/data/E101-1.xml create mode 100644 tests/data/E101-2.xml create mode 100644 tests/data/E101-3.xml create mode 100644 tests/validate_test.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 0606cf2..cd2021f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ * `Sense.relation_map()` method ([#216]) * `Synset.relation_map()` method ([#167], [#216]) +## Fixed + +* Enumerate repeated entry, sense, synset IDs for validation ([#228]) + ## [v0.10.1] @@ -706,3 +710,4 @@ abandoned, but this is an entirely new codebase. [#215]: https://github.com/goodmami/wn/issues/215 [#216]: https://github.com/goodmami/wn/issues/216 [#221]: https://github.com/goodmami/wn/issues/221 +[#228]: https://github.com/goodmami/wn/issues/228 diff --git a/tests/data/E101-0.xml b/tests/data/E101-0.xml new file mode 100644 index 0000000..0ab813c --- /dev/null +++ b/tests/data/E101-0.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/E101-1.xml b/tests/data/E101-1.xml new file mode 100644 index 0000000..d8c925c --- /dev/null +++ b/tests/data/E101-1.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/E101-2.xml b/tests/data/E101-2.xml new file mode 100644 index 0000000..38a1822 --- /dev/null +++ b/tests/data/E101-2.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/E101-3.xml b/tests/data/E101-3.xml new file mode 100644 index 0000000..7c5b232 --- /dev/null +++ b/tests/data/E101-3.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/validate_test.py b/tests/validate_test.py new file mode 100644 index 0000000..41aae5c --- /dev/null +++ b/tests/validate_test.py @@ -0,0 +1,19 @@ +from collections.abc import Sequence +from pathlib import Path + +from wn import lmf +from wn.validate import validate + + +def _assert_invalid(select: str, path: Path) -> None: + lex = lmf.load(path, progress_handler=None)["lexicons"][0] + report = validate(lex, select=[select], progress_handler=None) + print(report) + assert len(report[select]["items"]) > 0 + + +def test_E101(datadir): + _assert_invalid("E101", datadir / "E101-0.xml") + _assert_invalid("E101", datadir / "E101-1.xml") + _assert_invalid("E101", datadir / "E101-2.xml") + _assert_invalid("E101", datadir / "E101-3.xml") diff --git a/wn/validate.py b/wn/validate.py index c5d387c..9e9dd4b 100644 --- a/wn/validate.py +++ b/wn/validate.py @@ -57,9 +57,9 @@ def _non_unique_id(lex: lmf.Lexicon, ids: _Ids) -> _Result: [lex['id']], (f['id'] for e in _entries(lex) for f in _forms(e) if f.get('id')), (sb['id'] for sb in lex.get('frames', []) if sb.get('id')), - ids['entry'], - ids['sense'], - ids['synset'], + ids['entry'].elements(), + ids['sense'].elements(), + ids['synset'].elements(), )) From a6c35b1cdf6402c60b99837d19100db46af3ddf1 Mon Sep 17 00:00:00 2001 From: Michael Wayne Goodman Date: Wed, 11 Dec 2024 11:35:33 -0800 Subject: [PATCH 2/2] Fix linting error --- tests/validate_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/validate_test.py b/tests/validate_test.py index 41aae5c..76935db 100644 --- a/tests/validate_test.py +++ b/tests/validate_test.py @@ -1,4 +1,3 @@ -from collections.abc import Sequence from pathlib import Path from wn import lmf