Renaming things

This commit is contained in:
Alex Yatskov 2016-11-07 08:29:21 -08:00
parent c11b24cb37
commit a18f3be559
4 changed files with 18 additions and 18 deletions

View File

@ -9,7 +9,7 @@
<script src="js/ankinull.js"></script>
<script src="js/templates.js"></script>
<script src="js/util.js"></script>
<script src="js/dictionary.js"></script>
<script src="js/database.js"></script>
<script src="js/deinflector.js"></script>
<script src="js/translator.js"></script>
<script src="js/options.js"></script>

View File

@ -17,14 +17,14 @@
*/
class Dictionary {
class Database {
constructor() {
this.db = null;
this.dbVer = 6;
this.entities = null;
}
initDb() {
init() {
if (this.db !== null) {
return Promise.reject('database already initialized');
}
@ -39,8 +39,8 @@ class Dictionary {
});
}
prepareDb() {
this.initDb();
prepare() {
this.init();
return this.db.meta.get('version').then(row => {
return row ? row.value : 0;
@ -56,13 +56,13 @@ class Dictionary {
this.db = null;
return db.delete().then(() => {
this.initDb();
this.init();
return false;
});
});
}
sealDb() {
seal() {
if (this.db === null) {
return Promise.reject('database not initialized');
}

View File

@ -166,7 +166,7 @@ function populateDictionaries(opts) {
const container = $('.dicts');
container.empty();
yomichan().translator.dictionary.getDictionaries().then(rows => {
yomichan().translator.database.getDictionaries().then(rows => {
rows.forEach(row => {
const dictOpts = opts.dictionaries[row.title] || {enableTerms: true, enableKanji: false};
const html = Handlebars.templates['dictionary.html']({
@ -184,7 +184,7 @@ function populateDictionaries(opts) {
$('.dict-delete').click(e => {
const dict = $(e.target).closest('.dict');
const title = dict.data('title');
yomichan().translator.dictionary.deleteDictionary(title);
yomichan().translator.database.deleteDictionary(title);
dict.slideUp();
});

View File

@ -21,7 +21,7 @@ class Translator {
constructor() {
this.loaded = false;
this.tagMeta = null;
this.dictionary = new Dictionary();
this.database = new Database();
this.deinflector = new Deinflector();
}
@ -35,7 +35,7 @@ class Translator {
return loadJson('bg/data/tags.json');
}).then(tagMeta => {
this.tagMeta = tagMeta;
return this.dictionary.prepareDb();
return this.database.prepare();
}).then(exists => {
if (exists) {
return;
@ -62,11 +62,11 @@ class Translator {
};
return Promise.all([
this.dictionary.importDictionary('bg/data/edict/index.json', bankCallback),
this.dictionary.importDictionary('bg/data/enamdict/index.json', bankCallback),
this.dictionary.importDictionary('bg/data/kanjidic/index.json', bankCallback),
this.database.importDictionary('bg/data/edict/index.json', bankCallback),
this.database.importDictionary('bg/data/enamdict/index.json', bankCallback),
this.database.importDictionary('bg/data/kanjidic/index.json', bankCallback),
]).then(() => {
return this.dictionary.sealDb();
return this.database.seal();
}).then(() => {
if (callback) {
callback({state: 'end', progress: 100.0});
@ -84,7 +84,7 @@ class Translator {
for (let i = text.length; i > 0; --i) {
deinflectPromises.push(
this.deinflector.deinflect(text.slice(0, i), term => {
return this.dictionary.findTerm(term).then(definitions => definitions.map(definition => definition.tags));
return this.database.findTerm(term).then(definitions => definitions.map(definition => definition.tags));
}).then(deinflects => {
const processPromises = [];
for (const deinflect of deinflects) {
@ -143,7 +143,7 @@ class Translator {
for (const c of text) {
if (!processed[c]) {
promises.push(this.dictionary.findKanji(c).then((definitions) => definitions));
promises.push(this.database.findKanji(c).then((definitions) => definitions));
processed[c] = true;
}
}
@ -152,7 +152,7 @@ class Translator {
}
processTerm(groups, source, tags, rules, root) {
return this.dictionary.findTerm(root).then(definitions => {
return this.database.findTerm(root).then(definitions => {
for (const definition of definitions) {
if (definition.id in groups) {
continue;