1
yomichan-import/rikai.go

100 lines
2.4 KiB
Go
Raw Normal View History

2017-08-19 19:17:18 +00:00
/*
2017-08-19 19:17:31 +00:00
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>
2017-08-19 19:17:18 +00:00
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package main
import (
2017-08-19 19:17:31 +00:00
"database/sql"
"log"
2017-08-19 19:17:18 +00:00
"strings"
2017-08-19 19:17:31 +00:00
_ "github.com/mattn/go-sqlite3"
2017-08-19 19:17:18 +00:00
)
const RIKAI_REVISION = "rikai1"
func rikaiBuildRules(term *dbTerm) {
for _, tag := range term.Tags {
switch tag {
case "adj-i", "v1", "vk":
term.addRules(tag)
default:
if strings.HasPrefix(tag, "v5") {
term.addRules("v5")
} else if strings.HasPrefix(tag, "vs") {
term.addRules("vs")
}
}
}
}
func rikaiBuildScore(term *dbTerm) {
term.Score = 0
for _, tag := range term.Tags {
switch tag {
case "P":
term.Score += 5
case "arch", "iK":
term.Score -= 1
}
}
}
func rikaiExportDb(inputPath, outputDir, title string, stride int, pretty bool) error {
2017-08-19 19:17:31 +00:00
db, err := sql.Open("sqlite3", inputPath)
2017-08-19 19:17:18 +00:00
if err != nil {
return err
}
2017-08-19 19:17:31 +00:00
defer db.Close()
2017-08-19 19:17:18 +00:00
2017-08-19 19:17:31 +00:00
dictRows, err := db.Query("SELECT kanji, kana, entry FROM dict")
2017-08-19 19:17:18 +00:00
if err != nil {
return err
}
2017-08-19 19:17:31 +00:00
for dictRows.Next() {
var kanji, kana, entry *string
if err := dictRows.Scan(&kanji, &kana, &entry); err != nil {
return err
}
log.Print(kanji, kana, entry)
2017-08-19 19:17:18 +00:00
}
if title == "" {
2017-08-19 19:17:31 +00:00
title = "Rikai"
2017-08-19 19:17:18 +00:00
}
2017-08-19 19:17:31 +00:00
return nil
// return writeDb(
// outputDir,
// title,
// RIKAI_REVISION,
// terms.crush(),
// nil,
// rikaiBuildTagMeta(entities),
// stride,
// pretty,
// )
2017-08-19 19:17:18 +00:00
}