-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDev_parser.py
43 lines (43 loc) · 1.65 KB
/
Dev_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
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
psitive = 0
negative = 0
neutral = 0
for eachfile in file:
if count==12000:
break
count = count + 1
data.append(json.loads(eachfile))
count=10001
for eachdata in data:
if count==12000:
break
if count > 10000:
stars = eachdata['stars']
if stars > 3:
psitive = psitive + 1
fileWrite = open('/Suhas/USC/NLP 544/Project/Data/Dev/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/Dev/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/Dev/neutral/neutral' + str(count) + '.txt', "w",
encoding="latin1")
fileWrite.write(str(eachdata['text']))
# fileWrite = open('/Suhas/USC/NLP 544/Project/Data/Dev/file' + str(count) + '.txt', "w",
# encoding="latin1")
# fileWrite.write(str(eachdata['text'].split()))
count = count + 1
print("end")