add compact tags
This commit is contained in:
parent
6523b77ca1
commit
8d660e2829
@ -110,6 +110,32 @@ function dictTermsUndupe(definitions) {
|
|||||||
return definitionsUnique;
|
return definitionsUnique;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dictTermsCompressTags(definitions) {
|
||||||
|
let lastDictionary = '';
|
||||||
|
let lastPos = '';
|
||||||
|
|
||||||
|
for (const definition of definitions) {
|
||||||
|
const dictionary = JSON.stringify(definition.tags.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 filterOutCategories = [];
|
||||||
|
|
||||||
|
if (lastDictionary === dictionary) {
|
||||||
|
filterOutCategories.push('dictionary');
|
||||||
|
} else {
|
||||||
|
lastDictionary = dictionary;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastPos === pos) {
|
||||||
|
filterOutCategories.push('pos');
|
||||||
|
} else {
|
||||||
|
lastPos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
definition.tags = definition.tags.filter(tag => !filterOutCategories.includes(tag.category));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function dictTermsGroup(definitions, dictionaries) {
|
function dictTermsGroup(definitions, dictionaries) {
|
||||||
const groups = {};
|
const groups = {};
|
||||||
for (const definition of definitions) {
|
for (const definition of definitions) {
|
||||||
|
@ -139,7 +139,8 @@ function optionsSetDefaults(options) {
|
|||||||
popupWidth: 400,
|
popupWidth: 400,
|
||||||
popupHeight: 250,
|
popupHeight: 250,
|
||||||
popupOffset: 10,
|
popupOffset: 10,
|
||||||
showGuide: true
|
showGuide: true,
|
||||||
|
compactTags: false
|
||||||
},
|
},
|
||||||
|
|
||||||
scanning: {
|
scanning: {
|
||||||
|
@ -22,6 +22,7 @@ async function formRead() {
|
|||||||
const optionsNew = $.extend(true, {}, optionsOld);
|
const optionsNew = $.extend(true, {}, optionsOld);
|
||||||
|
|
||||||
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
|
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
|
||||||
|
optionsNew.general.compactTags = $('#compact-tags').prop('checked');
|
||||||
optionsNew.general.resultOutputMode = $('#result-output-mode').val();
|
optionsNew.general.resultOutputMode = $('#result-output-mode').val();
|
||||||
optionsNew.general.audioSource = $('#audio-playback-source').val();
|
optionsNew.general.audioSource = $('#audio-playback-source').val();
|
||||||
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
|
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
|
||||||
@ -125,6 +126,7 @@ async function onReady() {
|
|||||||
const options = await optionsLoad();
|
const options = await optionsLoad();
|
||||||
|
|
||||||
$('#show-usage-guide').prop('checked', options.general.showGuide);
|
$('#show-usage-guide').prop('checked', options.general.showGuide);
|
||||||
|
$('#compact-tags').prop('checked', options.general.compactTags);
|
||||||
$('#result-output-mode').val(options.general.resultOutputMode);
|
$('#result-output-mode').val(options.general.resultOutputMode);
|
||||||
$('#audio-playback-source').val(options.general.audioSource);
|
$('#audio-playback-source').val(options.general.audioSource);
|
||||||
$('#audio-playback-volume').val(options.general.audioVolume);
|
$('#audio-playback-volume').val(options.general.audioVolume);
|
||||||
|
@ -206,30 +206,16 @@ 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.only : 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.tags : 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.tags : depth0),{"name":"if","hash":{},"fn":container.program(6, 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 ("
|
|
||||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.only : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
|
||||||
+ " only)\n</div>\n";
|
|
||||||
},"3":function(container,depth0,helpers,partials,data) {
|
|
||||||
var stack1;
|
|
||||||
|
|
||||||
return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "")
|
|
||||||
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
|
||||||
+ "\n";
|
|
||||||
},"4":function(container,depth0,helpers,partials,data) {
|
|
||||||
return ", ";
|
|
||||||
},"6":function(container,depth0,helpers,partials,data) {
|
|
||||||
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(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
+ ((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 : "")
|
||||||
+ "</div>\n";
|
+ "</div>\n";
|
||||||
},"7":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;
|
||||||
|
|
||||||
return " <span class=\"label label-default tag-"
|
return " <span class=\"label label-default tag-"
|
||||||
@ -239,6 +225,20 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
|
|||||||
+ "\">"
|
+ "\">"
|
||||||
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
|
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
|
||||||
+ "</span>\n";
|
+ "</span>\n";
|
||||||
|
},"5":function(container,depth0,helpers,partials,data) {
|
||||||
|
var stack1;
|
||||||
|
|
||||||
|
return "<div>\n ("
|
||||||
|
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.only : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||||
|
+ " only)\n</div>\n";
|
||||||
|
},"6":function(container,depth0,helpers,partials,data) {
|
||||||
|
var stack1;
|
||||||
|
|
||||||
|
return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "")
|
||||||
|
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||||
|
+ "\n";
|
||||||
|
},"7":function(container,depth0,helpers,partials,data) {
|
||||||
|
return ", ";
|
||||||
},"9":function(container,depth0,helpers,partials,data) {
|
},"9":function(container,depth0,helpers,partials,data) {
|
||||||
var stack1;
|
var stack1;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findTermsGrouped(text, dictionaries, alphanumeric) {
|
async findTermsGrouped(text, dictionaries, alphanumeric) {
|
||||||
|
const options = await apiOptionsGet();
|
||||||
const titles = Object.keys(dictionaries);
|
const titles = Object.keys(dictionaries);
|
||||||
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
|
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
|
||||||
|
|
||||||
@ -45,6 +46,12 @@ class Translator {
|
|||||||
await this.buildTermFrequencies(definition, titles);
|
await this.buildTermFrequencies(definition, titles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.general.compactTags) {
|
||||||
|
for (const definition of definitionsGrouped) {
|
||||||
|
dictTermsCompressTags(definition.definitions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {length, definitions: definitionsGrouped};
|
return {length, definitions: definitionsGrouped};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +127,12 @@ class Translator {
|
|||||||
await this.buildTermFrequencies(definition, titles);
|
await this.buildTermFrequencies(definition, titles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.general.compactTags) {
|
||||||
|
for (const definition of definitionsMerged) {
|
||||||
|
dictTermsCompressTags(definition.definitions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {length, definitions: dictTermsSort(definitionsMerged)};
|
return {length, definitions: dictTermsSort(definitionsMerged)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,10 @@
|
|||||||
<label><input type="checkbox" id="show-usage-guide"> Show usage guide on startup</label>
|
<label><input type="checkbox" id="show-usage-guide"> Show usage guide on startup</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="checkbox">
|
||||||
|
<label><input type="checkbox" id="compact-tags"> Compact tags</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
|
<label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
{{#*inline "definition"}}
|
{{#*inline "definition"}}
|
||||||
|
{{#if tags}}
|
||||||
|
<div>
|
||||||
|
{{#each tags}}
|
||||||
|
<span class="label label-default tag-{{category}}" title="{{notes}}">{{name}}</span>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
{{#if only}}
|
{{#if only}}
|
||||||
<div>
|
<div>
|
||||||
(
|
(
|
||||||
@ -8,13 +15,6 @@
|
|||||||
only)
|
only)
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if tags}}
|
|
||||||
<div>
|
|
||||||
{{#each tags}}
|
|
||||||
<span class="label label-default tag-{{category}}" title="{{notes}}">{{name}}</span>
|
|
||||||
{{/each}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
{{#if glossary.[1]}}
|
{{#if glossary.[1]}}
|
||||||
<ul>
|
<ul>
|
||||||
{{#each glossary}}
|
{{#each glossary}}
|
||||||
|
Loading…
Reference in New Issue
Block a user