change db format, rename tags to definitionTags

This commit is contained in:
siikamiika 2017-10-13 02:40:20 +03:00
parent c0f56480bb
commit 7ec28bea54
5 changed files with 25 additions and 26 deletions

View File

@ -68,12 +68,11 @@ class Database {
const results = []; const results = [];
await this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => { await this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => {
if (titles.includes(row.dictionary)) { if (titles.includes(row.dictionary)) {
const tags = row.tags.split('\t');
results.push({ results.push({
expression: row.expression, expression: row.expression,
reading: row.reading, reading: row.reading,
tags: dictFieldSplit(tags[0]), definitionTags: dictFieldSplit(row.definitionTags),
termTags: tags.length > 1 ? dictFieldSplit(tags[1]) : [], termTags: dictFieldSplit(row.termTags || ''),
rules: dictFieldSplit(row.rules), rules: dictFieldSplit(row.rules),
glossary: row.glossary, glossary: row.glossary,
score: row.score, score: row.score,
@ -95,12 +94,11 @@ class Database {
const results = []; const results = [];
await this.db.terms.where('sequence').equals(sequence).each(row => { await this.db.terms.where('sequence').equals(sequence).each(row => {
if (row.dictionary === mainDictionary) { if (row.dictionary === mainDictionary) {
const tags = row.tags.split('\t');
results.push({ results.push({
expression: row.expression, expression: row.expression,
reading: row.reading, reading: row.reading,
tags: dictFieldSplit(tags[0]), definitionTags: dictFieldSplit(row.definitionTags),
termTags: tags.length > 1 ? dictFieldSplit(tags[1]) : [], termTags: dictFieldSplit(row.termTags || ''),
rules: dictFieldSplit(row.rules), rules: dictFieldSplit(row.rules),
glossary: row.glossary, glossary: row.glossary,
score: row.score, score: row.score,
@ -229,11 +227,11 @@ class Database {
const rows = []; const rows = [];
if (summary.version === 1) { if (summary.version === 1) {
for (const [expression, reading, tags, rules, score, ...glossary] of entries) { for (const [expression, reading, definitionTags, rules, score, ...glossary] of entries) {
rows.push({ rows.push({
expression, expression,
reading, reading,
tags, definitionTags,
rules, rules,
score, score,
glossary, glossary,
@ -241,15 +239,16 @@ class Database {
}); });
} }
} else { } else {
for (const [expression, reading, tags, rules, score, glossary, sequence] of entries) { for (const [expression, reading, definitionTags, rules, score, glossary, sequence, termTags] of entries) {
rows.push({ rows.push({
expression, expression,
reading, reading,
tags, definitionTags,
rules, rules,
score, score,
glossary, glossary,
sequence, sequence,
termTags,
dictionary: summary.title dictionary: summary.title
}); });
} }

View File

@ -115,8 +115,8 @@ function dictTermsCompressTags(definitions) {
let lastPos = ''; let lastPos = '';
for (const definition of definitions) { for (const definition of definitions) {
const dictionary = JSON.stringify(definition.tags.filter(tag => tag.category === 'dictionary').map(tag => tag.name).sort()); const dictionary = JSON.stringify(definition.definitionTags.filter(tag => tag.category === 'dictionary').map(tag => tag.name).sort());
const pos = JSON.stringify(definition.tags.filter(tag => tag.category === 'pos').map(tag => tag.name).sort()); const pos = JSON.stringify(definition.definitionTags.filter(tag => tag.category === 'pos').map(tag => tag.name).sort());
const filterOutCategories = []; const filterOutCategories = [];
@ -133,7 +133,7 @@ function dictTermsCompressTags(definitions) {
lastPos = pos; lastPos = pos;
} }
definition.tags = definition.tags.filter(tag => !filterOutCategories.includes(tag.category)); definition.definitionTags = definition.definitionTags.filter(tag => !filterOutCategories.includes(tag.category));
} }
} }
@ -229,7 +229,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
definitionsByGloss[gloss] = { definitionsByGloss[gloss] = {
expression: new Set(), expression: new Set(),
reading: new Set(), reading: new Set(),
tags: new Set(), definitionTags: new Set(),
glossary: definition.glossary, glossary: definition.glossary,
source: result.source, source: result.source,
reasons: [], reasons: [],
@ -253,11 +253,11 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
result.expressions.get(definition.expression).set(definition.reading, new Set()); result.expressions.get(definition.expression).set(definition.reading, new Set());
} }
for (const tag of definition.tags) { for (const tag of definition.definitionTags) {
if (typeof tag === 'string') { if (typeof tag === 'string') {
definitionsByGloss[gloss].tags.add(tag); definitionsByGloss[gloss].definitionTags.add(tag);
} else if (tag.category && tag.category !== 'dictionary') { } else if (tag.category && tag.category !== 'dictionary') {
definitionsByGloss[gloss].tags.add(tag.name); definitionsByGloss[gloss].definitionTags.add(tag.name);
} }
} }

View File

@ -206,14 +206,14 @@ templates['model.html'] = template({"1":function(container,depth0,helpers,partia
templates['terms.html'] = template({"1":function(container,depth0,helpers,partials,data) { templates['terms.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {});
return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.definitionTags : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.only : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.only : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : ""); + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : "");
},"2":function(container,depth0,helpers,partials,data) { },"2":function(container,depth0,helpers,partials,data) {
var stack1; var stack1;
return "<div>\n" return "<div>\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitionTags : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "</div>\n"; + "</div>\n";
},"3":function(container,depth0,helpers,partials,data) { },"3":function(container,depth0,helpers,partials,data) {
var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;

View File

@ -79,9 +79,9 @@ class Translator {
for (const gloss in definitionsByGloss) { for (const gloss in definitionsByGloss) {
const definition = definitionsByGloss[gloss]; const definition = definitionsByGloss[gloss];
const tags = await this.expandTags(definition.tags, definition.dictionary); const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary)); tags.push(dictTagBuildSource(definition.dictionary));
definition.tags = dictTagsSort(tags); definition.definitionTags = dictTagsSort(tags);
result.definitions.push(definition); result.definitions.push(definition);
} }
@ -166,8 +166,8 @@ class Translator {
let definitions = []; let definitions = [];
for (const deinflection of deinflections) { for (const deinflection of deinflections) {
for (const definition of deinflection.definitions) { for (const definition of deinflection.definitions) {
const tags = await this.expandTags(definition.tags, definition.dictionary); const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
tags.push(dictTagBuildSource(definition.dictionary)); definitionTags.push(dictTagBuildSource(definition.dictionary));
const termTags = await this.expandTags(definition.termTags, definition.dictionary); const termTags = await this.expandTags(definition.termTags, definition.dictionary);
definitions.push({ definitions.push({
@ -179,7 +179,7 @@ class Translator {
expression: definition.expression, expression: definition.expression,
reading: definition.reading, reading: definition.reading,
glossary: definition.glossary, glossary: definition.glossary,
tags: dictTagsSort(tags), definitionTags: dictTagsSort(definitionTags),
termTags: dictTagsSort(termTags), termTags: dictTagsSort(termTags),
sequence: definition.sequence sequence: definition.sequence
}); });

View File

@ -1,7 +1,7 @@
{{#*inline "definition"}} {{#*inline "definition"}}
{{#if tags}} {{#if definitionTags}}
<div> <div>
{{#each tags}} {{#each definitionTags}}
<span class="label label-default tag-{{category}}" title="{{notes}}">{{name}}</span> <span class="label label-default tag-{{category}}" title="{{notes}}">{{name}}</span>
{{/each}} {{/each}}
</div> </div>