-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraining_data_parser.py
45 lines (45 loc) · 1.5 KB
/
Training_data_parser.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
import os
import json
import csv
jsonenc = json.JSONEncoder()
print("hi")
data=[]
with open("/Suhas/USC/NLP 544/Project/yelp_academic_dataset_review.json", "r", encoding="latin1") as file:
# files = csv.reader(file)
count=0
for eachfile in file:
if count==11000:
break
count = count + 1
data.append(json.loads(eachfile))
count=0
psitive=0
negative=0
neutral=0
for eachdata in data:
if count==11000:
break
count = count + 1
# print(eachdata)
# try:
# os.remove('file'+str(count)+'.txt')
# except OSError:
# pass
# for each in eachfile:
stars = eachdata['stars']
if stars>3:
psitive= psitive+1
fileWrite = open('/Suhas/USC/NLP 544/Project/Data/Train/positive/positive'+str(count)+'.txt', "w", encoding="latin1")
fileWrite.write(str(eachdata['text']))
elif stars<3:
negative = negative + 1
fileWrite = open('/Suhas/USC/NLP 544/Project/Data/Train/negative/negative'+str(count)+'.txt', "w", encoding="latin1")
fileWrite.write(str(eachdata['text']))
elif stars==3:
neutral = neutral + 1
fileWrite = open('/Suhas/USC/NLP 544/Project/Data/Train/neutral/neutral'+str(count)+'.txt', "w", encoding="latin1")
fileWrite.write(str(eachdata['text']))
print("positive ",psitive)
print("negative ",negative)
print("neutral ",neutral)
print("end")