问题描述
我正在尝试使用CoreNLP服务器注释多个句子.但是,如果我尝试使用太多句子来实现这一点,我将得到:
I'm trying to annotate multiple sentences using the CoreNLP server. However, if I try to that with too many sentences I'm getting:
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个句子,一切都可以正常工作,但是随着它们的数量越来越大,服务器似乎崩溃了,我正在达到超时限制或其他限制-至少这是我对此的唯一解释
Everything is working if I run this for just 10 or 20 sentences but as the number of them gets larger the server seems to crumble and I'm reaching a timeout limit or something - at least that's the only explanation I have for this.
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);
}
// ...
}
}
如何解决此问题?
好的,我发现有一个超时选项:
Okay, I found that there is a timeout option:
props.setProperty("timeout", "50000");
但这无济于事.无论如何,它都在失败-它只需要更长的时间.
but that does not help. It's failing anyways - it just takes longer.
推荐答案
我遇到了类似的问题.就我而言,我想使用共参考分辨率,并通过使用以下注释器解决了该问题:标记化,分割,pos,引理,内在,去稀疏,提及,coref
I had a similar problem. In my case, I wanted to use the coreference resolution and I solved by using the following annotators: tokenize,ssplit,pos,lemma,ner,depparse,mention,coref
- 或以下命令行:
java -Xmx5g -cp stanford-corenlp-3.6.0.jar:stanford-corenlp-models-3.6.0.jar:* edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize tokenize,ssplit,pos,lemma, ner,depparse,mention,coref -file example_file.txt
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,mention,coref -file example_file.txt
原因是,根据此页面,它的效率更高(相对于速度): http://stanfordnlp.github.io/CoreNLP/coref.html#overview
The reason is that it's more efficient (in relation to speed), according to this page: http://stanfordnlp.github.io/CoreNLP/coref.html#overview
这篇关于edu.stanford.nlp.io.RuntimeIOException:无法连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!