-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathposition_tagger.py
More file actions
executable file
·30 lines (27 loc) · 947 Bytes
/
position_tagger.py
File metadata and controls
executable file
·30 lines (27 loc) · 947 Bytes
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
#!/usr/bin/python
import os
def tagfiles(olddir, newdir):
if not os.path.isdir(newdir):
os.mkdir(newdir)
for filename in os.listdir(olddir):
f = open("%s/%s" % (olddir,filename)).read().split(" ")
w = open("%s/%s" % (newdir,filename), 'w')
length = len(f)
for i in range(length):
if i < length/4:
w.write("%s_Q1 " % f[i])
elif i < length*3/4:
w.write("%s_Q23 " % f[i])
else:
w.write("%s_Q4 " % f[i])
w.close()
if __name__ == "__main__":
# usage: python position_tagger.py -d neg
# usage: python position_tagger.py -d yelp/default/1star
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-d", "--dir", dest="directory")
(options, args) = parser.parse_args()
olddir = options.directory
newdir = "%s_position" % olddir
tagfiles(olddir, newdir)