-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword.py
49 lines (42 loc) · 1.19 KB
/
word.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
39
40
41
42
43
44
45
46
47
48
49
# 处理不规则单词(待完善)
# 设置用户语音库路径
import sys, os, re
wds = sys.argv[1]
rule_tuple = (
('[ml]ice$', '([ml])ice$', '\\1ice'),
('booths$', 'booths$', 'booth'),
('feet$', 'feet$', 'foot'),
('eeth$', 'eeth$', 'ooth'),
# ('l[eo]aves$', 'l([eo])aves$', 'l\\1af'),
('ses$', 'ses$', 'sis'),
# ('men$', 'men$', 'man'),
('ives$', 'ives$', 'ife'),
('eaux$', 'eaux$', 'eau'),
('lves$', 'lves$', 'lf'),
('[sxz]es$', 'es$', ''),
('[^aeioudgkprt]hes$', 'es$', ''),
('(qu|[^aeiou])ies$', 'ies$', 'y'),
('s$', 's$', ''),
(',$', ',$', ''),
('.$', '.$', ''),
('ed$', 'ed$', ''),
#('ing$', 'ing$', 'e')
('ing$', 'ing$', '')
)
def regex_rules(rules=rule_tuple):
for line in rules:
pattern, search, replace = line
yield lambda word: re.search(pattern, word) and re.sub(search, replace, word)
def danshu(noun):
for rule in regex_rules():
result = rule(noun)
if result:
return result
try:
path = "/Users/lispython/workspace/dict/voice/"+wds[0]+"/"+wds+".wav"
if not os.path.exists(path):
wd = danshu(wds)
path = "/Users/lispython/workspace/dict/voice/"+wd[0]+"/"+wd+".wav"
print path
except:
pass