0

我在使用 polyglot 时遇到问题......它是 polyglot 中的错误吗?下面提供的是代码

import polyglot

from polyglot.downloader import downloader
print(downloader.supported_languages_table("ner2", 3))

以下代码的问题也仍然存在

import polyglot
from polyglot.text import Text, Word
blob = """The Israeli Prime Minister Benjamin Netanyahu has warned that Iran poses a "threat to the 
          entire world"."""
text = Text(blob)
text.entities

输出错误:IndexError: list index out of range 下面是我收到的第一个代码块的回溯。即使是第二个,我也收到了第二个代码块。感谢您的帮助:)

IndexError                                Traceback (most recent call 
last)
<ipython-input-5-3795737b065a> in <module>
  1 from polyglot.downloader import downloader
----> 2 print(downloader.supported_languages_table("ner2", 3))

~\anaconda3\lib\site-packages\polyglot\downloader.py in 
supported_languages_table(self, task, cols)
    976 
    977   def supported_languages_table(self, task, cols=3):
--> 978     languages = self.supported_languages(task)
    979     return pretty_list(languages)
    980 

~\anaconda3\lib\site-packages\polyglot\downloader.py in 
supported_languages(self, task)
    968     """
    969     if task:
--> 970       collection = self.get_collection(task=task)
    971       return [isoLangs[x.id.split('.')[1]]["name"]
    972                                          for x in 
              collection.packages]

~\anaconda3\lib\site-packages\polyglot\downloader.py in 
 get_collection(self, lang, task)
    944     else: raise ValueError("You should pass either the task or the 
    lang")
    945     try:
--> 946       return self.info(id)
    947     except ValueError as e:
    948       if lang: raise LanguageNotSupported("Language {} is not 
              supported".format(id))

~\anaconda3\lib\site-packages\polyglot\downloader.py in info(self, id)
    927     if id in self._packages: return self._packages[id]           
    928     if id in self._collections: return self._collections[id]
--> 929     self._update_index() # If package is not found, most probably 
            we did not
    930                          # warm up the cache
    931     if id in self._packages: return self._packages[id]

~\anaconda3\lib\site-packages\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)

~\anaconda3\lib\site-packages\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:列表索引超出范围

4

1 回答 1

0

我找到了一个解决方案,它在文件“C:\Python36\Lib\site-packages\polyglot\downloader.py ", ("fromcsobj" 函数在第 205 行)。

于 2021-09-26T01:23:56.377 回答