11# -*- coding: utf-8 -*-
22"""
3- Created on Tue Mar 13 21:34:29 2018
4-
5- @author: Administrator
3+ 朋友圈朋友签名的词云生成以及
4+ 签名情感分析
65"""
76import re ,jieba ,itchat
87import jieba .analyse
1615def analyseSignature (friends ):
1716 signatures = ''
1817 emotions = []
19- pattern = re .compile ("1f\d.+" )
2018 for friend in friends :
2119 signature = friend ['Signature' ]
2220 if (signature != None ):
@@ -29,7 +27,7 @@ def analyseSignature(friends):
2927 with open ('signatures.txt' ,'wt' ,encoding = 'utf-8' ) as file :
3028 file .write (signatures )
3129
32- # Sinature WordCloud
30+ # 朋友圈朋友签名的词云相关属性设置
3331 back_coloring = np .array (Image .open ('alice_color.png' ))
3432 wordcloud = WordCloud (
3533 font_path = 'simfang.ttf' ,
@@ -42,23 +40,24 @@ def analyseSignature(friends):
4240 height = 1000 ,
4341 margin = 15
4442 )
45-
43+
44+ #生成朋友圈朋友签名的词云
4645 wordcloud .generate (signatures )
4746 plt .imshow (wordcloud )
4847 plt .axis ("off" )
4948 plt .show ()
50- wordcloud .to_file ('signatures.jpg' )
49+ wordcloud .to_file ('signatures.jpg' )#保存到本地文件
5150
5251 # Signature Emotional Judgment
53- count_good = len (list (filter (lambda x :x > 0.66 ,emotions )))
54- count_normal = len (list (filter (lambda x :x >= 0.33 and x <= 0.66 ,emotions )))
55- count_bad = len (list (filter (lambda x :x < 0.33 ,emotions )))
52+ count_good = len (list (filter (lambda x :x > 0.66 ,emotions )))#正面积极
53+ count_normal = len (list (filter (lambda x :x >= 0.33 and x <= 0.66 ,emotions )))#中性
54+ count_bad = len (list (filter (lambda x :x < 0.33 ,emotions )))#负面消极
5655 labels = [u'负面消极' ,u'中性' ,u'正面积极' ]
5756 values = (count_bad ,count_normal ,count_good )
5857 plt .rcParams ['font.sans-serif' ] = ['simHei' ]
5958 plt .rcParams ['axes.unicode_minus' ] = False
60- plt .xlabel (u'情感判断' )
61- plt .ylabel (u'频数' )
59+ plt .xlabel (u'情感判断' )#x轴
60+ plt .ylabel (u'频数' )#y轴
6261 plt .xticks (range (3 ),labels )
6362 plt .legend (loc = 'upper right' ,)
6463 plt .bar (range (3 ), values , color = 'rgb' )
0 commit comments