首页 文章

当pycorenlp中的超时超过10,000时,我在Linux上得到“java.net.UnknownHostException:server:server:unknown error”(在OS X上运行正常) . 为什么?

提问于
浏览
0

我试图在长文本上运行pycorenlp . 为了避免收到 CoreNLP request timed out. Your document may be too long 错误消息,我通过指定超时来增加Stanford CoreNLP .

这是我使用的代码(它's a simplified version of pycorenlp' s 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 more

Stanford Core NLP Server使用以下方式启动:

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

我不想将文本分成较小的文本 .

有没有办法将超时设置为高于10000? (即高于10秒)

它在Mac OS X 10.10(java版“1.8.0_60”)上运行正常:Ubuntu 14.04(java版“1.8.0_77”)出现了这个问题 . 两者都有Python 2.7 pycorenlp 0.2.0和Stanford CoreNLP 3.6.0版 .

1 回答

  • 0

    要清楚,如果您在Macbook上运行服务器,则没有看到此问题?

    然后,这似乎是您运行服务器的计算机的问题 . 服务器代码试图调用:

    InetAddress.getLocalHost().getHostName()
    

    并获得例外 .

    这是我发现有人遇到类似问题的帖子:

    InetAddress.getLocalHost() throws UnknownHostException

    您尝试运行服务器的计算机上的/ etc / hosts文件中有什么?

相关问题