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

Retrieving synsets while in a loop over WordNet.words() raises RuntimeError #24

Open
goodmami opened this issue Jun 3, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@goodmami
Copy link
Collaborator

goodmami commented Jun 3, 2020

Somehow looking up the synsets for a word changes the underlying dictionary while iterating over it.

>>> import wn
>>> w = wn.WordNet()
>>> for word in w.words(lang='eng'):
...     w.synsets(word, pos='n')
... 
[]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/goodmami/postdoc/wnsd/env/lib/python3.8/site-packages/wn/__init__.py", line 184, in all_lemma_names
    for lemma_name in _lemma_pos_offset_map:
RuntimeError: dictionary changed size during iteration
@goodmami
Copy link
Collaborator Author

goodmami commented Jun 3, 2020

One workaround is to build the words list first:

>>> import wn
>>> w = wn.WordNet()
>>> words = list(w.words(lang='eng'))
>>> for word in words:
...     w.synsets(word, pos='n')
... 
>>>

@alvations
Copy link
Collaborator

Ah, because of that "smart" caching thing that original NLTK WN API was doing.

This is fixable. Let me put on the TODO.

@alvations alvations added the bug Something isn't working label Jun 3, 2020
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