diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 7a893fc0..1c2194df 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -68,10 +68,12 @@ class Database { const results = []; await this.db.terms.where('expression').equals(term).or('reading').equals(term).each(row => { if (titles.includes(row.dictionary)) { + const tags = row.tags.split('\t'); results.push({ expression: row.expression, reading: row.reading, - tags: dictFieldSplit(row.tags), + tags: dictFieldSplit(tags[0]), + termTags: tags.length > 1 ? dictFieldSplit(tags[1]) : [], rules: dictFieldSplit(row.rules), glossary: row.glossary, score: row.score, @@ -93,10 +95,12 @@ class Database { const results = []; await this.db.terms.where('sequence').equals(sequence).each(row => { if (row.dictionary === mainDictionary) { + const tags = row.tags.split('\t'); results.push({ expression: row.expression, reading: row.reading, - tags: dictFieldSplit(row.tags), + tags: dictFieldSplit(tags[0]), + termTags: tags.length > 1 ? dictFieldSplit(tags[1]) : [], rules: dictFieldSplit(row.rules), glossary: row.glossary, score: row.score, diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index b6ca6fd5..ee4f5946 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -136,6 +136,7 @@ function dictTermsGroup(definitions, dictionaries) { expression: firstDef.expression, reading: firstDef.reading, reasons: firstDef.reasons, + termTags: groupDefs[0].termTags, score: groupDefs.reduce((p, v) => v.score > p ? v.score : p, Number.MIN_SAFE_INTEGER), source: firstDef.source }); @@ -226,14 +227,16 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) { } for (const tag of definition.tags) { - if (dictIsJmdictTermTag(tag)) { - result.expressions.get(definition.expression).get(definition.reading).add(tag); - } else if (typeof tag === 'string') { + if (typeof tag === 'string') { definitionsByGloss[gloss].tags.add(tag); } else if (tag.category && tag.category !== 'dictionary') { definitionsByGloss[gloss].tags.add(tag.name); } } + + for (const tag of definition.termTags) { + result.expressions.get(definition.expression).get(definition.reading).add(tag); + } } for (const gloss in definitionsByGloss) { @@ -288,34 +291,12 @@ function dictTagsSort(tags) { }); } -function dictIsJmdictTermTag(tag) { - return [ - 'P', - 'news', - 'ichi', - 'spec', - 'gai', - 'ik', - 'iK', - 'ok', - 'oK', - 'ek', - 'eK', - 'io', - 'oik', - 'ateji', - 'gikun' - ].includes(tag); -} - function dictJmdictTermTagsRare(tags) { const rareTags = [ 'ik', 'iK', 'ok', 'oK', - 'ek', - 'eK', 'io', 'oik' ]; diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 9a576479..19c49337 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -276,11 +276,13 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + "\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(39, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(43, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.termTags : depth0),{"name":"if","hash":{},"fn":container.program(43, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.frequencies : depth0),{"name":"if","hash":{},"fn":container.program(46, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n
"; stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(25, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper)); if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} if (stack1 != null) { buffer += stack1; } return buffer + "\n"; -},"57":function(container,depth0,helpers,partials,data,blockParams,depths) { +},"60":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(58, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); -},"58":function(container,depth0,helpers,partials,data,blockParams,depths) { + return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(61, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : ""); +},"61":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; - return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(59, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(62, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"merged":(depths[1] != null ? depths[1].merged : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : ""); -},"59":function(container,depth0,helpers,partials,data) { +},"62":function(container,depth0,helpers,partials,data) { return "
No results found.
\n"; },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1; return "\n\n" - + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(57, data, 0, blockParams, depths),"inverse":container.program(61, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); + + ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(60, data, 0, blockParams, depths),"inverse":container.program(64, data, 0, blockParams, depths),"data":data})) != null ? stack1 : ""); },"main_d": function(fn, props, container, depth0, data, blockParams, depths) { var decorators = container.decorators; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 678bc613..737abd08 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -154,6 +154,7 @@ class Translator { for (const definition of deinflection.definitions) { const tags = await this.expandTags(definition.tags, definition.dictionary); tags.push(dictTagBuildSource(definition.dictionary)); + const termTags = await this.expandTags(definition.termTags, definition.dictionary); definitions.push({ source: deinflection.source, @@ -165,6 +166,7 @@ class Translator { reading: definition.reading, glossary: definition.glossary, tags: dictTagsSort(tags), + termTags: dictTagsSort(termTags), sequence: definition.sequence }); } diff --git a/tmpl/terms.html b/tmpl/terms.html index cc0f600e..72bf9824 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -80,6 +80,14 @@ {{/if}} + {{#if termTags}} +