Convert entryBy* tables into views
This commit is contained in:
@@ -3,7 +3,6 @@ import 'dart:collection';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:jadb/_data_ingestion/jmdict/objects.dart';
|
||||
import 'package:jadb/_data_ingestion/jmdict/table_names.dart';
|
||||
import 'package:jadb/util/romaji_transliteration.dart';
|
||||
import 'package:sqflite_common/sqlite_api.dart';
|
||||
|
||||
class ResolvedXref {
|
||||
@@ -75,13 +74,11 @@ Future<void> seedJMDictData(List<Entry> entries, Database db) async {
|
||||
for (final e in entries) {
|
||||
b.insert(JMdictTableNames.entry, e.sqlValue);
|
||||
for (final k in e.kanji) {
|
||||
b.insert(JMdictTableNames.kanjiElement, k.sqlValue..addAll({'entryId': e.id}));
|
||||
// b.insert(
|
||||
// JMdictTableNames.entryByKana,
|
||||
// {'entryId': e.id, 'kana': transliterateKatakanaToHiragana(k.reading)},
|
||||
// // Some entries have the same reading twice with difference in katakana and hiragana
|
||||
// conflictAlgorithm: ConflictAlgorithm.ignore,
|
||||
// );
|
||||
b.insert(
|
||||
JMdictTableNames.kanjiElement,
|
||||
k.sqlValue..addAll({'entryId': e.id}),
|
||||
);
|
||||
|
||||
for (final i in k.info) {
|
||||
b.insert(
|
||||
JMdictTableNames.kanjiInfo,
|
||||
@@ -99,15 +96,6 @@ Future<void> seedJMDictData(List<Entry> entries, Database db) async {
|
||||
r.sqlValue..addAll({'entryId': e.id}),
|
||||
);
|
||||
|
||||
b.insert(
|
||||
JMdictTableNames.entryByKana,
|
||||
{
|
||||
'entryId': e.id,
|
||||
'kana': transliterateKanaToLatin(r.reading),
|
||||
},
|
||||
// Some entries have the same reading twice with difference in katakana and hiragana
|
||||
conflictAlgorithm: ConflictAlgorithm.ignore,
|
||||
);
|
||||
for (final i in r.info) {
|
||||
b.insert(
|
||||
JMdictTableNames.readingInfo,
|
||||
@@ -129,20 +117,6 @@ Future<void> seedJMDictData(List<Entry> entries, Database db) async {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (final s in e.senses) {
|
||||
for (final g in s.glossary) {
|
||||
b.insert(
|
||||
JMdictTableNames.entryByEnglish,
|
||||
{
|
||||
'entryId': e.id,
|
||||
'english': g.phrase,
|
||||
},
|
||||
// Some entries have the same reading twice with difference in katakana and hiragana
|
||||
conflictAlgorithm: ConflictAlgorithm.ignore,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await b.commit(noResult: true);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
abstract class JMdictTableNames {
|
||||
static const String entry = 'JMdict_Entry';
|
||||
static const String entryByKana = 'JMdict_EntryByKana';
|
||||
static const String entryByEnglish = 'JMdict_EntryByEnglish';
|
||||
static const String kanjiElement = 'JMdict_KanjiElement';
|
||||
static const String kanjiInfo = 'JMdict_KanjiElementInfo';
|
||||
static const String readingElement = 'JMdict_ReadingElement';
|
||||
@@ -23,8 +21,6 @@ abstract class JMdictTableNames {
|
||||
|
||||
static Set<String> get allTables => {
|
||||
entry,
|
||||
entryByKana,
|
||||
entryByEnglish,
|
||||
kanjiElement,
|
||||
kanjiInfo,
|
||||
readingElement,
|
||||
|
||||
@@ -29,7 +29,7 @@ class QueryWord extends Command {
|
||||
libsqlitePath: argResults!.option('libsqlite')!,
|
||||
);
|
||||
|
||||
final result = await JaDBConnection(db).searchWord('kana');
|
||||
final result = await JaDBConnection(db).searchWord('かな');
|
||||
|
||||
if (result == null) {
|
||||
print("Invalid search");
|
||||
|
||||
@@ -240,3 +240,17 @@ CREATE TABLE "JMdict_ExampleSentence" (
|
||||
"japanese" TEXT NOT NULL
|
||||
-- "type" TEXT NOT NULL DEFAULT "tat",
|
||||
);
|
||||
|
||||
CREATE VIEW "JMdict_EntryByKana"("kana", "entryId")
|
||||
AS
|
||||
SELECT
|
||||
"JMdict_ReadingElement"."reading" AS "kana",
|
||||
"JMdict_ReadingElement"."entryId" AS "entryId"
|
||||
FROM "JMdict_ReadingElement";
|
||||
|
||||
CREATE VIEW "JMdict_EntryByEnglish"("english", "entryId")
|
||||
AS
|
||||
SELECT
|
||||
"JMdict_SenseGlossary"."phrase" AS "english",
|
||||
"JMdict_Sense"."senseId" AS "entryId"
|
||||
FROM "JMdict_SenseGlossary" JOIN "JMdict_Sense" USING("senseId");
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
-- These tables are for optimizing searches.
|
||||
|
||||
-- In order to include results from both, the software should
|
||||
-- first check if the searchword is convertible to kana, and then
|
||||
-- potentially get results from both by doing a union between two
|
||||
-- selects.
|
||||
|
||||
CREATE TABLE "JMdict_EntryByKana" (
|
||||
"kana" TEXT NOT NULL,
|
||||
"entryId" INTEGER NOT NULL REFERENCES "JMdict_Entry"("id"),
|
||||
PRIMARY KEY ("kana", "entryId")
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE INDEX "JMdict_EntryByKana_byKana" ON "JMdict_EntryByKana"("kana");
|
||||
|
||||
CREATE TABLE "JMdict_EntryByEnglish" (
|
||||
"english" TEXT NOT NULL,
|
||||
"entryId" INTEGER NOT NULL REFERENCES "JMdict_Entry"("id"),
|
||||
PRIMARY KEY ("english", "entryId")
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE INDEX "JMdict_EntryByEnglish_byEnglish" ON "JMdict_EntryByEnglish"("english");
|
||||
Reference in New Issue
Block a user