diff --git a/common.go b/common.go index a578c48..c94ead2 100644 --- a/common.go +++ b/common.go @@ -42,7 +42,7 @@ type vocabSource struct { Glossary []string } -func (d *vocabSource) addTags(tags []string) { +func (d *vocabSource) addTags(tags ...string) { for _, tag := range tags { if !hasString(tag, d.Tags) { d.Tags = append(d.Tags, tag) @@ -50,6 +50,19 @@ func (d *vocabSource) addTags(tags []string) { } } +func (d *vocabSource) addTagsPri(tags ...string) { + for _, tag := range tags { + switch tag { + case "news1", "ichi1", "spec1", "gai1": + d.addTags("P") + fallthrough + case "news2", "ichi2", "spec2", "gai2": + d.addTags(tag[:len(tag)-1]) + break + } + } +} + func buildVocabJson(entries []vocabSource, entities map[string]string) vocabJson { dict := vocabJson{ Indices: make(map[string]string), diff --git a/edict.go b/edict.go index 2307174..09a2aae 100644 --- a/edict.go +++ b/edict.go @@ -43,12 +43,12 @@ func convertEdictEntry(edictEntry jmdict.JmdictEntry) []vocabSource { entry.Expression = kanji.Expression entry.Reading = reading.Reading - entry.addTags(kanji.Information) - entry.addTags(kanji.Priorities) + entry.addTags(kanji.Information...) + entry.addTagsPri(kanji.Priorities...) } - entry.addTags(reading.Information) - entry.addTags(reading.Priorities) + entry.addTags(reading.Information...) + entry.addTagsPri(reading.Priorities...) for _, sense := range edictEntry.Sense { if hasString(reading.Reading, sense.RestrictedReadings) { @@ -63,10 +63,10 @@ func convertEdictEntry(edictEntry jmdict.JmdictEntry) []vocabSource { entry.Glossary = append(entry.Glossary, glossary.Content) } - entry.addTags(sense.PartsOfSpeech) - entry.addTags(sense.Fields) - entry.addTags(sense.Misc) - entry.addTags(sense.Dialects) + entry.addTags(sense.PartsOfSpeech...) + entry.addTags(sense.Fields...) + entry.addTags(sense.Misc...) + entry.addTags(sense.Dialects...) } entries = append(entries, entry) diff --git a/enamdict.go b/enamdict.go index 4cfe389..9cf6336 100644 --- a/enamdict.go +++ b/enamdict.go @@ -43,16 +43,16 @@ func convertJmnedictEntry(enamdictEntry jmdict.JmnedictEntry) []vocabSource { entry.Expression = kanji.Expression entry.Reading = reading.Reading - entry.addTags(kanji.Information) - entry.addTags(kanji.Priorities) + entry.addTags(kanji.Information...) + entry.addTagsPri(kanji.Priorities...) } - entry.addTags(reading.Information) - entry.addTags(reading.Priorities) + entry.addTags(reading.Information...) + entry.addTagsPri(reading.Priorities...) for _, trans := range enamdictEntry.Translations { entry.Glossary = append(entry.Glossary, trans.Translations...) - entry.addTags(trans.NameTypes) + entry.addTags(trans.NameTypes...) } entries = append(entries, entry)