安装
sudo pip install thulac
通过 import thulac 来引用
使用
# 代码示例1
import thulac
thu1 = thulac.thulac(
# user_dict= #设置用户词典,用户词典中的词会被打上uw标签。词典中每一个词一行,UTF8编码
T2S=True, #默认False, 是否将句子从繁体转化为简体
seg_only=True, #默认False, 时候只进行分词,不进行词性标注
filt=False, #默认False, 是否使用过滤器去除一些没有意义的词语,例如“可以”。
# model_path='' #设置模型文件所在文件夹,默认为models
deli=' ' # 默认为‘_’, 设置词与词性之间的分隔符
)
text = thu1.cut("我爱北京天安门", text=True) #进行一句话分词
# file_cut = thu1.cut_f(input_file='', output_file='') #对文件分词
print(text)