NLP初步——SnowNLP

2022年5月21日16:36:14 发表评论 1,381 views

pip install snownlp

个人感觉还是比较low的,可以仅作了解

(1)支持中文,受Textblob,没有用NLTK 特征、中文分词、词性标注、情感分析(买卖东西评价)、文本分类、拼音转换、繁体转简体、文本关键词提取、文本摘要提取

#-*- coding:utf-8 -*-
from snownlp import  SnowNLP
textzh = '本人喜欢折腾,倒腾大数据和AI人工智能滴一些技术。'
textzh2 =" 加入来自世界各地的成千上万的学习者,他们通过我们的在线课程提高了英语听力技能。加入来自世界各地的成千上万的学习者,他们通过我们的在线课程提高了英语听力技能。"
snownlp_bus1 = SnowNLP(textzh)
snownlp_bus2 = SnowNLP(textzh2)
print('1sentence',snownlp_bus1.sentences)
print('2sentence',snownlp_bus2.sentences)

# 分词:
word_list = []
for sentence in snownlp_bus1.sentences:
    word_list.append(SnowNLP(sentence).words)
print(word_list)
# 还行 折腾没识别出来  [['本人', '喜欢', '折', '腾'], ['倒腾', '大', '数据', '和', 'AI', '人工', '智能', '滴', '一些', '技术']]

# 词性标注:
tag_list = []
for sentence in snownlp_bus1.sentences:
    tag_list.append(list(SnowNLP(sentence).tags))
for sentence in snownlp_bus2.sentences:
    tag_list.append(list(SnowNLP(sentence).tags))
print(tag_list)

# 转换为拼音
print('pinyin',snownlp_bus2.pinyin)
# 简繁转换  略

# keywords Summary abstract
text = "SnowNLP是一个python写的类库,可以方便的处理中文文本内容,是受到了TextBlob的启发而写的,由于现在大部分的自然语言处理库基本都是针对英文的,于是写了一个方便处理中文的类库,并且和TextBlob不同的是,这里没有用NLTK,所有的算法都是自己实现的,并且自带了一些训练好的字典。注意本程序都是处理的unicode编码,所以使用时请自行decode成unicode。"
snow_pgh = SnowNLP(text)
print('key words',snow_pgh.keywords()) # key words ['库', '都', '写', 'unicode', '中文']
print('summary',snow_pgh.summary()) #  比较low的



 

 

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: