Use entity data from dictionary

This commit is contained in:
Alex Yatskov 2016-08-06 23:04:03 -07:00
parent 08d92a4ddb
commit 9468797b87
2 changed files with 24 additions and 14 deletions

View File

@ -19,7 +19,7 @@
class Dictionary { class Dictionary {
constructor() { constructor() {
this.termDicts = {}; this.termDicts = {};
this.kanjiDicts = {}; this.kanjiDicts = {};
} }
@ -36,22 +36,21 @@ class Dictionary {
for (let name in this.termDicts) { for (let name in this.termDicts) {
const dict = this.termDicts[name]; const dict = this.termDicts[name];
const indexStr = dict.i[term] || null; if (!(term in dict.i)) {
if (indexStr === null) {
continue; continue;
} }
const indices = indexStr.split(' ').map(Number); const indices = dict.i[term].split(' ').map(Number);
results = results.concat( results = results.concat(
indices.map(index => { indices.map(index => {
const [e, r, t, ...g] = dict.d[index]; const [e, r, t, ...g] = dict.d[index];
const addons = []; const tags = t.split(' ');
const tags = t.split(' ');
// //
// TODO: Handle addons through data. // TODO: Handle addons through data.
// //
const addons = [];
for (let tag of tags) { for (let tag of tags) {
if (tag.startsWith('v5') && tag !== 'v5') { if (tag.startsWith('v5') && tag !== 'v5') {
addons.push('v5'); addons.push('v5');
@ -66,6 +65,7 @@ class Dictionary {
reading: r, reading: r,
glossary: g, glossary: g,
tags: tags.concat(addons), tags: tags.concat(addons),
entities: dict.e,
addons: addons addons: addons
}; };
}) })

View File

@ -168,16 +168,26 @@ class Translator {
let popular = false; let popular = false;
let tagItems = []; let tagItems = [];
for (let tag of entry.tags) { for (let tag of entry.tags) {
const tagItem = this.tags[tag]; if (entry.addons.indexOf(tag) !== -1) {
if (tagItem && entry.addons.indexOf(tag) === -1) { continue;
tagItems.push({
class: tagItem.class || 'default',
order: tagItem.order || Number.MAX_SAFE_INTEGER,
desc: tagItem.desc,
name: tag
});
} }
const tagItem = {
class: 'default',
order: Number.MAX_SAFE_INTEGER,
desc: entry.entities[tag] || '',
name: tag
};
const tagMeta = this.tags[tag];
if (tagMeta) {
for (const key in tagMeta) {
tagItem[key] = tagMeta[key] || tagItem[key];
}
}
tagItems.push(tagItem);
// //
// TODO: Handle tagging as popular through data. // TODO: Handle tagging as popular through data.
// //