我正在尝试使用CoreNLP服务器注释多个句子。但是,如果我尝试使用太多句子,我会得到:
Exception in thread "Thread-48" edu.stanford.nlp.io.RuntimeIOException: Could not connect to server: 192.168.108.60:9000
at edu.stanford.nlp.pipeline.StanfordCoreNLPClient$2.run(StanfordCoreNLPClient.java:393)
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://192.168.108.60:9000?properties=%7B+%22inputFormat%22%3A+%22serialized%22%2C+%22outputSerializer%22%3A+%22edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer%22%2C+%22inputSerializer%22%3A+%22edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer%22%2C+%22annotators%22%3A+%22tokenize%2C+ssplit%2C+pos%2C+lemma%2C+ner%2C+parse%2C+dcoref%22%2C+%22outputFormat%22%3A+%22serialized%22+%7D
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at edu.stanford.nlp.pipeline.StanfordCoreNLPClient$2.run(StanfordCoreNLPClient.java:381)
如果我只运行10或20个句子,一切正常,但随着它们的数量变大,服务器似乎崩溃了,我达到了超时限制或者其他东西 - 至少这是我对此的唯一解释
StanfordCoreNLPClient coreNlp = new StanfordCoreNLPClient(props, "192.168.108.60", 9000);
// ..
for(int windowSize : windowSizeList) {
Map<String, List<TaggedSentence>> aspectMap = new HashMap<>();
for (int i = 0; i < sentenceList.size(); i++) {
Annotation document = sentenceList.get(i);
try {
coreNlp.annotate(document);
} catch(Exception e) {
LOGGER.error("Error", e);
}
// ...
}
}
如何解决此问题?
编辑:好的,我发现有一个超时选项:
props.setProperty("timeout", "50000");
但这没有用。无论如何它都失败了 - 它只需要更长时间。
答案 0 :(得分:0)
我有类似的问题。在我的情况下,我想使用coreference解决方案,我通过使用以下注释器解决:tokenize,ssplit,pos,lemma,ner,depparse,提,coref
java -Xmx5g -cp stanford-corenlp-3.6.0.jar:stanford-corenlp-models-3.6.0.jar:* edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma, ner,depparse,提及,coref -file example_file.txt
根据这个页面,原因是它的效率更高(与速度有关):http://stanfordnlp.github.io/CoreNLP/coref.html#overview