1
This commit is contained in:
Alex Yatskov 2016-12-17 19:24:08 -08:00
parent f4d0746f3c
commit 7300a38e59

View File

@ -27,14 +27,13 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"strconv"
"strings" "strings"
) )
type dbTagMeta struct { type dbTagMeta struct {
Category string `json:"class"` Category string `json:"class,omitempty"`
Notes string `json:"notes"` Notes string `json:"notes,omitempty"`
Order int `json:"order"` Order int `json:"order,omitempty"`
} }
type dbTerm struct { type dbTerm struct {
@ -56,18 +55,21 @@ func (term *dbTerm) addRules(rules ...string) {
term.Rules = appendStringUnique(term.Rules, rules...) term.Rules = appendStringUnique(term.Rules, rules...)
} }
func (terms dbTermList) crush() [][]string { func (terms dbTermList) crush() [][]interface{} {
var results [][]string var results [][]interface{}
for _, t := range terms { for _, t := range terms {
result := []string{ result := []interface{}{
t.Expression, t.Expression,
t.Reading, t.Reading,
strings.Join(t.Tags, " "), strings.Join(t.Tags, " "),
strings.Join(t.Rules, " "), strings.Join(t.Rules, " "),
strconv.Itoa(t.Score), t.Score,
}
for _, gloss := range t.Glossary {
result = append(result, gloss)
} }
result = append(result, t.Glossary...)
results = append(results, result) results = append(results, result)
} }
@ -92,24 +94,27 @@ func (kanji *dbKanji) addTags(tags ...string) {
} }
} }
func (kanji dbKanjiList) crush() [][]string { func (kanji dbKanjiList) crush() [][]interface{} {
var results [][]string var results [][]interface{}
for _, k := range kanji { for _, k := range kanji {
result := []string{ result := []interface{}{
k.Character, k.Character,
strings.Join(k.Onyomi, " "), strings.Join(k.Onyomi, " "),
strings.Join(k.Kunyomi, " "), strings.Join(k.Kunyomi, " "),
strings.Join(k.Tags, " "), strings.Join(k.Tags, " "),
} }
result = append(result, k.Meanings...) for _, meaning := range k.Meanings {
result = append(result, meaning)
}
results = append(results, result) results = append(results, result)
} }
return results return results
} }
func writeDb(outputDir, title string, termRecords [][]string, kanjiRecords [][]string, tagMeta map[string]dbTagMeta, pretty bool) error { func writeDb(outputDir, title string, termRecords [][]interface{}, kanjiRecords [][]interface{}, tagMeta map[string]dbTagMeta, pretty bool) error {
const DB_VERSION = 1 const DB_VERSION = 1
const BANK_STRIDE = 50000 const BANK_STRIDE = 50000
@ -121,7 +126,7 @@ func writeDb(outputDir, title string, termRecords [][]string, kanjiRecords [][]s
return json.Marshal(obj) return json.Marshal(obj)
} }
writeDbRecords := func(prefix string, records [][]string) (int, error) { writeDbRecords := func(prefix string, records [][]interface{}) (int, error) {
recordCount := len(records) recordCount := len(records)
bankCount := 0 bankCount := 0