-
Notifications
You must be signed in to change notification settings - Fork 3
/
read_csv.py
74 lines (54 loc) · 2.07 KB
/
read_csv.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
""" CSC111 Winter 2023 Course Project : Compel-O-Meter
Description
===========
Generating the lexicon used for data analysis
Copyright
==========
This file is Copyright (c) 2023 Akshaya Deepak Ramachandran, Kashish Mittal, Maryam Taj and Pratibha Thakur
"""
import csv
def read_csv_positive_file(csv_file1: str) -> dict[str, int]:
"""Takes in a csv file of positive words and returns a dictionary where each word in the file is assigned to 1."""
with open(csv_file1) as file:
reader = csv.reader(file)
i = 0
while i < 35:
next(reader)
i += 1
words = {}
for row in reader:
words[row[0]] = 1
return words
def read_csv_negative_file(csv_file1: str) -> dict[str, int]:
"""Takes in a csv file of negative words and returns a dictionary where each word in the file is assigned to -1."""
with open(csv_file1) as file:
reader = csv.reader(file)
i = 0
while i < 35:
next(reader)
i += 1
words = {}
for row in reader:
words[row[0]] = -1
return words
def return_dictionary(csv_file1: str, csv_file2: str) -> dict[str, int]:
"""Takes in 2 csv files,one containing postive words and the other containing negative words. It returns a
dictionary containing words from both the files with appropriate setiment scores assigned."""
positive = read_csv_positive_file(csv_file1)
negative = read_csv_negative_file(csv_file2)
words = positive
for word in negative:
words[word] = -1
return words
def reasoning_words_list(csv_file: str) -> list:
""" Takes in a csv file of reasoning words and returns a list containing these words."""
with open(csv_file) as file:
reader = csv.reader(file)
reasoning_words = []
for row in reader:
row = row[0].lower()
reasoning_words.append(row)
return reasoning_words
if __name__ == '__main__':
import doctest
doctest.testmod(verbose=True)