問答申論
jieba 中文斷詞模組,用於自然語言處理,將一段文字拆成有意義的詞組;如斷詞「獨立音樂需要大家一起來推廣」,會拆分成:獨立 / 音樂 / 需要 / 大家 / 一起 / 來 / 推廣 /。
安裝
pip install jieba
import jieba
sentence = "開發可以重複使用的程式碼,讓世界各地的開發者可以使用"
print ("輸入:", sentence)
words = jieba.cut(sentence, cut_all=False)
# cut方法接受三個輸入引數: 需要分詞的字串;cut_all引數用來控制是否採用全模式;HMM引數用來控制是否使用
print ("輸出:")
for word in words:
print(word)
得到以下結果: