-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataVisualizationPrep.py
39 lines (32 loc) · 1.13 KB
/
dataVisualizationPrep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from textblob import TextBlob
from jsonUtils import dictToJSOND3
def prepareMostRepeatedWords(reviews):
posList = ["NN", "JJ", "VBG", "VBP", "NNS"]
wordList = []
countWords = {}
mostRepeatedWords = {
"name": "Most Repeated Words",
"value": 9999,
"children": []
}
for review in reviews:
blob = TextBlob(review)
for word, pos in blob.tags:
if pos in posList:
word = word.lower()
wordList.append(word)
for word in wordList:
if word not in countWords.keys():
countWords[word] = 1
else:
countWords[word] += 1
countWords = sorted(countWords.items(), key=lambda x: x[1], reverse=True)
for key, value in countWords[:30]:
wordBlob = TextBlob(key)
# polarity (from -1 to 1 negative to positive)
# subjectivity (from 0 to 1, 0 is objective and 1 is subjective)
score = wordBlob.sentiment.polarity
mostRepeatedWords['children'].append(
{"name": key, "value": value, "sentiment": score})
dictToJSOND3(mostRepeatedWords)
return mostRepeatedWords