data(hanja): words, not only syllables
The import kept only readings of one syllable, so the Hanja search could convert 한 but never 한자, 학교, or 대한민국 — the conversion every other Korean input method offers. libhangul's table has 187k readings; both scripts now keep them all, and the search finds a word as readily as a syllable. The daemon pays for it: 24 MB instead of 12, and 170 ms to start instead of 30.
This commit is contained in:
17
map/mkhanja
17
map/mkhanja
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Write hanja.dict from a one-Hanja-per-row UTF-8 source."""
|
||||
"""Write hanja.dict from a Hanja-per-row UTF-8 source."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -10,16 +10,13 @@ MAXCANDIDATES = 128
|
||||
|
||||
|
||||
def ishangul(s):
|
||||
return len(s) == 1 and 0xAC00 <= ord(s) <= 0xD7A3
|
||||
return s != "" and all(0xAC00 <= ord(c) <= 0xD7A3 for c in s)
|
||||
|
||||
|
||||
def ishanja(s):
|
||||
if len(s) != 1:
|
||||
return False
|
||||
c = ord(s)
|
||||
return (0x3400 <= c <= 0x4DBF
|
||||
or 0x4E00 <= c <= 0x9FFF
|
||||
or 0xF900 <= c <= 0xFAFF)
|
||||
return s != "" and all(0x3400 <= ord(c) <= 0x4DBF
|
||||
or 0x4E00 <= ord(c) <= 0x9FFF
|
||||
or 0xF900 <= ord(c) <= 0xFAFF for c in s)
|
||||
|
||||
|
||||
def read(path):
|
||||
@@ -42,9 +39,9 @@ def read(path):
|
||||
raise ValueError(f"{path}:{lineno}: need Hanja<TAB>reading")
|
||||
hanja, reading = fields
|
||||
if not ishanja(hanja):
|
||||
raise ValueError(f"{path}:{lineno}: need one BMP Hanja character")
|
||||
raise ValueError(f"{path}:{lineno}: need BMP Hanja")
|
||||
if not ishangul(reading):
|
||||
raise ValueError(f"{path}:{lineno}: need one Hangul syllable")
|
||||
raise ValueError(f"{path}:{lineno}: need Hangul syllables")
|
||||
pair = (hanja, reading)
|
||||
if pair in seen:
|
||||
raise ValueError(f"{path}:{lineno}: duplicate Hanja reading")
|
||||
|
||||
Reference in New Issue
Block a user