如何从CoreNLP超时中恢复并继续处理请求?

时间:2018-05-18 17:18:57

标签: python stanford-nlp

我使用此命令在Ubuntu 16.04上启动了我的Standford NLP服务器(CoreNLP v 3.91 stanford-corenlp-full-2018-02-27.zip):

  

java -mx4g -cp" *" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

过了一段时间,如果我对它扔了太大的句子,它就会爆炸。

java.util.concurrent.TimeoutException
        at java.util.concurrent.FutureTask.get(FutureTask.java:205)
        at edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.handle (StanfordCoreNLPServer.java:866)

[pool-1-thread-6] INFO CoreNLP - [/127.0.0.1:34048] API call w/annotators tokenize,ssplit,pos,parse,depparse
But if you ask any feminist directly (and I have, one of my best friends is a woman's studies major and we have had MANY heated passionate arguments; i've spoken to her friends too), they will fully say that modern feminism is about having the choice, and while they completely disagree with women who take this choice, it is still their choice to make.
java.util.concurrent.TimeoutException
        at java.util.concurrent.FutureTask.get(FutureTask.java:205)
        at edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.handle(StanfordCoreNLPServer.java:866)
        at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
        at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
        at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
        at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
        at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
        at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
[Thread-0] INFO CoreNLP - CoreNLP Server is shutting down.

不幸的是,这会杀死我的服务器。我有我的python脚本捕获由服务器超时引起的异常,但我怎么能传递它,并继续使用服务器。我目前正在使用eval()使用上述命令重新启动服务器。

有没有更好的方法可以跳过这些崩溃?

编辑:这是一个例子,当CoreNLP v 3.91在我抛出过大的句子时失败: Timeout Exception 注意一个很长的句子将如何导致超时异常,并使服务器崩溃。

1 个答案:

答案 0 :(得分:0)

您应该尝试获取最新代码。当我向服务器提交一个很长的句子时,我得到超时异常,但它不会使服务器崩溃。

最新代码可以在GitHub上找到:https://github.com/stanfordnlp/CoreNLP上一个稳定版本(3.9.1):https://stanfordnlp.github.io/CoreNLP/

你也可以尝试设置“parse.maxlen = 100”(或更小的东西)以防止注释真正长的句子。其他注释器可以选择不处理很长的句子,这通常是罪魁祸首。