-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateLexicon.py
More file actions
35 lines (30 loc) · 922 Bytes
/
Copy pathcreateLexicon.py
File metadata and controls
35 lines (30 loc) · 922 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
# -*- coding: utf-8 -*-
import re
in_file = open(u'./lexicons/TOFEL.txt', 'r')
# pattern = r'^([a-zA-z]+(( |-)?[a-zA-Z]+)*)$'
#pattern = u'^([a-zA-Z \-]+)(\/([a-zA-z \-]+))*[\u4e00-\u9fa5]*$'
pattern = u'^([a-zA-Z \-]+)$'
out_file = open(u'./lexicons/TOFEL_2.txt', 'w')
count = 0
for line in in_file.readlines():
m = re.search(pattern, line.decode('utf-8'))
if m:
word = m.group(1)
word = word.strip()
print word
if len(word) > 1:
# 写入文件
out_file.write(word.encode('utf-8'))
out_file.write('\n')
count += 1
# word = m.group(3)
# if word:
# word = word.strip()
# if len(word) > 1:
# # 写入文件
# out_file.write(word.encode('utf-8'))
# out_file.write('\n')
# count += 1
out_file.close()
in_file.close()
print count