"""
基于 https://github.com/isnowfy/snownlp
$ pip install snownlp
"""
from snownlp import SnowNLP
# 分词
def snownlp_cut(text):
return SnowNLP(text).words
# 词性标准
def snownlp_tags(text):
# 返回积极情绪订单概率,高于 0.5 积极,低于消极
return SnowNLP(text).tags
# 情感分析
def snownlp_sentiments(text):
return SnowNLP(text).sentiments
# 转成拼音
def snownlp_pinyin(text):
return SnowNLP(text).pinyin
# 断句
def snownlp_sentences(text):
return SnowNLP(text).sentences
# 提取文本关键词
def snownlp_keywords(text):
return SnowNLP(text).keywords(5)
# 提取文本摘要
def snownlp_summary(text):
return SnowNLP(text).summary(5)
if __name__ == '__main__':
print(snownlp_cut('我是中国人'))
print(snownlp_cut('我是中国