【问题标题】:Preventing Stanford Core NLP Server from outputting the text it receives阻止 Stanford Core NLP Server 输出它接收到的文本
【发布时间】:2016-04-21 20:59:40
【问题描述】:

我正在运行Stanford CoreNLP 服务器:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9001 -timeout 50000

当它接收到一些文本时,它会在运行它的 shell 中输出它。如何防止这种情况发生?


重要的是,这是我用来将数据传递到斯坦福核心 NLP 服务器的代码:

'''
From https://github.com/smilli/py-corenlp/blob/master/example.py
'''
from pycorenlp import StanfordCoreNLP
import pprint

if __name__ == '__main__':
    nlp = StanfordCoreNLP('http://localhost:9000')
    fp = open("long_text.txt")
    text = fp.read()
    output = nlp.annotate(text, properties={
        'annotators': 'tokenize,ssplit,pos,depparse,parse',
        'outputFormat': 'json'
    })
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(output)

【问题讨论】:

    标签: nlp stanford-nlp


    【解决方案1】:

    目前没有办法做到这一点,但你是第二个被问到的人。所以,它现在在 Github 代码中,并将进入下一个版本。以后应该可以设置-quiet标志,服务器不会写入标准输出。

    【讨论】:

    • 截至 2020 年 6 月,是否为 Python 界面添加了关闭详细输出的功能?
    • @jackson95 你指的是哪个Python接口?
    • stanfordnlp(或较新的 spacy)?
    【解决方案2】:

    我询问了same question,可以提供某种解决方法。我目前正在虚拟机中运行服务器。为了暂时防止日志输出,我使用2&>1 >/dev/null 管道参数运行它:

    java -mx6g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -prettyPrint false 2&>1 >/dev/null
    

    在我们等待3.6.1 之前,这会显着提升性能。

    【讨论】:

    • 我在命令行中添加了“-quiet”,它似乎可以工作,虽然处理很多行仍然需要一些时间
    猜你喜欢
    • 1970-01-01
    • 2012-09-03
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-16
    相关资源
    最近更新 更多