Skip to content

Commit

Permalink
Fix #215 Look at dc:type when validating relations
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmami committed Nov 2, 2024
1 parent 0355d9a commit ff8e342
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
19 changes: 16 additions & 3 deletions wn/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ff8e342

Please sign in to comment.