Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
24 lines (24 sloc) 839 Bytes
import csv
import re
path = "C:\\Users\\Astha\\Desktop\\amazon_revs"
types = ['books' , 'dvd' , 'electronics' , 'kitchen_housewares']
cats = ['positive', 'negative']
with open('amazon_revs2.csv', 'wb') as f:
cw = csv.writer(f)
for t in types:
for c in cats:
t_p = path + '\\' + t + '\\' + c + '.review'
short_c = c[:3]
txt_p = open(t_p)
curr_rev = ''
add = 0
for line in txt_p:
# line = line.rstrip()
if re.match( r'<review_text>', line ):
add = 1
elif re.match( r'</review_text>', line ):
add = 0
cw.writerow([curr_rev, short_c])
curr_rev = ''
elif add == 1:
curr_rev = curr_rev + line
You can’t perform that action at this time.