NLTK CoreNLPDependencyParser:无法建立连接

2024-05-16 00:35:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试通过NLTK使用Stanford解析器,遵循示例here。在

我遵循示例的前两行(带有必要的导入)

from nltk.parse.corenlp import CoreNLPDependencyParser
dep_parser = CoreNLPDependencyParser(url='http://localhost:9000')
parse, = dep_parser.raw_parse('The quick brown fox jumps over the lazy dog.')

但我有个错误说:

^{pr2}$

我意识到,试图连接到作为构造函数输入的url肯定是个问题。在

dep_parser = CoreNLPDependencyParser(url='http://localhost:9000')

如果不是这个,我应该连接到哪个url?如果这是正确的,问题是什么?在


Tags: fromlocalhosthttpparser解析器url示例here
1条回答
网友
1楼 · 发布于 2024-05-16 00:35:20

您需要首先在localhost:9000上下载并运行CoreNLP服务器。在

1)下载CoreNLP,网址:https://stanfordnlp.github.io/CoreNLP/download.html
2) 将文件解压缩到某个目录,然后在该目录下运行以下命令以启动服务器

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

参考号:https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

上面代码的结果是

^{pr2}$

也可以通过nltkapi启动服务器(需要先配置CORENLP_HOME环境变量)

os.environ["CORENLP_HOME"] = "dir"
client = corenlp.CoreNLPClient()
# do something
client.stop()

相关问题 更多 >