在 jupyter 中安装 polyglot 后,我正在运行以下代码:
import polyglot
from polyglot.text import Text, Word
from polyglot.detect import Detector
h_proc = cleaned_text['text']
words = []
for words in h_proc[:50]:
for word in words:
pglot = Text(word)
words.append(pglot.morphemes)
words
我在以下位置收到错误words.append(pglot.morphemes)
:
HTTPError Traceback (most recent call last)
<ipython-input-25-08d428bde3b6> in <module>
12 for word in words:
13 pglot = Text(word)
---> 14 words.append(pglot.morphemes)
15
16 words
~\anaconda3\lib\site-packages\polyglot\decorators.py in __get__(self, obj, cls)
18 if obj is None:
19 return self
---> 20 value = obj.__dict__[self.func.__name__] = self.func(obj)
21 return value
22
~\anaconda3\lib\site-packages\polyglot\text.py in morphemes(self)
111 @cached_property
112 def morphemes(self):
--> 113 words, score = self.morpheme_analyzer.viterbi_segment(self.raw)
114 return WordList(words, language=self.language.code, parent=self)
115
~\anaconda3\lib\site-packages\polyglot\decorators.py in __get__(self, obj, cls)
18 if obj is None:
19 return self
---> 20 value = obj.__dict__[self.func.__name__] = self.func(obj)
21 return value
22
~\anaconda3\lib\site-packages\polyglot\text.py in morpheme_analyzer(self)
102 @cached_property
103 def morpheme_analyzer(self):
--> 104 return load_morfessor_model(lang=self.language.code)
105
106 def transliterate(self, target_language="en"):
~\anaconda3\lib\site-packages\polyglot\decorators.py in memoizer(*args, **kwargs)
28 key = tuple(list(args) + sorted(kwargs.items()))
29 if key not in cache:
---> 30 cache[key] = obj(*args, **kwargs)
31 return cache[key]
32 return memoizer
~\anaconda3\lib\site-packages\polyglot\load.py in load_morfessor_model(lang, version)
126 """
127 src_dir = "morph{}".format(version)
--> 128 p = locate_resource(src_dir, lang)
129 file_handler = _open(p)
130 tmp_file_ = NamedTemporaryFile(delete=False)
~\anaconda3\lib\site-packages\polyglot\load.py in locate_resource(name, lang, filter)
45 p = path.join(polyglot_path, task_dir, lang)
46 if not path.isdir(p):
---> 47 if downloader.status(package_id) != downloader.INSTALLED:
48 raise ValueError("This resource is available in the index "
49 "but not downloaded, yet. Try to run\n\n"
~\anaconda3\lib\site-packages\polyglot\downloader.py in status(self, info_or_id, download_dir)
735 """
736 if download_dir is None: download_dir = self._download_dir
--> 737 info = self._info_or_id(info_or_id)
738
739 # Handle collections:
~\anaconda3\lib\site-packages\polyglot\downloader.py in _info_or_id(self, info_or_id)
505 def _info_or_id(self, info_or_id):
506 if isinstance(info_or_id, unicode):
--> 507 return self.info(info_or_id)
508 else:
509 return info_or_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)
829 elif source == 'mirror':
830 index_url = path.join(self._url, 'index.json')
--> 831 data = urlopen(index_url).read()
832
833 if six.PY3:
~\anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
~\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response
~\anaconda3\lib\urllib\request.py in http_response(self, request, response)
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
642
~\anaconda3\lib\urllib\request.py in error(self, proto, *args)
561 http_err = 0
562 args = (dict, proto, meth_name) + args
--> 563 result = self._call_chain(*args)
564 if result:
565 return result
~\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result
~\anaconda3\lib\urllib\request.py in http_error_302(self, req, fp, code, msg, headers)
753 fp.close()
754
--> 755 return self.parent.open(new, timeout=req.timeout)
756
757 http_error_301 = http_error_303 = http_error_307 = http_error_302
~\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response
~\anaconda3\lib\urllib\request.py in http_response(self, request, response)
638 # request was successfully received, understood, and accepted.
639 if not (200 <= code < 300):
--> 640 response = self.parent.error(
641 'http', request, response, code, msg, hdrs)
642
~\anaconda3\lib\urllib\request.py in error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
570
571 # XXX probably also want an abstract factory that knows when it makes
~\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result
~\anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden
我不知道为什么我会得到这个,而且这个错误似乎没有太多背景。
我使用以下代码在我的 Windows 电脑上安装 polyglot:
!pip install pycld2-0.41-cp38-cp38-win_amd64.whl
!pip install PyICU-2.7.2-cp38-cp38-win_amd64.whl
!pip install Morfessor-2.0.6-py3-none-any.whl
!git clone https://github.com/aboSamoor/polyglot
!pip install -r polyglot\requirements.txt
!pip install polyglot
请帮忙!