Add stroke count
This commit is contained in:
parent
713f9bf3af
commit
e84763a8a6
12
common.go
12
common.go
@ -42,22 +42,22 @@ type vocabSource struct {
|
||||
Glossary []string
|
||||
}
|
||||
|
||||
func (d *vocabSource) addTags(tags ...string) {
|
||||
func (s *vocabSource) addTags(tags ...string) {
|
||||
for _, tag := range tags {
|
||||
if !hasString(tag, d.Tags) {
|
||||
d.Tags = append(d.Tags, tag)
|
||||
if !hasString(tag, s.Tags) {
|
||||
s.Tags = append(s.Tags, tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *vocabSource) addTagsPri(tags ...string) {
|
||||
func (s *vocabSource) addTagsPri(tags ...string) {
|
||||
for _, tag := range tags {
|
||||
switch tag {
|
||||
case "news1", "ichi1", "spec1", "gai1":
|
||||
d.addTags("P")
|
||||
s.addTags("P")
|
||||
fallthrough
|
||||
case "news2", "ichi2", "spec2", "gai2":
|
||||
d.addTags(tag[:len(tag)-1])
|
||||
s.addTags(tag[:len(tag)-1])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
37
kanjidic.go
37
kanjidic.go
@ -24,7 +24,9 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/FooSoft/jmdict"
|
||||
@ -38,9 +40,18 @@ type kanjiSource struct {
|
||||
Character string
|
||||
Kunyomi []string
|
||||
Onyomi []string
|
||||
Tags []string
|
||||
Meanings []string
|
||||
}
|
||||
|
||||
func (s *kanjiSource) addTags(tags ...string) {
|
||||
for _, tag := range tags {
|
||||
if !hasString(tag, s.Tags) {
|
||||
s.Tags = append(s.Tags, tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func buildKanjiJson(kanji []kanjiSource) kanjiJson {
|
||||
dict := kanjiJson{make(map[string][]string)}
|
||||
|
||||
@ -48,6 +59,7 @@ func buildKanjiJson(kanji []kanjiSource) kanjiJson {
|
||||
var params []string
|
||||
params = append(params, strings.Join(k.Onyomi, " "))
|
||||
params = append(params, strings.Join(k.Kunyomi, " "))
|
||||
params = append(params, strings.Join(k.Tags, " "))
|
||||
params = append(params, k.Meanings...)
|
||||
dict.Characters[k.Character] = params
|
||||
}
|
||||
@ -80,6 +92,31 @@ func outputKanjiJson(writer io.Writer, kanji []kanjiSource, pretty bool) error {
|
||||
func convertKanjidicCharacter(kanjidicCharacter jmdict.KanjidicCharacter) kanjiSource {
|
||||
character := kanjiSource{Character: kanjidicCharacter.Literal}
|
||||
|
||||
if level := kanjidicCharacter.Misc.JlptLevel; level != nil {
|
||||
character.addTags(fmt.Sprintf("jlpt:%s", *level))
|
||||
}
|
||||
|
||||
if grade := kanjidicCharacter.Misc.Grade; grade != nil {
|
||||
character.addTags(fmt.Sprintf("grade:%s", *grade))
|
||||
if gradeInt, err := strconv.Atoi(*grade); err == nil {
|
||||
if gradeInt >= 1 && gradeInt <= 8 {
|
||||
character.addTags("jouyou")
|
||||
} else if gradeInt >= 9 && gradeInt <= 10 {
|
||||
character.addTags("jinmeiyou")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, number := range kanjidicCharacter.DictionaryNumbers {
|
||||
if number.Type == "heisig" {
|
||||
character.addTags(fmt.Sprintf("heisig:%s", number.Value))
|
||||
}
|
||||
}
|
||||
|
||||
if counts := kanjidicCharacter.Misc.StrokeCounts; len(counts) > 0 {
|
||||
character.addTags(fmt.Sprintf("strokes:%s", counts[0]))
|
||||
}
|
||||
|
||||
if kanjidicCharacter.ReadingMeaning != nil {
|
||||
for _, m := range kanjidicCharacter.ReadingMeaning.Meanings {
|
||||
if m.Language == nil || *m.Language == "en" {
|
||||
|
Loading…
Reference in New Issue
Block a user