首页 文章

防止Stanford Core NLP Server输出收到的文本

提问于
浏览
1

我正在运行Stanford CoreNLP服务器:

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

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


重要的是,这是我用来将数据传递给Stanford Core NLP Server的代码:

'''
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)

2 回答

  • 1

    's currently not a way to do this, but you'是's asked. So, it'现在在Github代码中的第二个人,并将进入下一个版本 . 对于将来,您应该能够设置 -quiet 标志,并且服务器不会写入标准输出 .

  • 5

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

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

    在我们等待 3.6.1 之前,这会带来相当大的性能提升 .

相关问题