简体   繁体   English

Spacy/Textacy 不从 .txt(文本)文件中读取文件内容

[英]Spacy/Textacy not reading file contents from .txt (text) file

I am trying to read the contents (blog) from a text file using Python (SpaCy/Textacy/Textblob) but it has been in vain, so far.我正在尝试使用 Python (SpaCy/Textacy/Textblob) 从文本文件中读取内容(博客),但到目前为止都是徒劳的。 Following is the code that I have recently tried:以下是我最近尝试过的代码:

import content as content
import pattern as pattern
import textacy
import spacy
nlp = spacy.load('en')
verb_clause_pattern = r'<VERB><ADV><PART><VERB>+<PART>'
doc = textacy.Doc.content, lang = 'en'
lists = textacy.extract.pos_regex_matches(doc, pattern)
for list in lists:
    print(list.text)

And I am getting following error:我收到以下错误:

    "E:\TWP\TWP\venv\Scripts\python.exe E:/TWP/TWP/VerbPhrases.py
    Traceback (most recent call last):
      File "E:/TWP/TWP/VerbPhrases.py", line 5, in <module>
        nlp = spacy.load('en')
      File "E:\TWP\TWP\venv\lib\site-packages\spacy\__init__.py", line 30, in load
        return util.load_model(name, **overrides)
      File "E:\TWP\TWP\venv\lib\site-packages\spacy\util.py", line 169, in load_model
        raise IOError(Errors.E050.format(name=name))
    OSError: [E050] Can't find model 'en'. It doesn't seem to be a shortcut link, a Python package or a valid path to a data directory."

This is most probably a linking error caused by spaCy.这很可能是由 spaCy 引起的链接错误。 I keep getting this error.我不断收到此错误。 I managed to fix it by running this in Anaconda terminal for example:我设法通过在 Anaconda 终端中运行它来修复它,例如:

python -m spacy download en

Make sure you open the Anaconda terminal as an Administrator for the linking to work on Windows.确保您以管理员身份打开 Anaconda 终端,以便在 Windows 上进行链接。

If you are using Ubuntu Linux, try this:如果您使用的是 Ubuntu Linux,请尝试以下操作:

sudo python -m spacy.en.download all

In the latest release of spaCy, you can now choose between importing or linking.在最新版本的 spaCy 中,您现在可以选择导入或链接。 You may refer to this github issue for more details:你可以参考这个 github issue了解更多细节:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM