-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphonetics.py
More file actions
81 lines (65 loc) · 1.97 KB
/
phonetics.py
File metadata and controls
81 lines (65 loc) · 1.97 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import csv
import sys
from prettytable import PrettyTable
ptable = PrettyTable()
args = sys.argv
readings_path = "data/readings.csv"
phonetics_path = "data/phonetics.csv"
def search_pair(glyph):
with open(phonetics_path, encoding="utf-8") as f_obj:
reader = csv.reader(f_obj, delimiter=",")
for line in reader:
if glyph in str(line[0]):
return line
def search_readings(glyph):
with open(readings_path, encoding="utf-8") as f_obj:
reader = csv.reader(f_obj, delimiter=",")
for line in reader:
if glyph in str(line[0]):
return line
def search_glyph_list(phonetic):
res = []
with open(phonetics_path, encoding="utf-8") as f_obj:
reader = csv.reader(f_obj, delimiter=",")
for line in reader:
if phonetic in str(line[1]):
res.append(line[0])
return res
def search_glyph_family(glyph):
sym = glyph
res = [glyph]
while True:
phonetic = search_pair(sym)
if phonetic:
sym = phonetic[1]
res.append(sym)
else:
break
return res
def search_group(kanji):
glyph_list = [kanji] + search_glyph_list(kanji)
res = []
with open(readings_path, encoding="utf-8") as f_obj:
reader = csv.reader(f_obj, delimiter=",")
for line in reader:
for glyph in glyph_list:
if glyph in str(line[0]):
res.append(line)
return res
if len(args) > 1:
family = search_glyph_family(args[1])
print("phonetic family: ", family)
for phonetic in family[:-1]:
ptable.add_rows(search_group(phonetic))
ptable.field_names = [
"glyph", "pin", "cant",
"on", "kun", "kr", "viet"
]
ptable.del_column("kun")
ptable.sort_key([1, 2])
ptable.align = "l"
print(phonetic)
print(ptable)
ptable.clear()
else:
print("argument required")