基于Python第三方库jieba,对中文文本进行分词。
import jieba
text= "张小明来到了北京大学东门地铁站"
seg_list = jieba.cut(text, cut_all=True)
print("全模式:" + " ".join(seg_list))
seg_list = jieba.cut(text, cut_all=False)
print("精确模式:" + " ".join(seg_list))
seg_list = jieba.cut(text)
print("默认精确模式:" + " ".join(seg_list))
seg_list = jieba.cut_for_search(text)
print("搜索引擎模式:" + " ".join(seg_list))