import jieba import os import jieba.analyse with open('src.txt', 'r') as file: data = file.read() seg_list = jieba.cut(data, cut_all=True) print("Full Mode:", "| ".join(seg_list)) seg_list = jieba.cut(data, cut_all=False) print("Default Mode:", "| ".join(seg_list)) # 精確模式 seg_list = jieba.cut_for_search(data) # 搜索引擎模式 print("Search Mode:", "| ".join(seg_list)) tags = jieba.analyse.extract_tags(data, topK=20) #TF-IDF方法獲取top20關鍵詞 print("TopK Mode:", "| ".join(tags))