Comments (5)
The fix is proposed in many pull requests but it looks like the maintainer hasn't been active.
To fix it, go to $installation_path_of_pattern/text/__init__.py
Change line 608-609
yield line
raise StopIteration
to
This has made conjugate()
working for me in Python 3.7.4
from pattern.
instead of changing the source code, u can do monkey patching. i.e.
import os.path
import pattern.text
from pattern.helpers import decode_string
from codecs import BOM_UTF8
BOM_UTF8 = BOM_UTF8.decode("utf-8")
decode_utf8 = decode_string
def _read(path, encoding="utf-8", comment=";;;"):
"""Returns an iterator over the lines in the file at the given path,
strippping comments and decoding each line to Unicode.
"""
if path:
if isinstance(path, str) and os.path.exists(path):
# From file path.
f = open(path, "r", encoding="utf-8")
elif isinstance(path, str):
# From string.
f = path.splitlines()
else:
# From file or buffer.
f = path
for i, line in enumerate(f):
line = line.strip(BOM_UTF8) if i == 0 and isinstance(line, str) else line
line = line.strip()
line = decode_utf8(line, encoding)
if not line or (comment and line.startswith(comment)):
continue
yield line
pattern.text._read = _read
from pattern.
Hola, esto esta arreglado pero no en un release oficial, sino un fix de la comunidad. Es por una modificacion que se da a partir de 3.7+ que tiene que ver con algo de los generadores y que se yo que.
La solución esta ahi, pero yo tambien hice un fork y mergie una branch con arreglos de la comunidad.
from pattern.
Hi. Any idea how we can apply that fix on the library that hs been installed via pip?
from pattern.
Note that in my experience another, lazier fix, is that in your code you can run parse() 2-3 times and then the StopIteration error will stop occuring.
>>> from pattern.en import parse
>>> parse('This is a test.')
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/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 "/usr/local/lib/python3.8/site-packages/pattern/text/en/__init__.py", line 169, in parse
return parser.parse(s, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 1172, in parse
s[i] = self.find_tags(s[i], **kwargs)
File "/usr/local/lib/python3.8/site-packages/pattern/text/en/__init__.py", line 114, in find_tags
return _Parser.find_tags(self, tokens, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 1113, in find_tags
lexicon = kwargs.get("lexicon", self.lexicon or {}),
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 376, in __len__
return self._lazy("__len__")
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 368, in _lazy
self.load()
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 625, in load
dict.update(self, (x.split(" ")[:2] for x in _read(self._path) if len(x.split(" ")) > 1))
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 625, in <genexpr>
dict.update(self, (x.split(" ")[:2] for x in _read(self._path) if len(x.split(" ")) > 1))
RuntimeError: generator raised StopIteration
>>> parse('This is a test.')
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/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 "/usr/local/lib/python3.8/site-packages/pattern/text/en/__init__.py", line 169, in parse
return parser.parse(s, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 1172, in parse
s[i] = self.find_tags(s[i], **kwargs)
File "/usr/local/lib/python3.8/site-packages/pattern/text/en/__init__.py", line 114, in find_tags
return _Parser.find_tags(self, tokens, **kwargs)
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 1112, in find_tags
return find_tags(tokens,
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 1540, in find_tags
tagged = entities.apply(tagged)
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 976, in apply
if w in self:
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 382, in __contains__
return self._lazy("__contains__", *args)
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 368, in _lazy
self.load()
File "/usr/local/lib/python3.8/site-packages/pattern/text/__init__.py", line 959, in load
for x in _read(self.path):
RuntimeError: generator raised StopIteration
>>> parse('This is a test.')
'This/DT/O/O is/VBZ/B-VP/O a/DT/B-NP/O test/NN/I-NP/O ././O/O'
from pattern.
Related Issues (20)
- No module named 'pattern.en' on python 3.7.6 HOT 1
- ERROR: test_lexicon (__main__.TestLexicon)
- ERROR al instalar el módulo HOT 1
- Verb conjugation (Python 3.7-3.8) HOT 1
- Problematic lemmatization of 'thieves' and 'glass'
- Unexpected tokenization
- Why do I need mysql for a python package? HOT 1
- Conjugation of verbs with the ß in pattern.text.de appears to be broken
- Documentation of "pattern es" mismatch library code
- Mood if Statements Order
- Some invalid english verbs, missing forms
- Is Email pattern still working?
- Unexpected StopIteration exception being raised. HOT 1
- License Type issue
- Running Example Code Results in Exception HOT 1
- 'Thread' object has no attribute 'isAlive'
- pip install throws error - bin/sh: 1: mysql_config: not found HOT 3
- How can i use Neo4j with Pattern?
- Is this project active? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pattern.