如何使用tokenize注释器,使用pycorenlp(Python wrapper for Stanford CoreNLP),而不使用ssplit,如何执行文本的单词标记化?

2024-06-26 02:47:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行pycorenlp,它是Stanford CoreNLP的Python包装器,使用^{}注释器执行文本的单词标记化。在

我首先推出了斯坦福大学的CoreNLP:

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

然后运行:

^{pr2}$

令人惊讶的是,这没有输出:

text_input: this is a test.
text_output: {}

为什么?在


如果我添加^{},那么text_output不再是空的:

text_input = 'this is a test.'
print('text_input: {0}'.format(text_input))
text_output = nlp.annotate(text_input, properties={
                    'annotators': 'tokenize,ssplit',
                    'outputFormat': 'json'
                })
print('text_output: {0}'.format(text_output))

输出:

text_input: this is a test.
text_output: {u'sentences': [{u'parse': u'SENTENCE_SKIPPED_OR_UNPARSABLE', u'index': 0, u'tokens': [{u'index': 1, u'word': u'this', u'after': u' ', u'characterOffsetEnd': 4, u'characterOffsetBegin': 0, u'originalText': u'this', u'before': u''}, {u'index': 2, u'word': u'is', u'after': u' ', u'characterOffsetEnd': 7, u'characterOffsetBegin': 5, u'originalText': u'is', u'before': u' '}, {u'index': 3, u'word': u'a', u'after': u' ', u'characterOffsetEnd': 9, u'characterOffsetBegin': 8, u'originalText': u'a', u'before': u' '}, {u'index': 4, u'word': u'test', u'after': u'', u'characterOffsetEnd': 14, u'characterOffsetBegin': 10, u'originalText': u'test', u'before': u' '}, {u'index': 5, u'word': u'.', u'after': u'', u'characterOffsetEnd': 15, u'characterOffsetBegin': 14, u'originalText': u'.', u'before': u''}]}]}

我不能在不使用^{}注释器的情况下使用^{}注释器吗?在

overview of the annotator dependencies似乎在说我应该能够单独使用^{}注释器:

enter image description here


Tags: texttestinputoutputindexnlpisthis
1条回答
网友
1楼 · 发布于 2024-06-26 02:47:41

你说得对,如果唯一提供的注释器是“tokenize”,那么API似乎没有响应。它应该默认为PTBTokenizer,如文档中所述。另一个相关的问题是:Stanford CoreNLP gives NullPointerException。但是,如果只想标记化而不执行其他操作,则可以执行以下操作:

nwani@ip-172-31-43-96:~/stanford-corenlp-full-2015-12-09$ ~/jre1.8.0_101/bin/java -mx4g -cp "*" edu.stanford.nlp.process.PTBTokenizer <<< "this is a test"
this
is
a
test
PTBTokenizer tokenized 4 tokens at 19.11 tokens per second.

相关问题 更多 >