进行中文自然语言处理首先需要对文本进行分词。
1.添加用户自定义词典(对专有名词等)
import jieba
jieba.load_userdict('drop.txt')
seq_list = jieba.lcut('小明毕业于中国科学院大学,然后在哈佛大学深造,研究自然语言处理')
print(seq_list)
运行结果:
2.关键词提取
基于TF-IDF的关键词的提取
lines = open('words/c1.txt','rb').read()
# lines = lines.decode('utf-8')
print(analyse.extract_tags(lines,topK=10,withWeight=True))
运行结果:
基于TextRank算法的关键词提取
jieba.analyse.set_stop_words('drop.txt')
print(analyse.extract_tags(lines,topK=10,withWeight=True))
print(analyse.textrank(lines,topK=10,withWeight=True))
词性标记
运行结果: