我想使用 stanza CoreNLPClient 来提取名词短语,类似于这个方法。
但是,我似乎找不到一个好的端口来启动服务器。默认为 9000,但经常被占用,如错误消息所示:
PermanentlyFailedException:错误:无法在端口 9000 上启动 CoreNLP 服务器(可能那里已经运行了某些东西)
编辑:python.exe 正在使用端口 9000,这就是为什么我不能关闭进程以为 CoreNLPClient 腾出空间。
然后,当我选择其他端口,例如 7999、8000 或 8080 时,服务器一直在无限监听,不执行连续的代码行,只显示以下内容:
2021-07-19 12:05:55 信息:使用命令启动服务器:java -Xmx8G -cp C:\Users\timjo\stanza_corenlp* edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 7998 -timeout 60000 -threads 5 - maxCharLength 100000 -quiet True -serverProperties corenlp_server-2e15724b8064491b.props -preload -outputFormat 序列化
我安装了最新版本的节,并且正在 VS Code 中的 .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])]
主要问题:如何确保服务器在打开的端口上启动,然后关闭? 我希望有一种半自动的方式来查找打开/关闭占用的端口以供客户端运行。