【getTableData.py】情感分析接管数据的函数定义

This commit is contained in:
juanboy
2024-07-02 20:49:26 +08:00
parent d2b2a26ac5
commit 46bbc00317
2 changed files with 77 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
from utils.getPublicData import getAllArticleData
from snownlp import SnowNLP
def getTableDataList(flag):
if flag:
tableList = []
articeList = getAllArticleData()
for article in articeList:
item = list(article)
value = ''
if SnowNLP(item[5]).sentiments > 0.5:
value = '正面'
elif SnowNLP(item[5]).sentiments < 0.5:
value = '负面'
else:
value = '中性'
item.append(value)
tableList.append(item)
return tableList
else:
return getAllArticleData()