forked from irisshakya/final_proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
56 lines (41 loc) · 1.59 KB
/
driver.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from methods import us_comments, us_videos, process_comment_data, agregate_sentiments, merger
import pandas as pd
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from textblob import TextBlob
import csv
def main():
# Initialize the VADER sentiment analyzer
analyzer = SentimentIntensityAnalyzer()
comment_data = us_comments()
polarity_score_list = []
for comment in comment_data:
text = comment[1]
blob = TextBlob(text)
# Perform spellcheck
corrected_text = blob.correct()
# contains pos, neg, and compund scores
all_scores_for_comment = analyzer.polarity_scores(text)
# extract only compound scores from the dict
compound_score = all_scores_for_comment['compound']
polarity_score_list.append([comment[0],comment[1],compound_score])
# Write the list to a CSV file
with open('comment_polarity.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(polarity_score_list)
my_videos = us_videos()
us_video_id_list = list(my_videos['video_id'])
comment_list, comment_map = process_comment_data(comment_data)
usable_vid_count = 0
unusable_vid_count = 0
for key in comment_map:
if key in us_video_id_list:
usable_vid_count += 1
else:
unusable_vid_count += 1
# print(usable_vid_count)
# print(unusable_vid_count)
agregate_sentiments(comment_map, polarity_score_list)
# merges the USvideo.csv and agregate_sentiment's csv
merger()
if __name__ == '__main__':
main()