1
This commit is contained in:
Alex Yatskov 2016-11-04 22:51:50 -07:00
parent 8837365e7e
commit 97abfea07f

View File

@ -27,6 +27,7 @@ import (
"io" "io"
"os" "os"
"path" "path"
"strings"
"github.com/FooSoft/jmdict" "github.com/FooSoft/jmdict"
) )
@ -58,15 +59,15 @@ func (meta *termMetaEntry) addTagsPri(tags ...string) {
} }
} }
type termMetaIndex struct { type termMetaDb struct {
Version int `json:"version"` Version int `json:"version"`
Banks int `json:"banks"` Banks int `json:"banks"`
Entities map[string]string `json:"entities"` Entities map[string]string `json:"entities"`
entries []termMetaEntry entries []termMetaEntry
} }
func newTermMetaIndex(entries []termMetaEntry, entities map[string]string) termMetaIndex { func newTermMetaIndex(entries []termMetaEntry, entities map[string]string) termMetaDb {
return termMetaIndex{ return termMetaDb{
Version: DB_VERSION, Version: DB_VERSION,
Banks: bankCount(len(entries)), Banks: bankCount(len(entries)),
Entities: entities, Entities: entities,
@ -74,7 +75,7 @@ func newTermMetaIndex(entries []termMetaEntry, entities map[string]string) termM
} }
} }
func (index *termMetaIndex) output(dir string, pretty bool) error { func (index *termMetaDb) output(dir string, pretty bool) error {
if err := os.MkdirAll(dir, 0755); err != nil { if err := os.MkdirAll(dir, 0755); err != nil {
return err return err
} }
@ -94,16 +95,27 @@ func (index *termMetaIndex) output(dir string, pretty bool) error {
return err return err
} }
count := len(index.entries) var entries [][]string
var entryCount = len(entries)
for _, e := range index.entries {
entries = append(
entries,
[]string{
e.Expression,
e.Reading,
strings.Join(e.Tags, " "),
},
)
}
for i := 0; i < count; i += BANK_STRIDE { for i := 0; i < entryCount; i += BANK_STRIDE {
indexSrc := i indexSrc := i
indexDst := i + BANK_STRIDE indexDst := i + BANK_STRIDE
if indexDst > count { if indexDst > entryCount {
indexDst = count indexDst = entryCount
} }
bytes, err := marshalJson(index.entries[indexSrc:indexDst], pretty) bytes, err := marshalJson(entries[indexSrc:indexDst], pretty)
if err != nil { if err != nil {
return err return err
} }