-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkDict.py
38 lines (31 loc) · 1.07 KB
/
mkDict.py
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
#!/usr/bin/env python
#author:gaigai 2013/12/2
#This program generate the useful.dct by syl.mlf and full.dct
#input:syl.mlf full.dct
#output:useful.dct
import sys
if __name__ == '__main__':
if (len(sys.argv) != 4):
print 'Usage: mkDict.py infile(syl.mlf) infile(full.dct) outfile(useful.dct)'
sys.exit(1)
inFile1 = open(sys.argv[1], 'r')
inFile2 = open(sys.argv[2], 'r')
outFile = open(sys.argv[3], 'w')
content = inFile1.readlines()
newitem = []
for items in content:#this loop extracts the words in syl.mlf
if ".lab" not in items:
if "#" not in items:
if "." not in items:
items = items[:len(items)-1] #delete the "\n" in the end
newitem.append(items)
orderitem = list(set(newitem))
orderitem.sort()
phoneSet = inFile2.readlines()
for items in phoneSet:
item =items.split()
if item[0] in orderitem: #if in the set then output it
outFile.write(items)
inFile1.close()
inFile2.close()
outFile.close()