我想使用节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文件中运行以下代码:
# 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])]
主要问题:如何确保服务器在开放端口上启动,然后关闭?,我更希望有一种半自动的方法来找到打开/关闭已占用的端口,以便客户端在上面运行。
发布于 2021-07-26 17:42:58
一般来说,选择另一个没有其他用途的数字就足够了--也许9017?有很多数字可供选择!但是,更仔细的选择是在带try/catch的with循环中创建CoreNLPClient,并增加端口号,直到找到打开的端口。
发布于 2021-07-19 13:16:02
经过两个小时的工作,我现在知道以下几点:
。
关于客户端在使用其他端点时未关闭的
http://localhost:port'
而不是http://localhost:port'
希望这能帮助其他人解决这个问题。我想这是我的非计算机科学背景。
(编辑以解析排版)
https://stackoverflow.com/questions/68438711
复制相似问题