clips / pattern

Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.
https://github.com/clips/pattern/wiki
BSD 3-Clause "New" or "Revised" License
8.72k stars 1.58k forks source link

RuntimeError: generator raised StopIteration in Dutch verb conjugation #295

Open EmmaGerritse opened 4 years ago

EmmaGerritse commented 4 years ago

When running the following code:

import pattern.nl
from pattern.nl import conjugate
from pattern.nl import PRESENT, SG, PAST
conjugate("ben", PRESENT, 3, SG)

I get the following error:

Traceback (most recent call last):
  File "/home/emma/miniconda3/lib/python3.7/site-packages/Pattern-3.6-py3.7.egg/pattern/text/__init__.py", line 609, in _read
    raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/emma/miniconda3/lib/python3.7/site-packages/Pattern-3.6-py3.7.egg/pattern/text/__init__.py", line 2208, in conjugate
    b = self.lemma(verb, parse=kwargs.get("parse", True))
  File "/home/emma/miniconda3/lib/python3.7/site-packages/Pattern-3.6-py3.7.egg/pattern/text/__init__.py", line 2172, in lemma
    self.load()
  File "/home/emma/miniconda3/lib/python3.7/site-packages/Pattern-3.6-py3.7.egg/pattern/text/nl/inflect.py", line 246, in load
    _Verbs.load(self)
  File "/home/emma/miniconda3/lib/python3.7/site-packages/Pattern-3.6-py3.7.egg/pattern/text/__init__.py", line 2127, in load
    for v in _read(self._path):
RuntimeError: generator raised StopIteration

However, if I run conjugate("ben", PRESENT, 3, SG) again in the same shell it works as expected.

ichuniq commented 4 years ago

This is one of the behaviors applied in python 3.7 and Pattern is based on 3.6. This is also discussed in #282 #283 and stackoverflow

Pikamander2 commented 3 years ago

This appears to be an easy workaround:

def pattern_stopiteration_workaround():
    try:
        print(lexeme('gave'))
    except:
        pass

def main():
    pattern_stopiteration_workaround()
    #Add your other code here

Basically, the pattern code will fail the first time you run it, so you first need to run it once and catch the Exception it throws.

It's worked well enough for my own scripts, but I don't know if it fixes every possible issue.

Ideally though, somebody should fork the clips/pattern project since it's no longer maintained.