我使用多语时有问题…这是多语言的bug吗?下面是代码
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:列表索引超出范围下面是我收到的第一个代码块的回溯。即使是第二次,我收到的第二个代码块…任何帮助都是感激的谢谢:)
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))
~anaconda3libsite-packagespolyglotdownloader.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
~anaconda3libsite-packagespolyglotdownloader.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]
~anaconda3libsite-packagespolyglotdownloader.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))
~anaconda3libsite-packagespolyglotdownloader.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]
~anaconda3libsite-packagespolyglotdownloader.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)
~anaconda3libsite-packagespolyglotdownloader.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
我找到了一个解决方案,它替换了4项路径。Sep with "/"(在文件"C:Python36Libsite-packagespolyglotdownload .py", (" fromsobj"函数(第205行)。