-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
34 lines (26 loc) · 748 Bytes
/
helpers.py
File metadata and controls
34 lines (26 loc) · 748 Bytes
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
def extract_sentiment(results):
k = 0
for sentiment in results:
if k == 0 or results[sentiment] > results[k]:
k = sentiment
if k == 'neu':
return 'neutral'
elif k == 'pos':
return 'positive'
elif k == 'neg':
return 'negative'
return 'n/a'
def tokenizer(text):
import nltk
words = nltk.word_tokenize(text)
tokens = []
for word in words:
if len(word) >= 3:
tokens.append(word)
return tokens
def get_prevalent_element(elements):
max_count_element = elements[0]
for element in elements:
if elements.count(element) > elements.count(max_count_element):
max_count_element = element
return max_count_element