这里是王树义老师博客里看到的方法,感谢
- 对文档(多个句子)进行中文分词:
a_doc :
['孔丘开办私塾,学费要十条腊肉',
'听孔老二讲学的,都是贵族、官宦人家的子弟。',
'清代乾嘉学派考证儒学多为造假']
import jieba
def cut_words(a_list, a_function):
return [a_function(x) for x in a_list]
a_list_seg = cut_words(a_doc, lambda x: " ".join( jieba.cut(x) ))
['孔丘 开办 私塾 , 学费 要 十条 腊肉',
'听 孔老二 讲学 的 , 都 是 贵族 、 官宦 人家 的 子弟 。',
'清代 乾嘉学派 考证 儒学 多为 造假']
- 对单个句子分词:
a_sent :
'孔老二罪恶的一生'
import jieba
def cut_chinese_words(x):
return " ".join( jieba.cut(x) )
a_sent_seg
'孔老二 罪恶 的 一生'