1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 13:57:29 +01:00

Remove test database

This commit is contained in:
Oystein Kristoffer Tveit 2022-06-04 15:53:48 +02:00
parent 5ba64bbb46
commit cad62f2b8b
21 changed files with 0 additions and 78548 deletions

View File

@ -1,6 +0,0 @@
test.db
data/jisho
data/radkfile
data/kradfile
data/0002_radicals.json
!data/jouyou

View File

@ -1,295 +0,0 @@
-- KANJI
CREATE TABLE Kanji_YomiExample (
exampleID INTEGER PRIMARY KEY AUTOINCREMENT,
example TEXT NOT NULL,
reading TEXT NOT NULL,
meaning TEXT NOT NULL,
UNIQUE (example, reading, meaning)
);
CREATE TABLE Kanji_Radical (
id INTEGER NOT NULL UNIQUE,
symbol CHAR(1) NOT NULL PRIMARY KEY,
strokes INTEGER NOT NULL,
meaning TEXT NOT NULL,
searchSymbol CHAR(1)
);
CREATE TABLE Kanji_Radical_Forms (
form CHAR(1) NOT NULL PRIMARY KEY,
radical CHAR(1) NOT NULL,
FOREIGN KEY(radical) REFERENCES Kanji_Radical(symbol)
);
CREATE TABLE Kanji_Kunyomi (
yomi TEXT NOT NULL PRIMARY KEY
);
CREATE TABLE Kanji_Onyomi (
yomi TEXT NOT NULL PRIMARY KEY
);
CREATE TABLE Kanji_Part (
part CHAR(1) NOT NULL PRIMARY KEY
-- FOREIGN KEY(part) REFERENCES Kanji_Radical(symbol)
);
CREATE TABLE Kanji_Result (
kanji CHAR(1) PRIMARY KEY,
taughtIn INTEGER CHECK (taughtIn BETWEEN 1 AND 7),
jlptLevel INTEGER CHECK (jlptLevel BETWEEN 1 AND 5),
newspaperFrequencyRank INTEGER,
strokeCount INTEGER NOT NULL,
meaning INTEGER NOT NULL,
radical CHAR(1) NOT NULL,
isJouyou BOOLEAN NOT NULL DEFAULT false,
FOREIGN KEY (radical) REFERENCES Kanji_Radical(symbol)
);
CREATE TABLE Kanji_ResultKunyomiExample_XRef (
exampleID INTEGER NOT NULL,
kanji CHAR(1) NOT NULL,
FOREIGN KEY(exampleID) REFERENCES Kanji_YomiExample(exampleID),
FOREIGN KEY(kanji) REFERENCES Kanji_Result(kanji),
PRIMARY KEY(exampleID, kanji)
);
CREATE TABLE Kanji_ResultOnyomiExample_XRef (
exampleID INTEGER NOT NULL,
kanji CHAR(1) NOT NULL,
FOREIGN KEY(exampleID) REFERENCES Kanji_YomiExample(exampleID),
FOREIGN KEY(kanji) REFERENCES Kanji_Result(kanji),
PRIMARY KEY(exampleID, kanji)
);
CREATE TABLE Kanji_ResultKunyomi_XRef (
yomi TEXT NOT NULL,
kanji CHAR(1) NOT NULL,
FOREIGN KEY(yomi) REFERENCES Kanji_Kunyomi(yomi),
FOREIGN KEY(kanji) REFERENCES Kanji_Result(kanji),
PRIMARY KEY(yomi, kanji)
);
CREATE TABLE Kanji_ResultOnyomi_XRef (
yomi TEXT NOT NULL,
kanji CHAR(1) NOT NULL,
FOREIGN KEY(yomi) REFERENCES Kanji_Onyomi(yomi),
FOREIGN KEY(kanji) REFERENCES Kanji_Result(kanji),
PRIMARY KEY(yomi, kanji)
);
CREATE TABLE Kanji_ResultPart_XRef (
part CHAR(1) NOT NULL,
kanji CHAR(1) NOT NULL,
FOREIGN KEY(part) REFERENCES Kanji_Part(part),
FOREIGN KEY(kanji) REFERENCES Kanji_Result(kanji),
PRIMARY KEY(part, kanji)
);
-- RADKFILE
CREATE TABLE RADKFILE (
kanji CHAR(1) NOT NULL,
radical CHAR(1) NOT NULL,
FOREIGN KEY(radical) REFERENCES Kanji_Radical(symbol)
);
CREATE INDEX RADK ON RADKFILE (radical);
CREATE INDEX KRAD ON RADKFILE (kanji);
-- Example Sentence
CREATE TABLE ExampleSentence_Result (
resultID INTEGER PRIMARY KEY AUTOINCREMENT,
kanji TEXT NOT NULL,
kana TEXT NOT NULL,
english TEXT NOT NULL
);
CREATE TABLE ExampleSentence_Piece (
orderNum INTEGER NOT NULL,
lifted TEXT,
unlifted TEXT NOT NULL,
resultID INTEGER NOT NULL,
FOREIGN KEY(resultID) REFERENCES ExampleSentence_Result(resultID),
PRIMARY KEY(resultID, orderNum)
);
-- Words
CREATE TABLE PhraseScrape_Result (
uri TEXT NOT NULL PRIMARY KEY
);
CREATE TABLE PhraseScrape_Sentence (
english TEXT NOT NULL,
japanese TEXT NOT NULL,
PRIMARY KEY (english, japanese)
);
CREATE TABLE PhraseScrape_Sentence_Piece (
orderNum INTEGER NOT NULL,
lifted TEXT,
unlifted TEXT NOT NULL,
sentenceEnglish TEXT NOT NULL,
sentenceJapanese TEXT NOT NULL,
FOREIGN KEY(sentenceEnglish, sentenceJapanese) REFERENCES PhraseScrape_Sentence(english, japanese) ON DELETE CASCADE,
PRIMARY KEY (sentenceEnglish, sentenceJapanese, orderNum)
);
CREATE TABLE PhraseScrape_Meaning_SeeAlsoTerm (
seeAlsoTerm TEXT NOT NULL,
meaningDefinition TEXT NOT NULL,
resultUri TEXT NOT NULL,
FOREIGN KEY (meaningDefinition, resultUri) REFERENCES PhraseScrape_Meaning (definition, resultUri) ON DELETE CASCADE,
PRIMARY KEY (seeAlsoTerm, meaningDefinition, resultUri)
);
CREATE TABLE PhraseScrape_Meaning_Supplemental (
supplemental TEXT NOT NULL,
meaningDefinition TEXT NOT NULL,
resultUri TEXT NOT NULL,
FOREIGN KEY (meaningDefinition, resultUri) REFERENCES PhraseScrape_Meaning (definition, resultUri) ON DELETE CASCADE,
PRIMARY KEY (supplemental, meaningDefinition, resultUri)
);
CREATE TABLE PhraseScrape_Meaning_Tag (
tag TEXT NOT NULL,
meaningDefinition TEXT NOT NULL,
resultUri TEXT NOT NULL,
FOREIGN KEY (meaningDefinition, resultUri) REFERENCES PhraseScrape_Meaning (definition, resultUri) ON DELETE CASCADE,
PRIMARY KEY (tag, meaningDefinition, resultUri)
);
CREATE TABLE PhraseScrape_Meaning (
definition TEXT NOT NULL,
definitionAbstract TEXT,
resultUri TEXT NOT NULL,
FOREIGN KEY(resultUri) REFERENCES PhraseScrape_Result(uri) ON DELETE CASCADE,
PRIMARY KEY(definition,resultUri)
);
CREATE TABLE PhraseScrape_MeaningSentence_XRef (
sentenceEnglish TEXT NOT NULL,
sentenceJapanese TEXT NOT NULL,
resultUri TEXT NOT NULL,
FOREIGN KEY(resultUri) REFERENCES PhraseScrape_Result(uri) ON DELETE CASCADE,
FOREIGN KEY(sentenceEnglish, sentenceJapanese) REFERENCES PhraseScrape_Sentence(english, japanese) ON DELETE CASCADE
);
CREATE TABLE PhraseScrape_KanjiKanaPair (
kanji TEXT NOT NULL,
kana TEXT,
resultUri TEXT NOT NULL,
FOREIGN KEY(resultUri) REFERENCES PhraseScrape_Result(uri) ON DELETE CASCADE,
PRIMARY KEY (kanji, kana, resultUri)
);
CREATE TABLE PhraseScrape_AudioFile (
uri TEXT NOT NULL PRIMARY KEY,
mimetype TEXT NOT NULL,
resultUri TEXT NOT NULL,
FOREIGN KEY(resultUri) REFERENCES PhraseScrape_Result(uri) ON DELETE CASCADE
);
CREATE TABLE PhraseScrape_Note (
note TEXT NOT NULL,
resultUri TEXT NOT NULL,
FOREIGN KEY(resultUri) REFERENCES PhraseScrape_Result(uri) ON DELETE CASCADE,
PRIMARY KEY (note, resultUri)
);
-- API
CREATE TABLE PhraseSearch_JishoResult (
slug TEXT NOT NULL PRIMARY KEY,
isCommon BOOLEAN
);
CREATE TABLE PhraseScrape_JishoResult_Tag (
tag TEXT NOT NULL,
resultSlug TEXT NOT NULl,
FOREIGN KEY(resultSlug) REFERENCES PhraseSearch_JishoResult(slug) ON DELETE CASCADE,
PRIMARY KEY (tag, resultSlug)
);
CREATE TABLE PhraseScrape_JishoResult_Jlpt (
jlpt TEXT NOT NULL,
resultSlug TEXT NOT NULl,
FOREIGN KEY(resultSlug) REFERENCES PhraseSearch_JishoResult(slug) ON DELETE CASCADE,
PRIMARY KEY (jlpt, resultSlug)
);
CREATE TABLE PhraseSearch_JapaneseWord (
word TEXT,
reading TEXT,
resultSlug TEXT NOT NULl,
FOREIGN KEY(resultSlug) REFERENCES PhraseSearch_JishoResult(slug) ON DELETE CASCADE,
PRIMARY KEY (word, reading, resultSlug),
CHECK (word NOT NULL OR reading NOT NULL)
);
CREATE TABLE PhraseSearch_WordSense (
id INTEGER PRIMARY KEY AUTOINCREMENT
);
CREATE TABLE PhraseSearch_WordSense_Link (
text TEXT NOT NULL,
url TEXT NOT NULL,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY(url, senseID)
);
CREATE TABLE PhraseSearch_WordSense_Tag (
tag TEXT NOT NULL,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY (tag, senseID)
);
CREATE TABLE PhraseSearch_WordSense_SeeAlso (
seeAlso TEXT NOT NULL,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY (seeAlso, senseID)
);
CREATE TABLE PhraseSearch_WordSense_Antonym (
antonym TEXT NOT NULL,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY (antonym, senseID)
);
CREATE TABLE PhraseSearch_WordSense_Source (
language TEXT NOT NULL,
word TEXT,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY (language, senseID)
);
CREATE TABLE PhraseSearch_WordSense_Info (
info TEXT NOT NULL,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY (info, senseID)
);
CREATE TABLE PhraseSearch_WordSense_Restriction (
restriction TEXT NOT NULL,
senseID INTEGER NOT NULL,
FOREIGN KEY(senseID) REFERENCES PhraseSearch_WordSense(id) ON DELETE CASCADE,
PRIMARY KEY (restriction, senseID)
);
CREATE TABLE PhraseSearch_Attribution (
jmdict BOOLEAN NOT NULL,
jmnedict BOOLEAN NOT NULL,
dbpedia TEXT,
resultSlug TEXT NOT NULl PRIMARY KEY,
FOREIGN KEY(resultSlug) REFERENCES PhraseSearch_JishoResult(slug) ON DELETE CASCADE
);

View File

@ -1,254 +0,0 @@
INSERT INTO Kanji_Radical(id, symbol, strokes, meaning, searchSymbol) VALUES
(1, '', 1, 'one', NULL),
(2, '', 1, 'line', NULL),
(3, '', 1, 'dot', NULL),
(4, '', 1, 'slash', NULL),
(5, '', 1, 'second', NULL),
(6, '', 1, 'hook', NULL),
(7, '', 2, 'two', NULL),
(8, '', 2, 'lid', NULL),
(9, '', 2, 'man, human', NULL),
(10, '', 2, 'man, human', ''),
(11, '𠆢', 2, 'man, human', ''),
(12, '', 2, 'legs', NULL),
(13, '', 2, 'enter', NULL),
(14, '', 2, 'eight', NULL),
(15, '', 2, 'eight', ''),
(16, '', 2, 'open country', NULL),
(17, '', 2, 'cover', NULL),
(18, '', 2, 'ice', NULL),
(19, '', 2, 'table', NULL),
(20, '', 2, 'container, open mouth', NULL),
(21, '', 2, 'knife, sword', NULL),
(22, '', 2, 'knife, sword', ''),
(23, '', 2, 'power, force', NULL),
(24, '', 2, 'wrap, embrace', NULL),
(25, '', 2, 'spoon', NULL),
(26, '', 2, 'box', NULL),
(27, '', 2, 'ten, complete', NULL),
(28, '', 2, 'divination', NULL),
(29, '', 2, 'kneel', NULL),
(30, '', 2, 'cliff', NULL),
(31, '', 2, 'private', NULL),
(32, '', 2, 'right hand', NULL),
(33, '', 2, 'katakana, jisho search radical', NULL),
(34, '', 2, 'second', NULL),
(35, '', 2, 'katakana, jisho search radical', NULL),
(36, '', 2, 'slash', NULL),
(360, '𠂉', 2, 'slash', ''),
(37, '', 3, 'walk', ''),
(38, '', 3, 'mouth, opening', NULL),
(39, '', 3, 'enclosure', NULL),
(40, '', 3, 'earth', NULL),
(41, '', 3, 'scholar, bachelor', NULL),
(42, '', 3, 'go', NULL),
(43, '', 3, 'evening, sunset', NULL),
(44, '', 3, 'big, very', NULL),
(45, '', 3, 'woman, female', NULL),
(46, '', 3, 'child, seed', NULL),
(47, '', 3, 'roof', NULL),
(48, '', 3, 'thumb, inch', NULL),
(49, '', 3, 'small, insignificant', NULL),
(50, '', 3, 'small, insignificant', ''),
(51, '', 3, 'lame', NULL),
(52, '', 3, 'corpse', NULL),
(53, '', 3, 'sprout', NULL),
(54, '', 3, 'mountain', NULL),
(55, '', 3, 'river', NULL),
(56, '', 3, 'river', NULL),
(57, '', 3, 'work', NULL),
(58, '', 3, 'oneself', NULL),
(59, '', 3, 'turban, scarf', NULL),
(60, '', 3, 'pestle', NULL),
(61, '', 3, 'short, tiny', NULL),
(62, '广', 3, 'house on cliff', NULL),
(63, '', 3, 'long stride', NULL),
(64, '', 3, 'two hands, twenty', NULL),
(65, '', 3, 'shoot, arrow', NULL),
(66, '', 3, 'bow', NULL),
(67, '', 3, 'pig snout', NULL),
(68, '', 3, 'pig snout', NULL),
(69, '', 3, 'bristle, beard', NULL),
(70, '', 3, 'step', NULL),
(71, '', 3, 'heart', ''),
(72, '', 3, 'hand', ''),
(73, '', 3, 'water', ''),
(74, '', 3, 'dog', ''),
(75, '', 3, 'grass', ''),
(76, '', 3, 'town (阝 right)', ''),
(77, '', 3, 'mound, dam (阝 left)', ''),
(78, '', 3, 'second', NULL),
(79, '', 3, 'lid', NULL),
(80, '', 3, 'right hand', NULL),
(81, '', 3, 'slash', NULL),
(82, '', 4, 'old', ''),
(83, '', 4, 'heart', NULL),
(84, '', 4, 'spear, halberd', NULL),
(85, '', 4, 'door, house', NULL),
(86, '', 4, 'hand', NULL),
(87, '', 4, 'branch', NULL),
(88, '', 4, 'rap', NULL),
(89, '', 4, 'script, literature', NULL),
(90, '', 4, 'dipper', NULL),
(91, '', 4, 'axe', NULL),
(92, '', 4, 'square', NULL),
(93, '', 4, 'perish', NULL),
(94, '', 4, 'sun, day', NULL),
(95, '', 4, 'say', NULL),
(96, '', 4, 'moon, month', NULL),
(97, '', 4, 'tree', NULL),
(98, '', 4, 'lack, yawn', NULL),
(99, '', 4, 'stop', NULL),
(100, '', 4, 'death, decay', NULL),
(101, '', 4, 'weapon, lance', NULL),
(102, '', 4, 'compare, compete', NULL),
(103, '', 4, 'fur, hair', NULL),
(104, '', 4, 'clan', NULL),
(105, '', 4, 'steam, breath', NULL),
(106, '', 4, 'water', NULL),
(107, '', 4, 'fire', NULL),
(108, '', 4, 'fire', ''),
(109, '', 4, 'claw', NULL),
(110, '', 4, 'father', NULL),
(111, '', 4, 'mix, twine, cross', NULL),
(112, '', 4, 'split wood', NULL),
(113, '', 4, 'slice', NULL),
(114, '', 4, 'cow', NULL),
(115, '', 4, 'dog', NULL),
(116, '', 4, 'sign', ''),
(117, '', 4, 'jade (king)', NULL),
(118, '', 4, 'legs', NULL),
(119, '', 4, 'two', NULL),
(120, '', 4, 'wrap, embrace', NULL),
(121, '', 4, 'lame', NULL),
(122, '', 4, 'two', NULL),
(123, '', 4, 'sprout', NULL),
(124, '', 4, 'oneself', NULL),
(125, '', 4, 'mother, do not', NULL),
(126, '', 5, 'dark, profound', NULL),
(127, '', 5, 'tile', NULL),
(128, '', 5, 'sweet', NULL),
(129, '', 5, 'life', NULL),
(130, '', 5, 'use', NULL),
(131, '', 5, 'field', NULL),
(132, '', 5, 'bolt of cloth', NULL),
(133, '', 5, 'sickness', ''),
(134, '', 5, 'footsteps', NULL),
(135, '', 5, 'white', NULL),
(136, '', 5, 'skin', NULL),
(137, '', 5, 'dish', NULL),
(138, '', 5, 'eye', NULL),
(139, '', 5, 'spear', NULL),
(140, '', 5, 'arrow', NULL),
(141, '', 5, 'stone', NULL),
(142, '', 5, 'sign', NULL),
(143, '', 5, 'track', ''),
(144, '', 5, 'grain', NULL),
(145, '', 5, 'cave', NULL),
(146, '', 5, 'stand, erect', NULL),
(147, '', 5, 'clothes', ''),
(148, '', 5, 'one', NULL),
(149, '', 5, 'work', NULL),
(150, '', 5, 'open country', NULL),
(151, '', 5, 'mother, do not', NULL),
(152, '', 5, 'net', ''),
(153, '', 5, 'fang', NULL),
(154, '', 6, 'melon', NULL),
(155, '', 6, 'bamboo', NULL),
(156, '', 6, 'rice', NULL),
(157, '', 6, 'silk', NULL),
(158, '', 6, 'jar', NULL),
(159, '', 6, 'sheep', NULL),
(160, '', 6, 'feather', NULL),
(161, '', 6, 'beard', NULL),
(162, '', 6, 'plow', NULL),
(163, '', 6, 'ear', NULL),
(164, '', 6, 'brush', NULL),
(165, '', 6, 'meat', NULL),
(166, '', 6, 'self', NULL),
(167, '', 6, 'arrive', NULL),
(168, '', 6, 'mortar', NULL),
(169, '', 6, 'tongue', NULL),
(170, '', 6, 'boat', NULL),
(171, '', 6, 'stopping', NULL),
(172, '', 6, 'colour, prettiness', NULL),
(173, '', 6, 'tiger stripes', NULL),
(174, '', 6, 'insect', NULL),
(175, '', 6, 'blood', NULL),
(176, '', 6, 'go, do', NULL),
(177, '', 6, 'clothes', NULL),
(178, '西', 6, 'west', NULL),
(179, '', 7, 'minster, official', NULL),
(180, '', 7, 'see', NULL),
(181, '', 7, 'horn', NULL),
(182, '', 7, 'speech', NULL),
(183, '', 7, 'valley', NULL),
(184, '', 7, 'bean', NULL),
(185, '', 7, 'pig', NULL),
(186, '', 7, 'cat, badger', NULL),
(187, '', 7, 'shell', NULL),
(188, '', 7, 'red, naked', NULL),
(189, '', 7, 'run', NULL),
(190, '', 7, 'foot', NULL),
(191, '', 7, 'body', NULL),
(192, '', 7, 'cart, car', NULL),
(193, '', 7, 'bitter', NULL),
(194, '', 7, 'morning', NULL),
(195, '', 7, 'wine, alcohol', NULL),
(196, '', 7, 'divide, distinguish, choose', NULL),
(197, '', 7, 'village, mile', NULL),
(198, '', 7, 'opposite', NULL),
(199, '', 7, 'wheat', NULL),
(200, '', 8, 'metal, gold', NULL),
(201, '', 8, 'long, grow', NULL),
(202, '', 8, 'gate', NULL),
(203, '', 8, 'slave, capture', NULL),
(204, '', 8, 'small bird', NULL),
(205, '', 8, 'rain', NULL),
(206, '', 8, 'blue', NULL),
(207, '', 8, 'wrong', NULL),
(208, '', 8, 'big, very', NULL),
(209, '', 8, 'mountain', NULL),
(210, '', 8, 'legs', NULL),
(211, '', 8, 'script, literature', NULL),
(212, '', 9, 'face', NULL),
(213, '', 9, 'leather, rawhide', NULL),
(214, '', 9, 'leek', NULL),
(215, '', 9, 'sound', NULL),
(216, '', 9, 'leaf', NULL),
(217, '', 9, 'wind', NULL),
(218, '', 9, 'fly', NULL),
(219, '', 9, 'eat, food', NULL),
(220, '', 9, 'head', NULL),
(221, '', 9, 'fragrance', NULL),
(222, '', 9, 'mouth, opening', NULL),
(223, '', 10, 'horse', NULL),
(224, '', 10, 'bone', NULL),
(225, '', 10, 'tall', NULL),
(226, '', 10, 'long hair', NULL),
(227, '', 10, 'fight', NULL),
(228, '', 10, 'herbs, sacrificial wine', NULL),
(229, '', 10, 'tripod, cauldron', NULL),
(230, '', 10, 'ghost, demon', NULL),
(231, '', 10, 'stand, erect', NULL),
(232, '', 10, 'tanned leather', NULL),
(233, '', 11, 'fish', NULL),
(234, '', 11, 'bird', NULL),
(235, '', 11, 'salt', NULL),
(236, '鹿', 11, 'deer', NULL),
(237, '', 11, 'hemp, flax', NULL),
(238, '', 11, 'second', NULL),
(239, '', 11, 'mouth, opening', ''),
(240, '', 11, 'yellow', NULL),
(241, '', 11, 'black', NULL),
(242, '', 12, 'millet', NULL),
(243, '', 12, 'embroidery, needlework', NULL),
(244, '', 12, 'fire', NULL),
(245, '', 12, 'stop', NULL),
(246, '', 13, 'frog, amphibian', NULL),
(247, '', 13, 'tripod', NULL),
(248, '', 13, 'drum', NULL),
(249, '', 13, 'rat, mouse', NULL),
(250, '', 14, 'nose', NULL),
(251, '', 14, 'even, uniformly', NULL),
(252, '', 17, 'flute', NULL);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
DB_NAME=test.db
all: clean dart
sqlite3 $(DB_NAME) < 0001_initial.sql
sqlite3 $(DB_NAME) < 0002_populate_radicals.sql
sqlite3 $(DB_NAME) < 0003_populate_radkfile.sql
sqlite3 $(DB_NAME) < 0004_populate_jouyou_kanji.sql
convert_kradk:
iconv -f EUC-JP -t UTF-8 -o data/radkfile_utf8 data/radkfile
dart:
dart run tools/update_0002.dart
dart run tools/update_0003.dart
dart run tools/update_0004.dart
clean:
rm test.db || true

View File

@ -1 +0,0 @@
一右雨円王音下火花貝学気九休玉金空月犬見五口校左三山子四糸字耳七車手十出女小上森人水正生青夕石赤千川先早草足村大男竹中虫町天田土二日入年白八百文木本名目立力林六

View File

@ -1 +0,0 @@
引羽雲園遠何科夏家歌画回会海絵外角楽活間丸岩顔汽記帰弓牛魚京強教近兄形計元言原戸古午後語工公広交光考行高黄合谷国黒今才細作算止市矢姉思紙寺自時室社弱首秋週春書少場色食心新親図数西声星晴切雪船線前組走多太体台地池知茶昼長鳥朝直通弟店点電刀冬当東答頭同道読内南肉馬売買麦半番父風分聞米歩母方北毎妹万明鳴毛門夜野友用曜来里理話

View File

@ -1 +0,0 @@
悪安暗医委意育員院飲運泳駅央横屋温化荷界開階寒感漢館岸起期客究急級宮球去橋業曲局銀区苦具君係軽血決研県庫湖向幸港号根祭皿仕死使始指歯詩次事持式実写者主守取酒受州拾終習集住重宿所暑助昭消商章勝乗植申身神真深進世整昔全相送想息速族他打対待代第題炭短談着注柱丁帳調追定庭笛鉄転都度投豆島湯登等動童農波配倍箱畑発反坂板皮悲美鼻筆氷表秒病品負部服福物平返勉放味命面問役薬由油有遊予羊洋葉陽様落流旅両緑礼列練路和

View File

@ -1 +0,0 @@
愛案以衣位茨印英栄媛塩岡億加果貨課芽賀改械害街各覚潟完官管関観願岐希季旗器機議求泣給挙漁共協鏡競極熊訓軍郡群径景芸欠結建健験固功好香候康佐差菜最埼材崎昨札刷察参産散残氏司試児治滋辞鹿失借種周祝順初松笑唱焼照城縄臣信井成省清静席積折節説浅戦選然争倉巣束側続卒孫帯隊達単置仲沖兆低底的典伝徒努灯働特徳栃奈梨熱念敗梅博阪飯飛必票標不夫付府阜富副兵別辺変便包法望牧末満未民無約勇要養浴利陸良料量輪類令冷例連老労録

View File

@ -1 +0,0 @@
圧囲移因永営衛易益液演応往桜可仮価河過快解格確額刊幹慣眼紀基寄規喜技義逆久旧救居許境均禁句型経潔件険検限現減故個護効厚耕航鉱構興講告混査再災妻採際在財罪殺雑酸賛士支史志枝師資飼示似識質舎謝授修述術準序招証象賞条状常情織職制性政勢精製税責績接設絶祖素総造像増則測属率損貸態団断築貯張停提程適統堂銅導得毒独任燃能破犯判版比肥非費備評貧布婦武復複仏粉編弁保墓報豊防貿暴脈務夢迷綿輸余容略留領歴

View File

@ -1 +0,0 @@
胃異遺域宇映延沿恩我灰拡革閣割株干巻看簡危机揮貴疑吸供胸郷勤筋系敬警劇激穴券絹権憲源厳己呼誤后孝皇紅降鋼刻穀骨困砂座済裁策冊蚕至私姿視詞誌磁射捨尺若樹収宗就衆従縦縮熟純処署諸除承将傷障蒸針仁垂推寸盛聖誠舌宣専泉洗染銭善奏窓創装層操蔵臓存尊退宅担探誕段暖値宙忠著庁頂腸潮賃痛敵展討党糖届難乳認納脳派拝背肺俳班晩否批秘俵腹奮並陛閉片補暮宝訪亡忘棒枚幕密盟模訳郵優預幼欲翌乱卵覧裏律臨朗論

View File

@ -1 +0,0 @@
亜哀挨曖握扱宛嵐依威為畏尉萎偉椅彙違維慰緯壱逸芋咽姻淫陰隠韻唄鬱畝浦詠影鋭疫悦越謁閲炎怨宴援煙猿鉛縁艶汚凹押旺欧殴翁奥憶臆虞乙俺卸穏佳苛架華菓渦嫁暇禍靴寡箇稼蚊牙瓦雅餓介戒怪拐悔皆塊楷潰壊懐諧劾崖涯慨蓋該概骸垣柿核殻郭較隔獲嚇穫岳顎掛括喝渇葛滑褐轄且釜鎌刈甘汗缶肝冠陥乾勘患貫喚堪換敢棺款閑勧寛歓監緩憾還環韓艦鑑含玩頑企伎忌奇祈軌既飢鬼亀幾棋棄毀畿輝騎宜偽欺儀戯擬犠菊吉喫詰却脚虐及丘朽臼糾嗅窮巨拒拠虚距御凶叫狂享況峡挟狭恐恭脅矯響驚仰暁凝巾斤菌琴僅緊錦謹襟吟駆惧愚偶遇隅串屈掘窟繰勲薫刑茎契恵啓掲渓蛍傾携継詣慶憬稽憩鶏迎鯨隙撃桁傑肩倹兼剣拳軒圏堅嫌献遣賢謙鍵繭顕懸幻玄弦舷股虎孤弧枯雇誇鼓錮顧互呉娯悟碁勾孔巧甲江坑抗攻更拘肯侯恒洪荒郊貢控梗喉慌硬絞項溝綱酵稿衡購乞拷剛傲豪克酷獄駒込頃昆恨婚痕紺魂墾懇沙唆詐鎖挫采砕宰栽彩斎債催塞歳載剤削柵索酢搾錯咲刹拶撮擦桟惨傘斬暫旨伺刺祉肢施恣脂紫嗣雌摯賜諮侍慈餌璽軸𠮟疾執湿嫉漆芝赦斜煮遮邪蛇酌釈爵寂朱狩殊珠腫趣寿呪需儒囚舟秀臭袖羞愁酬醜蹴襲汁充柔渋銃獣叔淑粛塾俊瞬旬巡盾准殉循潤遵庶緒如叙徐升召匠床抄肖尚昇沼宵症祥称渉紹訟掌晶焦硝粧詔奨詳彰憧衝償礁鐘丈冗浄剰畳壌嬢錠譲醸拭殖飾触嘱辱尻伸芯辛侵津唇娠振浸紳診寝慎審震薪刃尽迅甚陣尋腎須吹炊帥粋衰酔遂睡穂随髄枢崇据杉裾瀬是姓征斉牲凄逝婿誓請醒斥析脊隻惜戚跡籍拙窃摂仙占扇栓旋煎羨腺詮践箋潜遷薦繊鮮禅漸膳繕狙阻租措粗疎訴塑遡礎双壮荘捜挿桑掃曹曽爽喪痩葬僧遭槽踪燥霜騒藻憎贈即促捉俗賊遜汰妥唾堕惰駄耐怠胎泰堆袋逮替滞戴滝択沢卓拓託濯諾濁但脱奪棚誰丹旦胆淡嘆端綻鍛弾壇恥致遅痴稚緻畜逐蓄秩窒嫡抽衷酎鋳駐弔挑彫眺釣貼超跳徴嘲澄聴懲勅捗沈珍朕陳鎮椎墜塚漬坪爪鶴呈廷抵邸亭貞帝訂逓偵堤艇締諦泥摘滴溺迭哲徹撤添塡殿斗吐妬途渡塗賭奴怒到逃倒凍唐桃透悼盗陶塔搭棟痘筒稲踏謄藤闘騰洞胴瞳峠匿督篤凸突屯豚頓貪鈍曇丼那謎鍋軟尼弐匂虹尿妊忍寧捻粘悩濃把覇婆罵杯排廃輩培陪媒賠伯拍泊迫剝舶薄漠縛爆箸肌鉢髪伐抜罰閥氾帆汎伴畔般販斑搬煩頒範繁藩蛮盤妃彼披卑疲被扉碑罷避尾眉微膝肘匹泌姫漂苗描猫浜賓頻敏瓶扶怖附訃赴浮符普腐敷膚賦譜侮舞封伏幅覆払沸紛雰噴墳憤丙併柄塀幣弊蔽餅壁璧癖蔑偏遍哺捕舗募慕簿芳邦奉抱泡胞俸倣峰砲崩蜂飽褒縫乏忙坊妨房肪某冒剖紡傍帽貌膨謀頰朴睦僕墨撲没勃堀奔翻凡盆麻摩磨魔昧埋膜枕又抹慢漫魅岬蜜妙眠矛霧娘冥銘滅免麺茂妄盲耗猛網黙紋冶弥厄躍闇喩愉諭癒唯幽悠湧猶裕雄誘憂融与誉妖庸揚揺溶腰瘍踊窯擁謡抑沃翼拉裸羅雷頼絡酪辣濫藍欄吏痢履璃離慄柳竜粒隆硫侶虜慮了涼猟陵僚寮療瞭糧厘倫隣瑠涙累塁励戻鈴零霊隷齢麗暦劣烈裂恋廉錬呂炉賂露弄郎浪廊楼漏籠麓賄脇惑枠湾腕

View File

@ -1 +0,0 @@
氏統保第結派案策基価提挙応企検藤沢裁証援施井護展態鮮視条幹独宮率衛張監環審義訴株姿閣衆評影松撃佐核整融製票渉響推請器士討攻崎督授催及憲離激摘系批郎健盟従修隊織拡故振弁就異献厳維浜遺塁邦素遣抗模雄益緊標宣昭廃伊江僚吉盛皇臨踏壊債興源儀創障継筋闘葬避司康善逮迫惑崩紀聴脱級博締救執房撤削密措志載陣我為抑幕染奈傷択秀徴弾償功拠秘拒刑塚致繰尾描鈴盤項喪伴養懸街契掲躍棄邸縮還属慮枠恵露沖緩節需射購揮充貢鹿却端賃獲郡併徹貴衝焦奪災浦析譲称納樹挑誘紛至宗促慎控智握宙俊銭渋銃操携診託撮誕侵括謝駆透津壁稲仮裂敏是排裕堅訳芝綱典賀扱顧弘看訟戒祉誉歓奏勧騒閥甲縄郷揺免既薦隣華範隠徳哲杉釈己妥威豪熊滞微隆症暫忠倉彦肝喚沿妙唱阿索誠襲懇俳柄驚麻李浩剤瀬趣陥斎貫仙慰序旬兼聖旨即柳舎偽較覇詳抵脅茂犠旗距雅飾網竜詩繁翼潟敵魅嫌斉敷擁圏酸罰滅礎腐脚潮梅尽僕桜滑孤炎賠句鋼頑鎖彩摩励縦輝蓄軸巡稼瞬砲噴誇祥牲秩帝宏唆阻泰賄撲堀菊絞縁唯膨矢耐塾漏慶猛芳懲剣彰棋丁恒揚冒之倫陳憶潜梨仁克岳概拘墓黙須偏雰遇諮狭卓亀糧簿炉牧殊殖艦輩穴奇慢鶴謀暖昌拍朗寛覆胞泣隔浄没暇肺貞靖鑑飼陰銘随烈尋稿丹啓也丘棟壌漫玄粘悟舗妊熟旭恩騰往豆遂狂岐陛緯培衰艇屈径淡抽披廷錦准暑磯奨浸剰胆繊駒虚霊帳悔諭惨虐翻墜沼据肥徐糖搭盾脈滝軌俵妨擦鯨荘諾雷漂懐勘栽拐駄添冠斜鏡聡浪亜覧詐壇勲魔酬紫曙紋卸奮欄逸涯拓眼獄尚彫穏顕巧矛垣欺釣萩粛栗愚嘉遭架鬼庶稚滋幻煮姫誓把践呈疎仰剛疾征砕謡嫁謙后嘆菌鎌巣頻琴班棚潔酷宰廊寂辰霞伏碁俗漠邪晶墨鎮洞履劣那殴娠奉憂朴亭淳怪鳩酔惜穫佳潤悼乏該赴桑桂髄虎盆晋穂壮堤飢傍疫累痴搬晃癒桐寸郭尿凶吐宴鷹賓虜陶鐘憾猪紘磁弥昆粗訂芽庄傘敦騎寧循忍怠如寮祐鵬鉛珠凝苗獣哀跳匠垂蛇澄縫僧眺亘呉凡憩媛溝恭刈睡錯伯笹穀陵霧魂弊妃舶餓窮掌麗綾臭悦刃縛暦宜盲粋辱毅轄猿弦稔窒炊洪摂飽冗桃狩朱渦紳枢碑鍛刀鼓裸猶塊旋弓幣膜扇腸槽慈楊伐駿漬糾亮墳坪紺娯椿舌羅峡俸厘峰圭醸蓮弔乙汁尼遍衡薫猟羊款閲偵喝敢胎酵憤豚遮扉硫赦窃泡瑞又慨紡恨肪扶戯伍忌濁奔斗蘭迅肖鉢朽殻享秦茅藩沙輔媒鶏禅嘱胴迭挿嵐椎絹陪剖譜郁悠淑帆暁傑楠笛玲奴錠拳翔遷拙侍尺峠篤肇渇叔雌亨堪叙酢吟逓嶺甚喬崇漆岬癖愉寅礁乃洲屯樺槙姻巌擬塀唇睦閑胡幽峻曹詠卑侮鋳抹尉槻隷禍蝶酪茎帥逝汽琢匿襟蛍蕉寡琉痢庸朋坑藍賊搾畔遼唄孔橘漱呂拷嬢苑巽杜渓翁廉謹瞳湧欣窯褒醜升殉煩巴禎劾租堕桟稜婿倭斐慕矯罷囚某虹魁泌鴻赳於蚊漸厄葵禄藻嫡孟嚇尭凸巳韻暢硝霜芹勅棺杏鳳儒慧馨楼愁匡彬欽眉褐薪嵯賜繕綜翠栓榛鮎艶凹蔦惣隼錬衷渚斥逐芙稀皐詔惟雛耀佑渥黛宵憧惇妄甫脩蚕酌蒼嬉頒暉肢只凱檀謄彗丑梓叶嗣絢汐伽朔抄畝黎爽蛮惰旺冴偲萌瑠壱侯允鯉蒔遥弧瑛舜彪附但卯芋綺凌茜洸皓婆毬鯛緋邑怜碧倣穣啄悌酉柚倹亦繭采詢賦紗玖眸錘弐倖諄笙痘裟侃爾洵昴耗莞銑碩伶滉宥伎晏迪朕且綸晨竣燦吏頌麿楓箇梧琳澪哉晟匁凪衿丙梢茄颯恕勺瑚蕗瞭遵虞燎侑柊斤謁捺嵩茉蓉燿袈冶誼墾栞菖勁椋旦紬叡凜胤爵亥麟脹汰莉瑳瑶椰耶丞絃奎璃昂塑熙柾諒菫崚鞠捷濫

View File

@ -1 +0,0 @@
党協総区領県設改府査委軍団各島革村勢減再税営比防補境導副算輸述線農州武象域額欧担準賞辺造被技低復移個門課脳極含蔵量型況針専谷史階管兵接細効丸湾録省旧橋岸周材戸央券編捜竹超並療採森競介根販歴将幅般貿講林装諸劇河航鉄児禁印逆換久短油暴輪占植清倍均億圧芸署伸停爆陸玉波帯延羽固則乱普測豊厚齢囲卒略承順岩練軽了庁城患層版令角絡損募裏仏績築貨混昇池血温季星永著誌庫刊像香坂底布寺宇巨震希触依籍汚枚複郵仲栄札板骨傾届巻燃跡包駐弱紹雇替預焼簡章臓律贈照薄群秒奥詰双刺純翌快片敬悩泉皮漁荒貯硬埋柱祭袋筆訓浴童宝封胸砂塩賢腕兆床毛緑尊祝柔殿濃液衣肩零幼荷泊黄甘臣浅掃雲掘捨軟沈凍乳恋紅郊腰炭踊冊勇械菜珍卵湖喫干虫刷湯溶鉱涙匹孫鋭枝塗軒毒叫拝氷乾棒祈拾粉糸綿汗銅湿瓶咲召缶隻脂蒸肌耕鈍泥隅灯辛磨麦姓筒鼻粒詞胃畳机膚濯塔沸灰菓帽枯涼舟貝符憎皿肯燥畜挟曇滴伺

View File

@ -1 +0,0 @@
政議民連対部合市内相定回選米実関決全表戦経最現調化当約首法性要制治務成期取都和機平加受続進数記初指権支産点報済活原共得解交資予向際勝面告反判認参利組信在件側任引求所次昨論官増係感情投示変打直両式確果容必演歳争談能位置流格疑過局放常状球職与供役構割費付由説難優夫収断石違消神番規術備宅害配警育席訪乗残想声念助労例然限追商葉伝働形景落好退頭負渡失差末守若種美命福望非観察段横深申様財港識呼達良候程満敗値突光路科積他処太客否師登易速存飛殺号単座破除完降責捕危給苦迎園具辞因馬愛富彼未舞亡冷適婦寄込顔類余王返妻背熱宿薬険頼覚船途許抜便留罪努精散静婚喜浮絶幸押倒等老曲払庭徒勤遅居雑招困欠更刻賛抱犯恐息遠戻願絵越欲痛笑互束似列探逃遊迷夢君閉緒折草暮酒悲晴掛到寝暗盗吸陽御歯忘雪吹娘誤洗慣礼窓昔貧怒泳祖杯疲皆鳴腹煙眠怖耳頂箱晩寒髪忙才靴恥偶偉猫幾

View File

@ -1 +0,0 @@
会同事自社発者地業方新場員立開手力問代明動京目通言理体田主題意不作用度強公持野以思家世多正安院心界教文元重近考画海売知道集別物使品計死特私始朝運終台広住真有口少町料工建空急止送切転研足究楽起着店病質待試族銀早映親験英医仕去味写字答夜音注帰古歌買悪図週室歩風紙黒花春赤青館屋色走秋夏習駅洋旅服夕借曜飲肉貸堂鳥飯勉冬昼茶弟牛魚兄犬妹姉漢

View File

@ -1 +0,0 @@
日一国人年大十二本中長出三時行見月後前生五間上東四今金九入学高円子外八六下来気小七山話女北午百書先名川千水半男西電校語土木聞食車何南万毎白天母火右読友左休父雨

View File

@ -1,178 +0,0 @@
import 'dart:convert';
import 'dart:io';
import 'package:html/parser.dart';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/api.dart';
class Radical {
final int id;
final String symbol;
final String? search_symbol;
final String meaning;
final int strokes;
const Radical({
required this.id,
required this.symbol,
required this.strokes,
required this.meaning,
this.search_symbol,
});
@override
String toString() {
return '$id - ($symbol, $strokes${search_symbol != null ? ", $search_symbol" : ""})';
}
String get sql_tuple => ' ('
'$id, '
"'$symbol', "
'$strokes, '
"'$meaning', "
"${search_symbol != null ? "'$search_symbol'" : 'NULL'}"
')';
factory Radical.fromJson(Map<String, dynamic> json) {
return Radical(
id: json['id'] as int,
symbol: json['symbol'] as String,
strokes: json['strokes'] as int,
meaning: json['meaning'] as String,
search_symbol: json['search_symbol'] as String?,
);
}
Map<String, Object?> toJson() => {
'id': id,
'symbol': symbol,
'strokes': strokes,
'meaning': meaning,
'search_symbol': search_symbol,
};
}
String hexToUnicode(String code) =>
String.fromCharCode(int.parse(code, radix: 16));
/// Some of the radicals in jisho are written using katakana,
/// and some are written using either the symbols from the
/// Kangxi radical block (U+2F00-U+2FDF) or the
/// Unified CJK Character block (U+4E00-U+9FFF). These have been
/// used without care, and therefore some of the radicals are not
/// easily searchable. This conversion table helps solve this issue.
///
/// See:
/// https://en.wikipedia.org/wiki/List_of_radicals_in_Unicode
/// https://second.wiki/wiki/unicodeblock_kangxi-radikale
/// https://wiki.contextgarden.net/List_of_Unicode_blocks
Future<Map<String, String>> fetchEquivalentUCJKIdeographs() async {
final response = await http.get(
Uri.parse(
'https://www.unicode.org/Public/UNIDATA/EquivalentUnifiedIdeograph.txt',
),
);
final Map<String, String> result = {};
for (final line in response.body.split('\n')) {
if (line.startsWith('#') || RegExp(r'^\s*$').hasMatch(line)) continue;
final items = line.split(RegExp(r'\s+'));
if (items[0].contains('.')) {
final startEnd = items[0].split('..');
final start = int.parse(startEnd[0], radix: 16);
final end = int.parse(startEnd[1], radix: 16);
for (int i = 0; i <= (end - start); i++) {
result[String.fromCharCode(start + i)] = hexToUnicode(items[2]);
}
} else {
result[hexToUnicode(items[0])] = hexToUnicode(items[2]);
}
}
return result;
}
final cacheFile = File('data/0002_radicals.json');
Future<void> cacheRadicals() async {
final Map<String, String> equivalentSymbols =
await fetchEquivalentUCJKIdeographs();
equivalentSymbols[''] = '';
equivalentSymbols[''] = '丿';
equivalentSymbols[''] = '';
equivalentSymbols[''] = '';
equivalentSymbols[''] = '';
final Map<String, List<String>> inverseEquivalentSymbols = {};
for (final entry in equivalentSymbols.entries) {
if (inverseEquivalentSymbols.containsKey(entry.value)) {
inverseEquivalentSymbols[entry.value]!.add(entry.key);
continue;
}
inverseEquivalentSymbols[entry.value] = [entry.key];
}
final response = await http.get(Uri.parse('https://jisho.org/'));
final document = parse(response.body);
final table = document.querySelector('.radical_table')!;
final List<Radical> radicals = [];
int i = 0;
for (final node in table.children) {
if (node.className == 'reset_icon_list_item') continue;
if (node.className == 'number') {
i = int.parse(node.innerHtml);
continue;
}
final String radical = node.innerHtml;
print('Caching: $radical');
KanjiResult? result;
for (final item in [
radical,
equivalentSymbols[radical],
...inverseEquivalentSymbols[radical] ?? [],
]) {
if (item == null) continue;
result = await searchForKanji(item);
if (result.found) break;
}
final Radical radicalData = Radical(
id: int.parse(node.attributes['data-radical']!),
symbol: radical,
strokes: i,
search_symbol: node.attributes['data-radk'],
meaning: ['', ''].contains(radical)
? 'katakana, jisho search radical'
: result!.data!.radical!.meaning,
);
radicals.add(radicalData);
}
assert(radicals.length == 252, '[ERROR] Missing radicals!');
final encoder = JsonEncoder.withIndent(' ');
cacheFile.writeAsStringSync(encoder.convert(radicals));
}
Future<void> main(List<String> args) async {
if (!cacheFile.existsSync()) {
await cacheRadicals();
}
List<Radical> radicals = (jsonDecode(cacheFile.readAsStringSync()) as List).map((e) => Radical.fromJson(e)).toList();
File('0002_populate_radicals.sql').writeAsStringSync(
'''
INSERT INTO Kanji_Radical(id, symbol, strokes, meaning, searchSymbol) VALUES
${radicals.map((r) => r.sql_tuple).join(',\n')};
''',
);
}

View File

@ -1,28 +0,0 @@
import 'dart:io';
// TODO: Automate download of radkfile
void main() {
final String content = File('data/radkfile_utf8').readAsStringSync();
final Iterable<String> blocks =
content.replaceAll(RegExp(r'^#.*$'), '').split(r'$').skip(2);
final List<String> tuples = [];
for (final block in blocks) {
final String radical = block[1];
final List<String> kanjiList = block
.replaceFirst(RegExp(r'.*\n'), '')
.split('')
..removeWhere((e) => e == '' || e == '\n');
for (final kanji in kanjiList) {
tuples.add(" ('$radical', '$kanji')");
}
}
File('0003_populate_radkfile.sql').writeAsStringSync(
'''
INSERT INTO RADKFILE(radical, kanji) VALUES
${tuples.join(',\n')};''',
);
}

View File

@ -1,213 +0,0 @@
// ignore_for_file: avoid_print
import 'dart:convert';
import 'dart:io';
import 'package:unofficial_jisho_api/api.dart';
Future<void> cacheData(int i) async {
final File cacheFile = File('data/jisho/grade$i.json');
final File kanjiFile = File('data/jouyou/grade$i.txt');
final List<String> kanji = [
for (final k in kanjiFile.readAsStringSync().runes) String.fromCharCode(k)
];
final List<KanjiResultData> data = [];
await Future.wait([
for (int i = 0; i < kanji.length; i++)
Future.delayed(Duration(milliseconds: 300 * i), () async {
print('$i: ${kanji[i]}');
final result = await searchForKanji(kanji[i]);
data.add(result.data!);
})
]);
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
cacheFile.writeAsStringSync(encoder.convert(data));
}
String quote(String input) => "'${input.replaceAll("'", "''")}'";
extension SQLInserts on KanjiResultData {
int? get jlptLevelNumber =>
jlptLevel != null ? int.parse(jlptLevel![1]) : null;
int? get taughtInNumber => taughtIn == null
? null
: taughtIn == 'junior high'
? 7
: int.parse(taughtIn![6]);
static String get kanjiResultCols =>
'(kanji, strokeCount, meaning, radical, jlptLevel, newspaperFrequencyRank, taughtIn, isJouyou)';
String get kanjiResultRow =>
// ignore: prefer_interpolation_to_compose_strings
'("$kanji", $strokeCount, "$meaning", "${radical!.symbol}", ' +
((jlptLevel != null) ? '$jlptLevelNumber, ' : 'NULL, ') +
((newspaperFrequencyRank != null)
? '$newspaperFrequencyRank, '
: 'NULL, ') +
((taughtIn != null) ? '$taughtInNumber, ' : 'NULL, ') +
'true'
')';
static String get yomiCols => '(yomi)';
static String get partCols => '(part)';
List<String> get onyomiRows => onyomi.map((y) => '("$y")').toList();
List<String> get kunyomiRows => kunyomi.map((y) => '("$y")').toList();
List<String> get partsRows => kunyomi.map((p) => '("$p")').toList();
static String get yomiXRefCols => '(kanji, yomi)';
static String get partXRefCols => '(kanji, part)';
List<String> get onyomiXRefRows =>
onyomi.map((y) => "('$kanji', '$y')").toList();
List<String> get kunyomiXRefRows =>
kunyomi.map((y) => "('$kanji', '$y')").toList();
List<String> get partsXRefRows =>
kunyomi.map((p) => "('$kanji', '$p')").toList();
static String get yomiExampleCols => '(example, reading, meaning)';
List<String> get onyomiExamplesRows => onyomiExamples
.map(
(y) =>
'(${quote(y.example)}, ${quote(y.reading)}, ${quote(y.meaning)})',
)
.toList();
List<String> get kunyomiExamplesRows => kunyomiExamples
.map(
(y) =>
'(${quote(y.example)}, ${quote(y.reading)}, ${quote(y.meaning)})',
)
.toList();
static String get yomiExampleXRefCols => '(exampleID, kanji)';
List<String> onyomiExamplesXRefRows(int exampleID) => [
for (int i = 0; i < onyomiExamples.length; i++)
"(${exampleID + i}, '$kanji')"
];
List<String> kunyomiExamplesXRefRows(int exampleID) => [
for (int i = 0; i < kunyomiExamples.length; i++)
"(${exampleID + i}, '$kanji')"
];
}
int exampleIDXRefCounter = 1;
List<String> generateStatements(List<KanjiResultData> kanji) {
final List<String> statements = [];
final List<String> tableKanjiResult = [];
final List<String> tableOnyomi = [];
final List<String> tableKunyomi = [];
final List<String> tablePart = [];
final List<String> tableOnyomiExamples = [];
final List<String> tableKunyomiExamples = [];
final List<String> tableOnyomiXRef = [];
final List<String> tableKunyomiXRef = [];
final List<String> tablePartXRef = [];
final List<String> tableOnyomiExamplesXRef = [];
final List<String> tableKunyomiExamplesXRef = [];
for (final k in kanji) {
tableKanjiResult.add(k.kanjiResultRow);
tableOnyomi.addAll(k.onyomiRows);
tableKunyomi.addAll(k.kunyomiRows);
tablePart.addAll(k.partsRows);
tableOnyomiExamples.addAll(k.onyomiExamplesRows);
tableKunyomiExamples.addAll(k.kunyomiExamplesRows);
tableOnyomiXRef.addAll(k.onyomiXRefRows);
tableKunyomiXRef.addAll(k.kunyomiXRefRows);
tablePartXRef.addAll(k.partsXRefRows);
}
for (final k in kanji) {
final oxr = k.onyomiExamplesXRefRows(exampleIDXRefCounter);
exampleIDXRefCounter += oxr.length;
tableOnyomiExamplesXRef.addAll(oxr);
}
for (final k in kanji) {
final kxr = k.kunyomiExamplesXRefRows(exampleIDXRefCounter);
exampleIDXRefCounter += kxr.length;
tableKunyomiExamplesXRef.addAll(kxr);
}
void insertStatement({
required String table,
required List<String> values,
orIgnore = false,
}) =>
statements.add(
'INSERT${orIgnore ? ' OR IGNORE' : ''} INTO $table VALUES\n'
'${values.join(',\n')};\n',
);
insertStatement(
table: 'Kanji_Result${SQLInserts.kanjiResultCols}',
values: tableKanjiResult,
);
for (final isOnyomi in [true, false]) {
final String name = isOnyomi ? 'Onyomi' : 'Kunyomi';
insertStatement(
table: 'Kanji_$name${SQLInserts.yomiCols}',
values: isOnyomi ? tableOnyomi : tableKunyomi,
orIgnore: true,
);
insertStatement(
table: 'Kanji_Result${name}_XRef${SQLInserts.yomiXRefCols}',
values: isOnyomi ? tableOnyomiXRef : tableKunyomiXRef,
);
insertStatement(
table: 'Kanji_YomiExample${SQLInserts.yomiExampleCols}',
values: isOnyomi ? tableOnyomiExamples : tableKunyomiExamples,
orIgnore: true,
);
insertStatement(
table: 'Kanji_Result${name}Example_XRef${SQLInserts.yomiExampleXRefCols}',
values: isOnyomi ? tableOnyomiExamplesXRef : tableKunyomiExamplesXRef,
);
}
insertStatement(
table: 'Kanji_Part${SQLInserts.partCols}',
values: tablePart,
orIgnore: true,
);
insertStatement(
table: 'Kanji_ResultPart_XRef${SQLInserts.partXRefCols}',
values: tablePartXRef,
);
return statements;
}
Future<void> main() async {
final dataDir = Directory('data/jisho');
dataDir.createSync();
final List<String> statements = [];
for (int i = 1; i <= 7; i++) {
final File cacheFile = File('data/jisho/grade$i.json');
if (!cacheFile.existsSync()) {
await cacheData(i);
}
final String content = cacheFile.readAsStringSync();
final List<KanjiResultData> kanji = (jsonDecode(content) as List)
.map((e) => KanjiResultData.fromJson(e))
.toList();
statements.addAll(generateStatements(kanji));
}
File('0004_populate_jouyou_kanji.sql')
.writeAsStringSync(statements.join('\n'));
}