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
|
Glossary []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *vocabSource) addTags(tags ...string) {
|
func (s *vocabSource) addTags(tags ...string) {
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
if !hasString(tag, d.Tags) {
|
if !hasString(tag, s.Tags) {
|
||||||
d.Tags = append(d.Tags, tag)
|
s.Tags = append(s.Tags, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *vocabSource) addTagsPri(tags ...string) {
|
func (s *vocabSource) addTagsPri(tags ...string) {
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
switch tag {
|
switch tag {
|
||||||
case "news1", "ichi1", "spec1", "gai1":
|
case "news1", "ichi1", "spec1", "gai1":
|
||||||
d.addTags("P")
|
s.addTags("P")
|
||||||
fallthrough
|
fallthrough
|
||||||
case "news2", "ichi2", "spec2", "gai2":
|
case "news2", "ichi2", "spec2", "gai2":
|
||||||
d.addTags(tag[:len(tag)-1])
|
s.addTags(tag[:len(tag)-1])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
kanjidic.go
37
kanjidic.go
@ -24,7 +24,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/FooSoft/jmdict"
|
"github.com/FooSoft/jmdict"
|
||||||
@ -38,9 +40,18 @@ type kanjiSource struct {
|
|||||||
Character string
|
Character string
|
||||||
Kunyomi []string
|
Kunyomi []string
|
||||||
Onyomi []string
|
Onyomi []string
|
||||||
|
Tags []string
|
||||||
Meanings []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 {
|
func buildKanjiJson(kanji []kanjiSource) kanjiJson {
|
||||||
dict := kanjiJson{make(map[string][]string)}
|
dict := kanjiJson{make(map[string][]string)}
|
||||||
|
|
||||||
@ -48,6 +59,7 @@ func buildKanjiJson(kanji []kanjiSource) kanjiJson {
|
|||||||
var params []string
|
var params []string
|
||||||
params = append(params, strings.Join(k.Onyomi, " "))
|
params = append(params, strings.Join(k.Onyomi, " "))
|
||||||
params = append(params, strings.Join(k.Kunyomi, " "))
|
params = append(params, strings.Join(k.Kunyomi, " "))
|
||||||
|
params = append(params, strings.Join(k.Tags, " "))
|
||||||
params = append(params, k.Meanings...)
|
params = append(params, k.Meanings...)
|
||||||
dict.Characters[k.Character] = params
|
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 {
|
func convertKanjidicCharacter(kanjidicCharacter jmdict.KanjidicCharacter) kanjiSource {
|
||||||
character := kanjiSource{Character: kanjidicCharacter.Literal}
|
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 {
|
if kanjidicCharacter.ReadingMeaning != nil {
|
||||||
for _, m := range kanjidicCharacter.ReadingMeaning.Meanings {
|
for _, m := range kanjidicCharacter.ReadingMeaning.Meanings {
|
||||||
if m.Language == nil || *m.Language == "en" {
|
if m.Language == nil || *m.Language == "en" {
|
||||||
|
Loading…
Reference in New Issue
Block a user