标签: stanford-stanza

使用 Stanza 和 CoreNLPClient 提取名词短语

我正在尝试使用 Stanza(使用斯坦福 CoreNLP)从句子中提取名词短语。这只能通过 Stanza 中的 CoreNLPClient 模块来完成。

# Import client module
from stanza.server import CoreNLPClient
# Construct a CoreNLPClient with some basic annotators, a memory allocation of 4GB, and port number 9001
client = CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner', 'parse'], memory='4G', endpoint='http://localhost:9001')
Run Code Online (Sandbox Code Playgroud)

这是一个句子的例子,我正在使用tregrex客户端中的函数来获取所有名词短语。Tregex函数dict of dicts在python中返回a 。因此,我需要先处理 的输出,tregrex然后再将其传递给Tree.fromstringNLTK 中的函数,以将名词短语正确提取为字符串。

pattern = 'NP'
text = "Albert Einstein was a German-born theoretical physicist. He developed the theory of relativity."
matches = client.tregrex(text, pattern) ``
Run Code Online (Sandbox Code Playgroud)

因此,我想出了一种方法stanza_phrases,它必须循​​环遍历NLTK …

python nlp stanford-nlp stanford-stanza

3
推荐指数
1
解决办法
1129
查看次数

如何通过命令行下载节的模型?

可以通过 Python 下载一节的模型,如下镜像):

import stanza
stanza.download('en')       # This downloads the English models for the neural pipeline
Run Code Online (Sandbox Code Playgroud)

如何通过命令行下载节的模型?

例如,使用 spaCy 可以使用:

python -m spacy download en
Run Code Online (Sandbox Code Playgroud)

我尝试失败:

python -m stanza download en
Run Code Online (Sandbox Code Playgroud)

我用stanza==1.0.1

python nlp stanford-stanza

3
推荐指数
1
解决办法
964
查看次数

标签 统计

nlp ×2

python ×2

stanford-stanza ×2

stanford-nlp ×1