# -*- coding: utf-8 -*-
"""
Created on Tue Aug 28 15:09:32 2018
@author: wenyun.wxw
"""
data=ratecontent_less+ratecontent_jd_less #合并天猫评论和京东评论
num=len(data)
for i in range(num-1):
if data[i]=='此用户没有填写评论!':
del data[i]
def cipin(data,query):
#count=0
comment=[]
for i in range(len(data)):
for j in range(len(query)):
if query[j] in data[i]:
#count=count+1
comment.append(data[i])
break
return comment
#场景
q1=['卧室','床头','起床','房间','闹钟','房间']
q2=['客厅','电视']
q3=['厨房','餐桌','做饭']
#人群
q4=['老人','父母','妈妈','父亲','母亲','姥姥','奶奶','爷爷','姥爷']
q5=['孩子','小孩','宝宝','儿子','女儿','小孩']
q6=['全家','家人']
comment1=cipin(data,q1)
comment2=cipin(data,q2)
comment3=cipin(data,q3)
comment4=cipin(data,q4)
comment5=cipin(data,q5)
comment45=cipin(data,q4+q5)
comment6=cipin(data,q6)
comment456=cipin(data,q4+q5+q6)
comment56=cipin(data,q5+q6)
comment46=cipin(data,q4+q6)
#全家
comment7=[]
for i in range(len(data)):
for qq1 in q4+q5:
for qq2 in q6:
if qq1 in data[i] or qq2 in data[i]:
comment7.append(data[i])
break
break
break
#只有老人
comment9=[]
for l in comment4:
if l not in comment5 and l not in comment7:
comment9.append(l)
#只有孩子
comment10=[]
for l in comment5:
if l not in comment4 and l not in comment7:
comment10.append(l)
#普通购买者
comment8=[]
for l in data:
if l not in comment9+comment10+comment7:
comment8.append(l)
#词频
word,wordcount,wordcount_sort=fenci(comment8)
#词云
wordcloud = WordCloud(background_color="white",font_path="file:///C:/windows/Fonts/MSYH.TTC",
width=1000, height=860, margin=2).fit_words(wordcount)
plt.imshow(wordcloud)
plt.axis("off")