WIP
This commit is contained in:
parent
a06c2ff08f
commit
1820d11c00
10
edict.go
10
edict.go
@ -23,7 +23,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/FooSoft/jmdict"
|
||||
@ -161,7 +161,13 @@ func jmdictExtractTerms(edictEntry jmdict.JmdictEntry) []dbTerm {
|
||||
return terms
|
||||
}
|
||||
|
||||
func jmdictExportDb(outputDir, title string, reader io.Reader, pretty bool) error {
|
||||
func jmdictExportDb(inputPath, outputDir, title string, pretty bool) error {
|
||||
reader, err := os.Open(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
dict, entities, err := jmdict.LoadJmdictNoTransform(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
|
10
enamdict.go
10
enamdict.go
@ -23,7 +23,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/FooSoft/jmdict"
|
||||
)
|
||||
@ -95,7 +95,13 @@ func jmnedictExtractTerms(enamdictEntry jmdict.JmnedictEntry) []dbTerm {
|
||||
return terms
|
||||
}
|
||||
|
||||
func jmnedictExportDb(outputDir, title string, reader io.Reader, pretty bool) error {
|
||||
func jmnedictExportDb(inputPath, outputDir, title string, pretty bool) error {
|
||||
reader, err := os.Open(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
dict, entities, err := jmdict.LoadJmnedictNoTransform(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
|
16
epwing.go
16
epwing.go
@ -23,9 +23,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -55,16 +52,11 @@ type epwingExtractor interface {
|
||||
getFontWide() map[int]string
|
||||
}
|
||||
|
||||
func epwingExportDb(outputDir, title string, reader io.Reader, pretty bool) error {
|
||||
data, err := ioutil.ReadAll(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func epwingExportDb(inputPath, outputDir, title string, pretty bool) error {
|
||||
var book epwingBook
|
||||
if err := json.Unmarshal(data, &book); err != nil {
|
||||
return err
|
||||
}
|
||||
// if err := json.Unmarshal(data, &book); err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
translateExp := regexp.MustCompile(`{{([nw])_(\d+)}}`)
|
||||
epwingExtractors := map[string]epwingExtractor{
|
||||
|
10
kanjidic.go
10
kanjidic.go
@ -24,7 +24,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/FooSoft/jmdict"
|
||||
@ -78,7 +78,13 @@ func kanjidicExtractKanji(entry jmdict.KanjidicCharacter) dbKanji {
|
||||
return kanji
|
||||
}
|
||||
|
||||
func kanjidicExportDb(outputDir, title string, reader io.Reader, pretty bool) error {
|
||||
func kanjidicExportDb(inputPath, outputDir, title string, pretty bool) error {
|
||||
reader, err := os.Open(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
dict, err := jmdict.LoadKanjidic(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
|
15
main.go
15
main.go
@ -26,7 +26,6 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -35,10 +34,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
flagPretty = 1 << iota
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage:\n %s [options] [edict|enamdict|kanjidic|epwing] input-path [output-dir]\n\n", path.Base(os.Args[0]))
|
||||
fmt.Fprintf(os.Stderr, "Parameters:\n")
|
||||
@ -46,7 +41,7 @@ func usage() {
|
||||
}
|
||||
|
||||
func exportDb(inputPath, outputDir, format, title string, pretty bool) error {
|
||||
handlers := map[string]func(string, string, io.Reader, bool) error{
|
||||
handlers := map[string]func(string, string, string, bool) error{
|
||||
"edict": jmdictExportDb,
|
||||
"enamdict": jmnedictExportDb,
|
||||
"kanjidic": kanjidicExportDb,
|
||||
@ -58,13 +53,7 @@ func exportDb(inputPath, outputDir, format, title string, pretty bool) error {
|
||||
return errors.New("unrecognized dictionray format")
|
||||
}
|
||||
|
||||
input, err := os.Open(inputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer input.Close()
|
||||
|
||||
return handler(outputDir, title, input, pretty)
|
||||
return handler(inputPath, outputDir, title, pretty)
|
||||
}
|
||||
|
||||
func serveDb(serveDir string, port int) error {
|
||||
|
Loading…
Reference in New Issue
Block a user