1

kanjidic non-english support

This commit is contained in:
Alex Yatskov 2017-06-10 17:35:58 -07:00
parent 4ff2370fa3
commit 6d5fd0f4ac
3 changed files with 57 additions and 43 deletions

View File

@ -253,28 +253,3 @@ func detectFormat(path string) string {
return ""
}
func convertLanguage(language string) string {
switch language {
case "dutch":
return "dut"
case "french":
return "fre"
case "german":
return "ger"
case "hungarian":
return "hun"
case "italian":
return "ita"
case "russian":
return "rus"
case "slovenian":
return "slv"
case "spanish":
return "spa"
case "swedish":
return "swe"
default:
return ""
}
}

View File

@ -194,7 +194,27 @@ func jmdictExportDb(inputPath, outputDir, language, title string, stride int, pr
return err
}
langTag := convertLanguage(language)
var langTag string
switch language {
case "dutch":
langTag = "dut"
case "french":
langTag = "fre"
case "german":
langTag = "ger"
case "hungarian":
langTag = "hun"
case "italian":
langTag = "ita"
case "russian":
langTag = "rus"
case "slovenian":
langTag = "slv"
case "spanish":
langTag = "spa"
case "swedish":
langTag = "swe"
}
var terms dbTermList
for _, entry := range dict.Entries {

View File

@ -32,9 +32,23 @@ import (
const KANJIDIC_REVISION = "kanjidic1"
func kanjidicExtractKanji(entry jmdict.KanjidicCharacter) dbKanji {
func kanjidicExtractKanji(entry jmdict.KanjidicCharacter, language string) *dbKanji {
if entry.ReadingMeaning == nil {
return nil
}
kanji := dbKanji{Character: entry.Literal}
for _, m := range entry.ReadingMeaning.Meanings {
if m.Language == nil && language == "" || m.Language != nil && language == *m.Language {
kanji.Meanings = append(kanji.Meanings, m.Meaning)
}
}
if len(kanji.Meanings) == 0 {
return nil
}
if level := entry.Misc.JlptLevel; level != nil {
kanji.addTags(fmt.Sprintf("jlpt:%s", *level))
}
@ -60,24 +74,16 @@ func kanjidicExtractKanji(entry jmdict.KanjidicCharacter) dbKanji {
kanji.addTags(fmt.Sprintf("strokes:%s", counts[0]))
}
if entry.ReadingMeaning != nil {
for _, m := range entry.ReadingMeaning.Meanings {
if m.Language == nil || *m.Language == "en" {
kanji.Meanings = append(kanji.Meanings, m.Meaning)
}
}
for _, r := range entry.ReadingMeaning.Readings {
switch r.Type {
case "ja_on":
kanji.Onyomi = append(kanji.Onyomi, r.Value)
case "ja_kun":
kanji.Kunyomi = append(kanji.Kunyomi, r.Value)
}
for _, r := range entry.ReadingMeaning.Readings {
switch r.Type {
case "ja_on":
kanji.Onyomi = append(kanji.Onyomi, r.Value)
case "ja_kun":
kanji.Kunyomi = append(kanji.Kunyomi, r.Value)
}
}
return kanji
return &kanji
}
func kanjidicExportDb(inputPath, outputDir, language, title string, stride int, pretty bool) error {
@ -92,9 +98,22 @@ func kanjidicExportDb(inputPath, outputDir, language, title string, stride int,
return err
}
var langTag string
switch language {
case "french":
langTag = "fr"
case "spanish":
langTag = "es"
case "portuguese":
langTag = "pt"
}
var kanji dbKanjiList
for _, entry := range dict.Characters {
kanji = append(kanji, kanjidicExtractKanji(entry))
kanjiCurr := kanjidicExtractKanji(entry, langTag)
if kanjiCurr != nil {
kanji = append(kanji, *kanjiCurr)
}
}
tagMeta := map[string]dbTagMeta{