当前位置:   article > 正文

python snownlp情感分析和词云分析_python情感分析snownlp方法

python情感分析snownlp方法

1 snownlp

安装

pip install snownlp -i https://pypi.douban.com/simple/

  • 1
  • 2
from snownlp import SnowNLP
s = SnowNLP("今天我很快乐。你怎么样呀?");
1) s.words        分词
2) s.sentences    句子/分句
3) s.sentiments   情感偏向,0-1之间的浮点数,越靠近1越积极(正面)
4) s.pinyin       转为拼音
5) s.han          转为简体
6) s.keywords(n) 提取关键字,n默认为5
7) s.summary(n)  提取摘要,n默认为5

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

示例
分词库仍以jieba的中文分词效果最佳

from snownlp import SnowNLP
s = SnowNLP(u"今天我很快乐。你怎么样呀?");
print("[words]",s.words); # 分词
  • 1
  • 2
  • 3

2 jieba 分词

pip install jieba -i https://pypi.douban.com/simple/
  • 1
import jieba

text = "征战四海只为今日一胜,我不会再败了。"
# jieba.cut直接得到generator形式的分词结果
seg = jieba.cut(text)  
print(' '.join(seg)) 

# 也可以使用jieba.lcut得到list的分词结果
seg = jieba.lcut(text)
print(seg)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

jieba分词有三种不同的分词模式:精确模式、全模式和搜索引擎模式:

jieba.cut(sentence,cut_a
    本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/721346
    推荐阅读
    相关标签
      

    闽ICP备14008679号