WIP
This commit is contained in:
parent
8837365e7e
commit
97abfea07f
36
termmeta.go
36
termmeta.go
@ -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 i := 0; i < count; i += BANK_STRIDE {
|
for _, e := range index.entries {
|
||||||
indexSrc := i
|
entries = append(
|
||||||
indexDst := i + BANK_STRIDE
|
entries,
|
||||||
if indexDst > count {
|
[]string{
|
||||||
indexDst = count
|
e.Expression,
|
||||||
|
e.Reading,
|
||||||
|
strings.Join(e.Tags, " "),
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := marshalJson(index.entries[indexSrc:indexDst], pretty)
|
for i := 0; i < entryCount; i += BANK_STRIDE {
|
||||||
|
indexSrc := i
|
||||||
|
indexDst := i + BANK_STRIDE
|
||||||
|
if indexDst > entryCount {
|
||||||
|
indexDst = entryCount
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, err := marshalJson(entries[indexSrc:indexDst], pretty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user