系统相关
首页 > 系统相关> > java – 如何在Windows上设置Stanford CoreNLP服务器以返回文本的情绪

java – 如何在Windows上设置Stanford CoreNLP服务器以返回文本的情绪

作者:互联网

我试图在Windows上使用Stanford CoreNLP设置本地服务器,以计算超过1M文章和视频文本的情绪分数.我不懂Java,所以我需要一些帮助.

我成功安装了Stanford CoreNLP 3.6.0,我运行的服务器运行:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer

从我的其他计算机运行此http帖子工作,我收到预期的响应(xxx.xxx.xxx.xxx是服务器的IP地址):

wget --post-data 'the quick brown fox jumped over the lazy dog' 'xxx.xxx.xxx.xxx:9000/?properties={"tokenize.whitespace": "true", "annotators": "tokenize,ssplit,pos,lemma,parse", "outputFormat": "json"}' -O -

但是,回复并不包含情绪.显而易见的解决方案是添加注释器:

wget --post-data 'the quick brown fox jumped over the lazy dog' 'xxx.xxx.xxx.xxx:9000/?properties={"tokenize.whitespace": "true", "annotators": "tokenize,ssplit,pos,lemma,parse,sentiment", "outputFormat": "json"}' -O -

但是,在服务器端,我收到此错误:

java.lang.IllegalArgumentException: Unknown annotator: sentiment
at edu.stanford.nlp.pipeline.StanfordCoreNLP.ensurePrerequisiteAnnotators(StanfordCoreNLP.java:281)
at edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.getProperties(StanfordCoreNLPServer.java:476)
at edu.stanford.nlp.pipeline.StanfordCoreNLP$CoreNLPHandler.handle(StanfordCoreNLPServer.java:350)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.thread.run(Unknown Source)

下一个明显的解决方案是添加一个参数来启动服务器,该服务运行:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -annotators "tokenize,ssplit,pos,lemma,parse,sentiment"

从之前运行相同的http帖子分别给出相同的确切结果和错误.

我做错了什么,或者是否需要对核心代码进行一些修改?我不懂Java,所以我无法进行这些更改.

作为旁注,这个类似的命令启动一个控制台,似乎正确加载情绪:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators "tokenize,ssplit,pos,lemma,parse,sentiment"

[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator tokenize
[main] INFO edu.stanford.nlp.pipeline.TokenizerAnnotator - TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator ssplit
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator pos
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [0.5 sec].
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator lemma
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator parse
[main] INFO edu.stanford.nlp.parser.common.ParserGrammar - Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ... done [0.4 sec].
[main] INFO edu.stanford.nlp.pipeline.StanfordCoreNLP - Adding annotator sentiment

Entering interactive shell. Type q RETURN or EOF to quit.
NLP> _

解决方法:

尝试使用GitHub version代码运行.你的第一个解决方案是正确的 – 它无法找到情绪注释器的事实是代码中的错误:

wget --post-data 'the quick brown fox jumped over the lazy dog' 'xxx.xxx.xxx.xxx:9000/?properties={"annotators": "tokenize,ssplit,pos,lemma,parse,sentiment", "outputFormat": "json"}' -O -

(旁注:tokenize.whitespace属性在文档中,表明您可以传递任意属性,但我建议不要在生产中使用它).

标签:java,stanford-nlp,server,sentiment-analysis
来源: https://codeday.me/bug/20190519/1135723.html