-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmytokenizer.py
More file actions
42 lines (35 loc) · 945 Bytes
/
mytokenizer.py
File metadata and controls
42 lines (35 loc) · 945 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
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
'''
our tokenizer
'''
import sys
# import os
import twokenize
def tokenize(istring, ostring):
# print 'this is mytokenizer.py
ifile = open(istring, 'r')
ofile = open(ostring, 'w')
for line in ifile:
try:
ofile.write(u" ".join(twokenize.tokenize(
line[:])).encode('utf-8') + '\n')
except:
print line
ofile.close()
ifile.close()
def tokenize_str(istring):
ostring = []
for line in istring.split('\n'):
try:
ostring.append(
u" ".join(twokenize.tokenize(line[:])).encode('utf-8'))
except Exception as e:
print e
print line
return '\n'.join(ostring)
if __name__ == '__main__':
try:
tokenize(*sys.argv[1:])
except TypeError:
print "Usage : python tokenize.py <input file> <output file>"
print "See README for input file format"