Module: Daidai::Tables
- Defined in:
- lib/daidai/tables.rb
Overview
Loads and memoizes the JMdictDB conjugation tables vendored under
resources/. The files are tab-separated and copied verbatim from jconj
(Stuart McGraw / EDRDG) — see NOTICE. Keep them in sync with upstream via
rake daidai:sync.
Defined Under Namespace
Classes: Okurigana
Constant Summary collapse
- DIR =
File.("resources", __dir__)
- CONJO_ERRATA =
Corrections for known errors in the upstream JMdictDB tables, applied at load so the vendored CSVs stay byte-identical to upstream (keeping
rake daidai:check_resourcesgreen) while daidai still emits the right form. Keyed by JMdict code + [conj_id, negative?, polite?, onum] so a pos-id renumber upstream can't silently misapply the fix; values override only the given Okurigana fields.• v5u negative conditional (買う → 買わなかったら): upstream conjo.csv stores "わかったら", dropping the な. Every other class is correct here (v5u-s even has わなかったら), so this one cell is a typo. Without it every godan-u verb's negative ~tara comes out as 買わかったら / 使わかったら / …. { [ "v5u", 11, true, false, 1 ] => { okuri: "わなかったら" } }.freeze
Class Method Summary collapse
-
.conj ⇒ Object
conjugation id (Integer) => human name ("Past (~ta)", …).
-
.conjo ⇒ Object
[pos_id, conj_id, negative?, polite?, onum] => Okurigana.
-
.pos_ids ⇒ Object
JMdict POS keyword ("v5k", "adj-i", …) => conjo pos id (Integer).
- .reload! ⇒ Object
Class Method Details
.conj ⇒ Object
conjugation id (Integer) => human name ("Past (~ta)", …)
33 34 35 |
# File 'lib/daidai/tables.rb', line 33 def conj @conj ||= read("conj.csv").to_h { |r| [ r["id"].to_i, r["name"] ] } end |
.conjo ⇒ Object
[pos_id, conj_id, negative?, polite?, onum] => Okurigana
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/daidai/tables.rb', line 38 def conjo @conjo ||= begin table = read("conjo.csv").each_with_object({}) do |r, acc| key = [ r["pos"].to_i, r["conj"].to_i, r["neg"] == "t", r["fml"] == "t", r["onum"].to_i ] acc[key] = Okurigana.new( stem: r["stem"].to_i, okuri: r["okuri"].to_s, euphr: presence(r["euphr"]), euphk: presence(r["euphk"]) ) end apply_conjo_errata(table) end end |
.pos_ids ⇒ Object
JMdict POS keyword ("v5k", "adj-i", …) => conjo pos id (Integer)
54 55 56 |
# File 'lib/daidai/tables.rb', line 54 def pos_ids @pos_ids ||= read("kwpos.csv").to_h { |r| [ r["kw"], r["id"].to_i ] } end |
.reload! ⇒ Object
58 59 60 |
# File 'lib/daidai/tables.rb', line 58 def reload! @conj = @conjo = @pos_ids = nil end |