-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataset.py
35 lines (25 loc) · 979 Bytes
/
dataset.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
from csv import DictReader
class DataSet():
def __init__(self, name="train", path="./dataset"):
self.path = path
print("Reading dataset")
bodies = name+"_bodies.csv"
stances = name+"_stances.csv"
self.stances = self.read(stances)
articles = self.read(bodies)
self.articles = dict()
#make the body ID an integer value
for s in self.stances:
s['Body ID'] = int(s['Body ID'])
#copy all bodies into a dictionary
for article in articles:
self.articles[int(article['Body ID'])] = article['articleBody']
print("Total stances: " + str(len(self.stances)))
print("Total bodies: " + str(len(self.articles)))
def read(self,filename):
rows = []
with open(self.path + "/" + filename, "r", encoding='utf-8') as table:
r = DictReader(table)
for line in r:
rows.append(line)
return rows