1

output revision

This commit is contained in:
Alex Yatskov 2016-12-23 21:52:49 -08:00
parent 3d8c170838
commit 27f5201098
6 changed files with 21 additions and 1 deletions

View File

@ -114,7 +114,7 @@ func (kanji dbKanjiList) crush() [][]interface{} {
return results
}
func writeDb(outputDir, title string, termRecords [][]interface{}, kanjiRecords [][]interface{}, tagMeta map[string]dbTagMeta, pretty bool) error {
func writeDb(outputDir, title string, revision string, termRecords [][]interface{}, kanjiRecords [][]interface{}, tagMeta map[string]dbTagMeta, pretty bool) error {
const DB_VERSION = 1
const BANK_STRIDE = 10000
@ -166,6 +166,7 @@ func writeDb(outputDir, title string, termRecords [][]interface{}, kanjiRecords
var db struct {
Title string `json:"title"`
Version int `json:"version"`
Revision string `json:"revision"`
TagMeta map[string]dbTagMeta `json:"tagMeta"`
TermBanks int `json:"termBanks"`
KanjiBanks int `json:"kanjiBanks"`
@ -173,6 +174,7 @@ func writeDb(outputDir, title string, termRecords [][]interface{}, kanjiRecords
db.Title = title
db.Version = DB_VERSION
db.Revision = revision
db.TagMeta = tagMeta
if db.TermBanks, err = writeDbRecords("term", termRecords); err != nil {

View File

@ -133,6 +133,10 @@ func (e *daijirinExtractor) exportRules(term *dbTerm, tags []string) {
}
}
func (*daijirinExtractor) getRevision() string {
return "daijirin:1"
}
func (e *daijirinExtractor) exportTags(term *dbTerm, tags []string) {
parsed := []string{
"並立助",

View File

@ -29,6 +29,8 @@ import (
"github.com/FooSoft/jmdict"
)
const JMDICT_REVISION = "jmdict:1"
func jmdictBuildRules(term *dbTerm) {
for _, tag := range term.Tags {
switch tag {
@ -183,6 +185,7 @@ func jmdictExportDb(inputPath, outputDir, title string, pretty bool) error {
return writeDb(
outputDir,
title,
JMDICT_REVISION,
terms.crush(),
nil,
jmdictBuildTagMeta(entities),

View File

@ -28,6 +28,8 @@ import (
"github.com/FooSoft/jmdict"
)
const JMNEDICT_REVISION = "jmnedict:1"
func jmnedictBuildTagMeta(entities map[string]string) map[string]dbTagMeta {
tags := make(map[string]dbTagMeta)
@ -115,6 +117,7 @@ func jmnedictExportDb(inputPath, outputDir, title string, pretty bool) error {
return writeDb(
outputDir,
title,
JMNEDICT_REVISION,
terms.crush(),
nil,
jmnedictBuildTagMeta(entities),

View File

@ -57,6 +57,7 @@ type epwingExtractor interface {
extractKanji(entry epwingEntry) []dbKanji
getFontNarrow() map[int]string
getFontWide() map[int]string
getRevision() string
}
func epwingExportDb(inputPath, outputDir, title string, pretty bool) error {
@ -100,6 +101,7 @@ func epwingExportDb(inputPath, outputDir, title string, pretty bool) error {
var terms dbTermList
var kanji dbKanjiList
var revisions []string
for _, subbook := range book.Subbooks {
if extractor, ok := epwingExtractors[subbook.Title]; ok {
@ -134,6 +136,8 @@ func epwingExportDb(inputPath, outputDir, title string, pretty bool) error {
terms = append(terms, extractor.extractTerms(entry)...)
kanji = append(kanji, extractor.extractKanji(entry)...)
}
revisions = append(revisions, extractor.getRevision())
} else {
return fmt.Errorf("failed to find compatible extractor for '%s'", subbook.Title)
}
@ -142,6 +146,7 @@ func epwingExportDb(inputPath, outputDir, title string, pretty bool) error {
return writeDb(
outputDir,
title,
strings.Join(revisions, ";"),
terms.crush(),
kanji.crush(),
nil,

View File

@ -30,6 +30,8 @@ import (
"github.com/FooSoft/jmdict"
)
const KANJIDIC_REVISION = "kanjidic:1"
func kanjidicExtractKanji(entry jmdict.KanjidicCharacter) dbKanji {
kanji := dbKanji{Character: entry.Literal}
@ -107,6 +109,7 @@ func kanjidicExportDb(inputPath, outputDir, title string, pretty bool) error {
return writeDb(
outputDir,
title,
KANJIDIC_REVISION,
nil,
kanji.crush(),
tagMeta,