问题
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)
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);
}
// ...
}
}
How can I fix this issue?
Edit: 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.
回答1:
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
- Or a command line like the one below:
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
The reason is that it's more efficient (in relation to speed), according to this page: http://stanfordnlp.github.io/CoreNLP/coref.html#overview
来源:https://stackoverflow.com/questions/39809061/edu-stanford-nlp-io-runtimeioexception-could-not-connect-to-server