Permalink
Cannot retrieve contributors at this time
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?
BigData/get_amazon_revs.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
24 lines (24 sloc)
839 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |