首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何确保为节CoreNLPClient提供一个可行的端点?

如何确保为节CoreNLPClient提供一个可行的端点?
EN

Stack Overflow用户
提问于 2021-07-19 10:10:00
回答 2查看 99关注 0票数 1

我想使用节CoreNLPClient提取名词短语,类似于this method

但是,我似乎找不到一个好的端口来启动服务器。缺省值为9000,但这经常被占用,如错误消息所示:

PermanentlyFailedException:错误:无法在端口9000上启动CoreNLP服务器(可能有些东西已经在那里运行)

编辑: python.exe正在使用端口9000,这就是为什么我不能关闭进程来为CoreNLPClient腾出空间。

然后,当我选择其他端口(如7999、8000或8080 )时,服务器一直不确定地监听,不执行连续的代码行,只显示以下内容:

edu.stanford.nlp.pipeline.StanfordCoreNLPServer

2021-07-19 12:05:55信息:命令启动服务器: java -Xmx8G -cp C:\Users\timjo\stanza_corenlp* -port 7998 -timeout 60000 -threads 5 -maxCharLength 100000 -quiet True -serverProperties corenlp_ server -2e15724b8064491b.props -preload -outputFormat

我安装了最新版本的stanza,并且正在从VS代码中的.ipynb文件中运行以下代码:

代码语言:javascript
运行
复制
# sample sentence
sentence = "Albert Einstein was a German-born theoretical physicist." 

# start the client as indicated in the docs
with CoreNLPClient(properties='corenlp_server-2e15724b8064491b.props', endpoint='https://localhost:7998', memory='8G', be_quiet=True) as client:
     matches = client.tregex(text=sentence, pattern = 'NP')

# extract the noun phrases and their indices
noun_phrases = [[text, begin, end] for text, begin, end in
     zip([sentence[match_id]['spanString'] for sentence in matches['sentences'] for match_id in sentence],
         [sentence[match_id]['characterOffsetBegin'] for sentence in matches['sentences'] for match_id in sentence],
         [sentence[match_id]['characterOffsetEnd'] for sentence in matches['sentences'] for match_id in sentence])]

主要问题:如何确保服务器在开放端口上启动,然后关闭?,我更希望有一种半自动的方法来找到打开/关闭已占用的端口,以便客户端在上面运行。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-07-26 17:42:58

一般来说,选择另一个没有其他用途的数字就足够了--也许9017?有很多数字可供选择!但是,更仔细的选择是在带try/catch的with循环中创建CoreNLPClient,并增加端口号,直到找到打开的端口。

票数 1
EN

Stack Overflow用户

发布于 2021-07-19 13:16:02

经过两个小时的工作,我现在知道以下几点:

  1. 使用端口9000不是一个选项,因为它是由python使用的。非正式的证据表明,这需要使用jupyter笔记本,而不是常规python .py文件.

关于客户端在使用其他端点时未关闭的

  1. :我应该使用http://localhost:port'而不是http://localhost:port'

希望这能帮助其他人解决这个问题。我想这是我的非计算机科学背景。

(编辑以解析排版)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68438711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档