diff options
| author | Alex Yatskov <alex@foosoft.net> | 2017-09-12 20:20:03 -0700 | 
|---|---|---|
| committer | Alex Yatskov <alex@foosoft.net> | 2017-09-12 20:20:03 -0700 | 
| commit | 79b99131f69ab778e4c8203caa0894e8accde436 (patch) | |
| tree | 9e2f1870e16b6a6f67add91347bc113b50fe3b97 /ext/bg/js | |
| parent | 3b29893072b89b75c7fd82b9138b09572ec6248c (diff) | |
add frequency table support for kanji
Diffstat (limited to 'ext/bg/js')
| -rw-r--r-- | ext/bg/js/database.js | 42 | ||||
| -rw-r--r-- | ext/bg/js/settings.js | 4 | ||||
| -rw-r--r-- | ext/bg/js/translator.js | 1 | 
3 files changed, 41 insertions, 6 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          );      } diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 55b469d0..b5ac8c8b 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -82,7 +82,9 @@ function formUpdateVisibility(options) {      const debug = $('#debug');      if (options.general.debugInfo) { -        const text = JSON.stringify(options, null, 4); +        const temp = utilIsolate(options); +        temp.anki.fieldTemplates = '...'; +        const text = JSON.stringify(temp, null, 4);          debug.html(handlebarsEscape(text));          debug.show();      } else { diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 3b9a1128..1e79b6fc 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -127,6 +127,7 @@ class Translator {              const tags = definition.tags.map(tag => dictTagBuild(tag, definition.tagMeta));              tags.push(dictTagBuildSource(definition.dictionary));              definition.tags = dictTagsSort(tags); +            definition.frequencies = await this.database.findKanjiFreq(definition.character, titles);          }          return definitions; |