Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
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