aboSamoor / polyglot

Multilingual text (NLP) processing toolkit
http://polyglot-nlp.com
Other
2.31k stars 337 forks source link

Error Slicing polyglot.text.Chunk #81

Open ghost opened 7 years ago

ghost commented 7 years ago

A polyglot.text.Chunk can be indexed to extract the words within the Chunk. This is a handy shortcut! But, I found a little bug when you try to slice a Chunk:

some_chunk[:]

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-30-463af73407c0> in <module>()
----> 1 some_chunk[:]

/usr/local/lib/python3.5/dist-packages/polyglot/text.py in __getitem__(self, key)
    351     """Returns a string at the given index."""
    352     if isinstance(key, slice):
--> 353         return self.__class__(self._collection[key])
    354     else:
    355         return self._collection[key]

/usr/local/lib/python3.5/dist-packages/polyglot/text.py in __init__(self, subsequence, start_index, end_index, tag, parent)
    415     self.start = start_index
    416     #: The end index within a Text
--> 417     self.end = end_index or len(sentence) - 1
    418     class_name = self.__class__.__name__
    419     self.tag = tag if tag else class_name

NameError: name 'sentence' is not defined