summaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-12 20:20:03 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-12 20:20:03 -0700
commit79b99131f69ab778e4c8203caa0894e8accde436 (patch)
tree9e2f1870e16b6a6f67add91347bc113b50fe3b97 /ext/bg/js/database.js
parent3b29893072b89b75c7fd82b9138b09572ec6248c (diff)
add frequency table support for kanji
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js42
1 files changed, 37 insertions, 5 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index ea55416c..1760a70a 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -129,6 +129,21 @@ class Database {
return results;
}
+ async findKanjiFreq(kanji, titles) {
+ if (!this.db) {
+ throw 'database not initialized';
+ }
+
+ const results = [];
+ await this.db.kanjiFreq.where('character').equals(kanji).each(row => {
+ if (titles.includes(row.dictionary)) {
+ results.push({frequency: row.frequency, dictionary: row.dictionary});
+ }
+ });
+
+ return results;
+ }
+
async cacheTagMeta(titles) {
if (!this.db) {
throw 'database not initialized';
@@ -186,7 +201,7 @@ class Database {
});
}
- await this.db.terms.bulkAdd(utilIsolate(rows));
+ await this.db.terms.bulkAdd(rows);
};
const termFreqDataLoaded = async (title, entries, total, current) => {
@@ -203,7 +218,7 @@ class Database {
});
}
- await this.db.termFreq.bulkAdd(utilIsolate(rows));
+ await this.db.termFreq.bulkAdd(rows);
};
const kanjiDataLoaded = async (title, entries, total, current) => {
@@ -223,7 +238,24 @@ class Database {
});
}
- await this.db.kanji.bulkAdd(utilIsolate(rows));
+ await this.db.kanji.bulkAdd(rows);
+ };
+
+ const kanjiFreqDataLoaded = async (title, entries, total, current) => {
+ if (callback) {
+ callback(total, current);
+ }
+
+ const rows = [];
+ for (const [character, frequency] of entries) {
+ rows.push({
+ character,
+ frequency,
+ dictionary: title
+ });
+ }
+
+ await this.db.kanjiFreq.bulkAdd(rows);
};
const tagDataLoaded = async (title, entries, total, current) => {
@@ -244,7 +276,7 @@ class Database {
rows.push(row);
}
- await this.db.tagMeta.bulkAdd(utilIsolate(rows));
+ await this.db.tagMeta.bulkAdd(rows);
};
return await Database.importDictionaryZip(
@@ -253,7 +285,7 @@ class Database {
termDataLoaded,
termFreqDataLoaded,
kanjiDataLoaded,
- null,
+ kanjiFreqDataLoaded,
tagDataLoaded
);
}