Skip to content

Commit

Permalink
!squash
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Jun 10, 2023
1 parent 733e81b commit 1c6f278
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions src/unihan_db/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,47 @@ def import_char(
c.kIRGDaeJaweon.append(k)

if "kFenn" in char:
for d in char["kFenn"]:
c.kFenn.append(kFenn(phonetic=d["phonetic"], frequency=d["frequency"]))
for _kf in char["kFenn"]:
assert isinstance(_kf, dict)
c.kFenn.append(kFenn(phonetic=_kf["phonetic"], frequency=_kf["frequency"]))

if "kHanyuPinlu" in char:
for d in char["kHanyuPinlu"]:
for _khp in char["kHanyuPinlu"]:
assert isinstance(_khp, dict)
assert isinstance(_khp["location"], dict)
c.kHanyuPinlu.append(
kHanyuPinlu(phonetic=d["phonetic"], frequency=d["frequency"])
kHanyuPinlu(phonetic=_khp["phonetic"], frequency=_khp["frequency"])
)

if "kHDZRadBreak" in char:
d = char["kHDZRadBreak"]
k = kHDZRadBreak(radical=d["radical"], ucn=d["ucn"])
k.locations.append(
UnhnLocation(
volume=d["location"]["volume"],
page=d["location"]["page"],
character=d["location"]["character"],
virtual=d["location"]["virtual"],
_khrb = char["kHDZRadBreak"]
assert isinstance(_khrb, dict)
assert isinstance(_khrb["location"], dict)
c.kHDZRadBreak.append(
kHDZRadBreak(
radical=_khrb["radical"],
ucn=_khrb["ucn"],
locations=[
UnhnLocation(
volume=_khrb["location"]["volume"],
page=_khrb["location"]["page"],
character=_khrb["location"]["character"],
virtual=_khrb["location"]["virtual"],
)
],
)
)
c.kHDZRadBreak.append(k)

if "kSBGY" in char:
for d in char["kSBGY"]:
k = kSBGY()
k.locations.append(UnhnLocation(page=d["page"], character=d["character"]))
c.kSBGY.append(k)
for _ksbgy in char["kSBGY"]:
assert isinstance(_ksbgy, dict)
c.kSBGY.append(
kSBGY(
locations=UnhnLocation(
page=_ksbgy["page"], character=_ksbgy["character"]
)
)
)

rs_fields = ( # radical-stroke fields, since they're the same structure
("kRSUnicode", kRSUnicode, c.kRSUnicode),
Expand All @@ -235,16 +249,17 @@ def import_char(
("kRSKorean", kRSKorean, c.kRSKorean),
)

for f, Model, column in rs_fields:
if f in char:
for _md in char[f]:
for f_rs, RSModel, rs_column in rs_fields:
if f_rs in char:
for _md in char[f_rs]:
assert isinstance(_md, dict)
k = Model(
radical=_md["radical"],
strokes=_md["strokes"],
simplified=_md["simplified"],
rs_column.append(
RSModel(
radical=_md["radical"],
strokes=_md["strokes"],
simplified=_md["simplified"],
)
)
column.append(k)

irg_fields = ( # IRG, since they're the same structure
("kIRG_GSource", kIRG_GSource, c.kIRG_GSource),
Expand All @@ -258,11 +273,11 @@ def import_char(
("kIRG_VSource", kIRG_VSource, c.kIRG_VSource),
)

for f, Model, column in irg_fields:
if f in char:
_irg = char[f]
for f_irg, IRGModel, column in irg_fields:
if f_irg in char:
_irg = char[f_irg]
assert isinstance(_irg, dict)
column.append(Model(source=_irg["source"], location=_irg["location"]))
column.append(IRGModel(source=_irg["source"], location=_irg["location"]))

if "kGSR" in char:
for _kgsr in char["kGSR"]:
Expand Down

0 comments on commit 1c6f278

Please sign in to comment.