NLTK CoreNLPDependencyParser:无法建立连接

编程入门 行业动态 更新时间:2024-10-28 02:36:14
本文介绍了NLTK CoreNLPDependencyParser:无法建立连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过示例此处.

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

I follow the first two lines of the example (with the necessary import)

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

但我收到一条错误消息:

but I get an error saying:

[...] Failed to establish a new connection: [Errno 61] Connection refused"

我意识到尝试连接到作为构造函数输入的url一定是一个问题.

I realize that it must be an issue with trying to connect to the url given as input to the constructor.

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

如果不是,我应该连接到哪个URL?如果正确,那是什么问题?

What url should I be connecting to, if not this? If this is correct, what is the issue?

推荐答案

您需要先下载localhost:9000并运行CoreNLP服务器.

You need to first download and run the CoreNLP server on localhost:9000.

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

1) download CoreNLP at stanfordnlp.github.io/CoreNLP/download.html 2) unzip the files to some directory then run the following command in the that directory to start the server

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

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

上面的代码的结果就像

>>> print(parse.to_conll(4)) The DT 4 det quick JJ 4 amod brown JJ 4 amod fox NN 5 nsubj jumps VBZ 0 ROOT over IN 9 case the DT 9 det lazy JJ 9 amod dog NN 5 nmod . . 5 punct

您还可以通过NLTK API启动服务器(需要先配置CORENLP_HOME环境变量)

You can also start the server via NLTK API (need to configure the CORENLP_HOME environment variable first)

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

更多推荐

NLTK CoreNLPDependencyParser:无法建立连接

本文发布于:2023-11-15 04:47:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591284.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NLTK   CoreNLPDependencyParser

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!