-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecode.py
More file actions
49 lines (43 loc) · 1.18 KB
/
Copy pathdecode.py
File metadata and controls
49 lines (43 loc) · 1.18 KB
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
44
45
46
47
48
49
#!/usr/bin/env python
# Produce nicer CSV files for the insult detection problem
# Usage: `./scriptname inputfilename outputfilename`
from __future__ import unicode_literals
from ftfy import fix_text
import sys
import csv
infile = open(sys.argv[1])
outfile = open(sys.argv[2], 'w')
writer = csv.writer(outfile)
for line in infile:
#splits on commas
splits = line.split(",")
#make empty newline
newline = []
#add before the first comma and the second comma
newline.append(splits[0])
newline.append(splits[1])
comment = ",".join(splits[2:])
#make line that starts with common and adds after the second comma. strip the quotes
#comment = ','.join(splits[2:]).strip().strip('"').strip()
#replace double quote sequences with single quotes
#comment = comment.replace('""','"')
#get rid of all unicode
try:
comment = comment.decode("unicode-escape")
except:
pass
try:
comment = comment.decode("unicode-escape")
except:
pass
try:
comment = comment.decode("unicode-escape")
except:
pass
#encode as utf8
comment = fix_text(comment)
comment = comment.encode("utf-8")
newline.append(comment)
writer.writerow(newline)
infile.close()
outfile.close()