Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synset.relations fails with a KeyError #177

Closed
dchaplinsky opened this issue Nov 11, 2022 · 3 comments
Closed

synset.relations fails with a KeyError #177

dchaplinsky opened this issue Nov 11, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@dchaplinsky
Copy link

Hi! I'm trying to collect a dataset of relations between words in the engilsh WordNet.

However when I run the following code

synset = wn.synset("omw-en31-00128106-n")
synset.relations()
``

it fails with the following traceback:

KeyError Traceback (most recent call last)
Cell In [18], line 1
----> 1 synset.relations()

File ~/Projects/wikidrill/venv/lib/python3.9/site-packages/wn/_core.py:662, in Synset.relations(self, *args)
641 """Return a mapping of relation names to lists of synsets.
642
643 One or more relation names may be given as positional
(...)
659
660 """
661 d: Dict[str, List['Synset']] = {}
--> 662 for relname, ss in self._get_relations(args):
663 if relname in d:
664 d[relname].append(ss)

File ~/Projects/wikidrill/venv/lib/python3.9/site-packages/wn/_core.py:713, in Synset._get_relations(self, args)
711 rel_type, ili = rel_row[0], rel_row[4]
712 if ili is not None:
--> 713 relations[rel_type].add(ili)
715 # map back to target lexicons
716 seen = {ss._id for _, ss in targets}

KeyError: 'hypernym'


Same applies to the example from the docstring of relations methods
@goodmami goodmami added the bug Something isn't working label Nov 13, 2022
@goodmami
Copy link
Owner

Thanks, I've reproduced the bug locally and I should I have a fix ready.

goodmami added a commit that referenced this issue Nov 14, 2022
Fix #177: KeyError on ILI-based relations queries
@goodmami
Copy link
Owner

@dchaplinsky a fix has been released in version 0.9.3. Please let me know if you still see the issue.

@dchaplinsky
Copy link
Author

Great, thanks for the fix. Could I humble recommend using defaultdict(set)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants