java NLTK Stanford Segmentor,如何设置类路径
我试图使用NLTK令牌化包中的Stanford Segementer位。然而,我在尝试使用基本测试集时遇到了一些问题。运行以下命令:
# -*- coding: utf-8 -*-
from nltk.tokenize.stanford_segmenter import StanfordSegmenter
seg = StanfordSegmenter()
seg.default_config('zh')
sent = u'这是斯坦福中文分词器测试'
print(seg.segment(sent))
我甚至补充说
import os
javapath = "C:/Users/User/Folder/stanford-segmenter-2017-06-09/*"
os.environ['CLASSPATH'] = javapath
。。。在我的代码前面,但这似乎没有帮助
如何使分节器正常运行
# 1 楼答案
注意:此解决方案仅适用于以下情况:
首先,您必须首先正确安装Java 8,如果Stanford CoreNLP在命令行上工作,则NLTK v3中的Stanford CoreNLP API。2.5如下
注意:在NLTK中使用新的CoreNLP API之前,您必须在终端中启动CoreNLP服务器
英式
在终端:
在Python中:
中国人
在终端:
用Python
德文
在终端:
在Python中:
西班牙文
在终端:
在Python中:
法语的
在终端:
在Python中:
阿拉伯文
在终端:
在Python中: