我正在尝试对一个很长的文本运行pycorenlp。为了避免收到CoreNLP request timed out. Your document may be too long错误消息,我通过指定超时增加了Stanford CoreNLP。
下面是我使用的代码(这是pycorenlp的example.py的简化版本):
from pycorenlp import StanfordCoreNLP
if __name__ == '__main__':
nlp = StanfordCoreNLP('http://localhost:9000')
text = (
'Pusheen and Smitha walked along the beach. Pusheen wanted to surf,'
'but fell off the surfboard.')
output = nlp.annotate(text, properties={
'timeout': '10001' # Setting the timeout to 10000 or below "fixes" the issue.
'annotators': 'tokenize,ssplit,pos,depparse,parse',
'outputFormat': 'json'
})
print(output)它输出server: unknown error。服务器日志包含:
java.net.UnknownHostException: server: server: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at edu.stanford.nlp.pipeline.StanfordCoreNLPServer$CoreNLPHandler.handle(StanfordCoreNLPServer.java:393)
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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: server: unknown error
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 10 moreStanford Core NLP服务器使用以下工具启动:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer 9000我不想把文本分割成更小的文本。
有没有办法将超时设置为大于10000?(即高于10秒)
它在MacOSX10.10 (java版本“1.8.0_60”)上运行良好:这个问题出现在Ubuntu14.04 (java版本"1.8.0_77")中。两者都有Python2.7pycorenlp0.2.0和斯坦福CoreNLP版本3.6.0。
发布于 2016-04-21 17:03:51
需要明确的是,如果你在Macbook上运行服务器,你不会看到这个问题?
那么这似乎是运行服务器的机器的问题。服务器代码正在尝试调用:
InetAddress.getLocalHost().getHostName()然后得到一个异常。
这是我在某人遇到类似问题时发现的一个帖子:
InetAddress.getLocalHost() throws UnknownHostException
在您试图运行服务器的机器上的/etc/hosts文件中有什么?
https://stackoverflow.com/questions/36731867
复制相似问题