当标记包含中文和英文的文本时,结果会将英文单词分成字母,这不是我想要的。请考虑以下代码:
from nltk.tokenize.stanford_segmenter import StanfordSegmenter
segmenter = StanfordSegmenter()
segmenter.default_config('zh')
print(segmenter.segment('哈佛大学的Melissa Dell'))
输出为哈佛大学 的 M e l i s s a D e l l
。如何修改此行为?
答案 0 :(得分:2)
您可以尝试解霸。
import jieba
jieba.lcut('哈佛大学的Melissa Dell')
['哈佛大学', '的', 'Melissa', ' ', 'Dell']
答案 1 :(得分:0)
我不能代表nltk
,但如果在这句话中运行,Stanford CoreNLP将不会出现此行为。
如果您在示例中发出此命令,则会获得正确的标记:
java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -props StanfordCoreNLP-chinese.properties -file example.txt -outputFormat text
如果您想通过Python访问Stanford CoreNLP,可能需要考虑使用stanza
。