Showing
2 changed files
with
77 additions
and
0 deletions
| @@ -152,3 +152,59 @@ def getCommentCharDataTwo():# 统计评论数据中不同性别的数量 | @@ -152,3 +152,59 @@ def getCommentCharDataTwo():# 统计评论数据中不同性别的数量 | ||
| 152 | }) | 152 | }) |
| 153 | return resultData | 153 | return resultData |
| 154 | 154 | ||
| 155 | +def getYuQingCharDataOne():# 统计热词中正面、中性、负面的数量 | ||
| 156 | + hotWordList = getAllHotWords() | ||
| 157 | + xData = ['正面','中性','负面'] | ||
| 158 | + yData = [0,0,0] | ||
| 159 | + for word in hotWordList: | ||
| 160 | + emotionValue = SnowNLP(word[0]).sentiments | ||
| 161 | + if emotionValue > 0.5: | ||
| 162 | + yData[0] += 1 | ||
| 163 | + elif emotionValue == 0.5: | ||
| 164 | + yData[1] += 1 | ||
| 165 | + elif emotionValue < 0.5: | ||
| 166 | + yData[2] += 1 | ||
| 167 | + finalData = [{ | ||
| 168 | + 'name':x, | ||
| 169 | + 'value':yData[index] | ||
| 170 | + } for index,x in enumerate(xData)] | ||
| 171 | + return xData,yData,finalData | ||
| 172 | + | ||
| 173 | +def getYuQingCharDataTwo():# 统计评论列表和文章列表中的情感值 | ||
| 174 | + xData = ['正面', '中性', '负面'] | ||
| 175 | + finalData1 = [{ | ||
| 176 | + 'name':x, | ||
| 177 | + 'value':0 | ||
| 178 | + } for x in xData] | ||
| 179 | + finalData2 = [{ | ||
| 180 | + 'name': x, | ||
| 181 | + 'value': 0 | ||
| 182 | + } for x in xData] | ||
| 183 | + | ||
| 184 | + for comment in commentList: | ||
| 185 | + emotionValue = SnowNLP(comment[4]).sentiments | ||
| 186 | + if emotionValue > 0.5: | ||
| 187 | + finalData1[0]['value'] += 1 | ||
| 188 | + elif emotionValue == 0.5: | ||
| 189 | + finalData1[1]['value'] += 1 | ||
| 190 | + elif emotionValue < 0.5: | ||
| 191 | + finalData1[2]['value'] += 1 | ||
| 192 | + for artile in articleList: | ||
| 193 | + emotionValue = SnowNLP(artile[5]).sentiments | ||
| 194 | + if emotionValue > 0.5: | ||
| 195 | + finalData2[0]['value'] += 1 | ||
| 196 | + elif emotionValue == 0.5: | ||
| 197 | + finalData2[1]['value'] += 1 | ||
| 198 | + elif emotionValue < 0.5: | ||
| 199 | + finalData2[2]['value'] += 1 | ||
| 200 | + return finalData1,finalData2 | ||
| 201 | + | ||
| 202 | +def getYuQingCharDataThree():# 提取前10个热词及其对应的出现频率 | ||
| 203 | + hotWordList = getAllHotWords() | ||
| 204 | + xData = [] | ||
| 205 | + yData = [] | ||
| 206 | + for i in hotWordList[:10]: | ||
| 207 | + xData.append(i[0]) | ||
| 208 | + yData.append(int(i[1])) | ||
| 209 | + return xData,yData | ||
| 210 | + |
utils/getTableData.py
0 → 100644
| 1 | +from utils.getPublicData import getAllArticleData | ||
| 2 | +from snownlp import SnowNLP | ||
| 3 | + | ||
| 4 | +def getTableDataList(flag): | ||
| 5 | + if flag: | ||
| 6 | + tableList = [] | ||
| 7 | + articeList = getAllArticleData() | ||
| 8 | + for article in articeList: | ||
| 9 | + item = list(article) | ||
| 10 | + value = '' | ||
| 11 | + if SnowNLP(item[5]).sentiments > 0.5: | ||
| 12 | + value = '正面' | ||
| 13 | + elif SnowNLP(item[5]).sentiments < 0.5: | ||
| 14 | + value = '负面' | ||
| 15 | + else: | ||
| 16 | + value = '中性' | ||
| 17 | + item.append(value) | ||
| 18 | + tableList.append(item) | ||
| 19 | + return tableList | ||
| 20 | + else: | ||
| 21 | + return getAllArticleData() |
-
Please register or login to post a comment