Skip to content

Commit

Permalink
Fix #148: serialize LMF metadata properly
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmami committed Nov 4, 2021
1 parent 77222c6 commit a50e537
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

* `wn.lmf` now serialized DC and non-DC metadata correctly ([#148])


## [v0.8.2]

Expand Down Expand Up @@ -462,3 +466,4 @@ abandoned, but this is an entirely new codebase.
[#123]: https://github.com/goodmami/wn/issues/123
[#124]: https://github.com/goodmami/wn/issues/124
[#125]: https://github.com/goodmami/wn/issues/125
[#148]: https://github.com/goodmami/wn/issues/148
5 changes: 3 additions & 2 deletions tests/data/mini-lmf-1.0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Spanish:
email="[email protected]"
license="https://creativecommons.org/licenses/by/4.0/"
version="1"
url="https://example.com/test-en">
url="https://example.com/test-en"
dc:description="An example lexicon for testing.">

<LexicalEntry id="test-en-information-n">
<Lemma partOfSpeech="n" writtenForm="information" script="Latn">
Expand All @@ -37,7 +38,7 @@ Spanish:
</Sense>
</LexicalEntry>

<LexicalEntry id="test-en-example-n">
<LexicalEntry id="test-en-example-n" confidenceScore="1.0">
<Lemma partOfSpeech="n" writtenForm="example" />
<Sense id="test-en-example-n-0002-01" synset="test-en-0002-n" >
<SenseRelation relType="derivation" target="test-en-exemplify-v-0003-01" />
Expand Down
12 changes: 9 additions & 3 deletions wn/lmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,15 @@ def _indent(elem: ET.Element, level: int) -> None:

def _meta_dict(m: Optional[Metadata]) -> Dict[str, str]:
if m:
d = {f'dc:{key}': str(val)
for key, val in zip(m._fields, m)
if val is not None}
d = {f'dc:{key}': str(getattr(m, key))
for key in _DC_ATTRS
if getattr(m, key, None) is not None}
if m.status is not None:
d['status'] = m.status
if m.note is not None:
d['note'] = m.note
if m.confidence is not None:
d['confidenceScore'] = str(m.confidence)
else:
d = {}
return d

0 comments on commit a50e537

Please sign in to comment.