Я пытаюсь запустить pycorenlp, который является оболочкой Python для Stanford CoreNLP, чтобы выполнить токенизацию текста, используя аннотатор tokenize
.Как я могу выполнять токенизацию текста, используя аннотатор tokenize, с pycorenlp (оболочка Python для Stanford CoreNLP), без ssplit?
Я первый запуск Stanford CoreNLP:
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 50000
затем запустить:
from pycorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('http://localhost:9000')
text_input = 'this is a test.'
print('text_input: {0}'.format(text_input))
text_output = nlp.annotate(text_input, properties={
'annotators': 'tokenize',
'outputFormat': 'json'
})
print('text_output: {0}'.format(text_output))
Удивительно, но это не дает никакого выхода:
text_input: this is a test.
text_output: {}
Почему?
Если я добавляю ssplit
, то 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''}]}]}
Не могу ли я использовать tokenize
аннотатор без использования ssplit
аннотатор?
overview of the annotator dependencies, кажется, сказать, что я должен быть в состоянии использовать tokenize
аннотатор в одиночку:
Я crossposted вопрос о Quora: https://www.quora.com/unanswered/How-can-I-perform- Word-tokenization-of-a-text-using-the -ken-annotator-with-pycorenlp-Python-wrapper-for-Stanford-CoreNLP-without-ssplit –