1
This commit is contained in:
Alex Yatskov 2016-08-07 13:24:56 -07:00
parent 0e0e449e7e
commit 713f9bf3af
3 changed files with 27 additions and 14 deletions

View File

@ -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),

View File

@ -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)

View File

@ -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)