polyglot icon indicating copy to clipboard operation
polyglot copied to clipboard

List index out of range

Open GJena opened this issue 8 years ago • 9 comments

Windows 8.1 Python 3.5 Trying to run the NER example given in the documentation and it results in a list index out of range error.

GJena avatar Jun 20 '16 22:06 GJena

Hi, @GJena , thanks for pointing it out. Can you provide more details, like the stacktrace when the error happens?

alantian avatar Jul 03 '16 17:07 alantian

List index out of range occurs also to me:

Environment: (Win10, Anaconda, Conda, python 2.7, PyICU installed from github and PyCLD2 installed from whl)

Language Detection and Tokenization examples run correctly, but from there on examples fail.

Here is the code:

-- coding: utf-8 --

import polyglot from polyglot.text import Text, Word text = Text(u"O primeiro uso de desobediência civil em massa ocorreu em setembro de 1906.")

print("{:<16}{}".format("Word", "POS Tag")+"\n"+"-"*30) for word, tag in text.pos_tags: print(u"{:<16}{:>2}".format(word, tag))


and here is Traceback

Traceback (most recent call last): File "C:/Users/Petteri/PycharmProjects/Polyglot/Testi.py", line 8, in for word, tag in text.pos_tags: File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\decorators.py", line 20, in get value = obj.dict[self.func.name] = self.func(obj) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\text.py", line 155, in pos_tags for word,t in self.pos_tagger.annotate(self.words): File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\decorators.py", line 20, in get value = obj.dict[self.func.name] = self.func(obj) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\text.py", line 104, in pos_tagger return get_pos_tagger(lang=self.language.code) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\decorators.py", line 30, in memoizer cache[key] = obj(_args, *_kwargs) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\tag\base.py", line 181, in get_pos_tagger return POSTagger(lang=lang) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\tag\base.py", line 131, in init super(POSTagger, self).init(lang=lang) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\tag\base.py", line 40, in init self.predictor = self._load_network() File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\tag\base.py", line 137, in _load_network self.embeddings = load_embeddings(self.lang, type='cw') File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\decorators.py", line 30, in memoizer cache[key] = obj(_args, *_kwargs) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\load.py", line 61, in load_embeddings p = locate_resource(src_dir, lang) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\load.py", line 43, in locate_resource if downloader.status(package_id) != downloader.INSTALLED: File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\downloader.py", line 737, in status info = self._info_or_id(info_or_id) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\downloader.py", line 507, in _info_or_id return self.info(info_or_id) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\downloader.py", line 929, in info self._update_index() # If package is not found, most probably we did not File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\downloader.py", line 843, in _update_index P = Package.fromcsobj(p) File "C:\Anaconda2\envs\polyglot\lib\site-packages\polyglot\downloader.py", line 216, in fromcsobj language = subdir.split(path.sep)[1] IndexError: list index out of range


petteri72 avatar Aug 18 '16 19:08 petteri72

I get the same error. window 7, 64 bit, Python 3.5 anaconda, installed pyicu and pycld2 wheels from http://www.lfd.uci.edu/~gohlke/pythonlibs/ It seems to happen whenever the downloader gets involved or when I try to call the downloader directly: print(downloader.models())

IndexError                                Traceback (most recent call last)
<ipython-input-16-5df9209721dc> in <module>()
----> 1 print(downloader.models())

C:\Program Files\Anaconda3\lib\site-packages\polyglot-16.7.4-py3.5.egg\polyglot\downloader.py in models(self)
    491 
    492   def models(self):
--> 493     self._update_index()
    494     return [pkg for (id,pkg) in self._packages.items()
    495         if pkg.subdir != 'corpora']

C:\Program Files\Anaconda3\lib\site-packages\polyglot-16.7.4-py3.5.egg\polyglot\downloader.py in _update_index(self, url)
    841     packages = []
    842     for p in objs:
--> 843       P = Package.fromcsobj(p)
    844       packages.append(P)
    845     self._packages = dict((p.id, p) for p in packages)

C:\Program Files\Anaconda3\lib\site-packages\polyglot-16.7.4-py3.5.egg\polyglot\downloader.py in fromcsobj(csobj)
    214     filename = attrs["name"]
    215     task = subdir.split(path.sep)[0]
--> 216     language = subdir.split(path.sep)[1]
    217     attrs = attrs
    218     return Package(**locals())

IndexError: list index out of range

sabriwi avatar Feb 23 '17 11:02 sabriwi

ok, the solution was hidden here https://github.com/aboSamoor/polyglot/issues/12

sabriwi avatar Feb 23 '17 11:02 sabriwi

@petteri72 did it resolved?

devappamazing avatar May 08 '17 16:05 devappamazing

Now it works :) To solve this issue: I replace path.sep with "/" (4 items in lines number: 208, 210, 215 and 216) at file "C:\Python36\Lib\site-packages\polyglot\downloader.py", ("fromcsobj" function in line 205)

ehsanasgarian avatar Mar 12 '19 07:03 ehsanasgarian

@ehsanasgarian This method doesn't work...I replace 4 items in function "fromcsobj"

Seymour0724 avatar Sep 26 '21 01:09 Seymour0724

@ehsanasgarian @Seymour0724 This method doesn't work for me too. Do you have any update? thanks!

RyanXu11 avatar Feb 09 '23 22:02 RyanXu11

After restart "jupyter lab" in powershell, it works! So please don't forget restart jupyter in command. Thank you everybody.

RyanXu11 avatar Feb 10 '23 10:02 RyanXu11