forked from mahavivo/english-dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vivo
committed
Apr 15, 2019
1 parent
c4841ab
commit 56881b1
Showing
4 changed files
with
80 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# OALD4原始文档音标使用了"Kingsoft Phonetic Plain"字体,导致不安装该字体的电脑会出现乱码,在此批量替换修正。 | ||
# OALD4原始文档音标使用了“Kingsoft Phonetic Plain”字体,导致不安装该字体的电脑会出现乱码,在此批量替换修正。 | ||
# 金山词霸音标字体编码表可参见 http://www.fmddlmyy.cn/text66.html | ||
|
||
import re | ||
|
||
|
||
file_src = "/users/vivo/desktop/OALD4_INIT.txt" | ||
|
||
file_dst = "/users/vivo/desktop/OALD4_edited.txt" | ||
file_src = '/users/vivo/desktop/OALD4_INIT.txt' | ||
file_dst = '/users/vivo/desktop/OALD4_edited.txt' | ||
|
||
|
||
def converter(match): | ||
phonetic_string = match.group() | ||
correct_symbol = phonetic_string.replace("5", "ˈ").replace("7", "ˌ").replace("9", "ˌ") \ | ||
.replace("A", "æ").replace("B", "ɑ").replace("C", "ɔ").replace("E", "ə").replace("F", "ʃ") \ | ||
.replace("I", "ɪ").replace("J", "ʊ").replace("N", "ŋ").replace("Q", "ʌ") \ | ||
.replace("R", "ɔ").replace("T", "ð").replace("U", "u").replace("V", "ʒ") \ | ||
.replace("W", "θ").replace("Z", "ɛ").replace(r"\\\\", "ɜ").replace("^", "ɡ") \ | ||
.replace(":", "ː").replace("[", "ɜːr").replace("L", "ər").replace("?@", "US") | ||
correct_symbol = phonetic_string.replace('5', 'ˈ').replace('7', 'ˌ').replace('9', 'ˌ') \ | ||
.replace('A', 'æ').replace('B', 'ɑ').replace('C', 'ɔ').replace('E', 'ə').replace('F', 'ʃ') \ | ||
.replace('I', 'ɪ').replace('J', 'ʊ').replace('N', 'ŋ').replace('Q', 'ʌ') \ | ||
.replace('R', 'ɔ').replace('T', 'ð').replace('U', 'u').replace('V', 'ʒ') \ | ||
.replace('W', 'θ').replace('Z', 'ɛ').replace(r'\\\\', 'ɜ').replace('^', 'ɡ') \ | ||
.replace(':', 'ː').replace('[', 'ɜːr').replace('L', 'ər').replace('?@', 'US') | ||
|
||
return correct_symbol | ||
|
||
|
||
|
||
with open(file_src, 'r') as f: | ||
text = f.read() | ||
|
||
p = re.compile("/.*?; .*?/") | ||
|
||
p = re.compile('/.*?; .*?/') | ||
result = re.sub(p, converter, text) | ||
|
||
|
||
with open(file_dst, 'w') as fo: | ||
fo.write(result) | ||
fo.write(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#! /usr/bin/env python | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# csv数据转换成SQLite数据库格式,不直接放ecdict.db,是因为会膨胀很大。 | ||
# 此数据包含770611条记录,来自 https://github.com/skywind3000/ECDICT | ||
|
||
import stardict | ||
|
||
stardict.convert_dict("./ecdict.db", "./ecdict.csv") | ||
stardict.convert_dict('./ecdict.db', './ecdict.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters