basic structure for feature-merge-similar-results

This commit is contained in:
siikamiika 2017-09-29 05:41:29 +03:00
parent 9106b59af6
commit b24c705234
8 changed files with 35 additions and 14 deletions

View File

@ -29,9 +29,9 @@ async function apiTermsFind(text) {
const options = utilBackend().options;
const translator = utilBackend().translator;
const searcher = options.general.groupResults ?
translator.findTermsGrouped.bind(translator) :
translator.findTermsSplit.bind(translator);
const searcher = (options.general.resultOutputMode === 'merge') && translator.findTermsMerged.bind(translator)
|| (options.general.resultOutputMode === 'split') && translator.findTermsSplit.bind(translator)
|| (options.general.resultOutputMode === 'group') && translator.findTermsGrouped.bind(translator);
const {definitions, length} = await searcher(
text,

View File

@ -208,7 +208,7 @@ class Database {
});
}
} else {
for (const [expression, reading, tags, rules, score, glossary] of entries) {
for (const [expression, reading, tags, rules, score, glossary, sequence] of entries) {
rows.push({
expression,
reading,
@ -216,6 +216,7 @@ class Database {
rules,
score,
glossary,
sequence,
dictionary: summary.title
});
}

View File

@ -207,7 +207,8 @@ async function dictFieldFormat(field, definition, mode, options) {
const data = {
marker,
definition,
group: options.general.groupResults,
group: options.general.resultOutputMode === 'group',
merge: options.general.resultOutputMode === 'merge',
modeTermKanji: mode === 'term-kanji',
modeTermKana: mode === 'term-kana',
modeKanji: mode === 'kanji'

View File

@ -132,7 +132,7 @@ function optionsSetDefaults(options) {
enable: true,
audioSource: 'jpod101',
audioVolume: 100,
groupResults: true,
resultOutputMode: 'group',
debugInfo: false,
maxResults: 32,
showAdvanced: false,

View File

@ -22,9 +22,9 @@ async function formRead() {
const optionsNew = $.extend(true, {}, optionsOld);
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
optionsNew.general.resultOutputMode = $('#result-output-mode').val();
optionsNew.general.audioSource = $('#audio-playback-source').val();
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
optionsNew.general.groupResults = $('#group-terms-results').prop('checked');
optionsNew.general.debugInfo = $('#show-debug-info').prop('checked');
optionsNew.general.showAdvanced = $('#show-advanced-options').prop('checked');
optionsNew.general.maxResults = parseInt($('#max-displayed-results').val(), 10);
@ -124,9 +124,9 @@ async function onReady() {
const options = await optionsLoad();
$('#show-usage-guide').prop('checked', options.general.showGuide);
$('#result-output-mode').val(options.general.resultOutputMode);
$('#audio-playback-source').val(options.general.audioSource);
$('#audio-playback-volume').val(options.general.audioVolume);
$('#group-terms-results').prop('checked', options.general.groupResults);
$('#show-debug-info').prop('checked', options.general.debugInfo);
$('#show-advanced-options').prop('checked', options.general.showAdvanced);
$('#max-displayed-results').val(options.general.maxResults);

View File

@ -48,6 +48,18 @@ class Translator {
return {length, definitions: definitionsGrouped};
}
async findTermsMerged(text, dictionaries, alphanumeric) {
const titles = Object.keys(dictionaries);
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
const definitionsMerged = dictTermsGroup(definitions, dictionaries);
// for (const definition of definitionsMerged) {
// await this.buildTermFrequencies(definition, titles);
// }
return {length, definitions: definitionsMerged};
}
async findTermsSplit(text, dictionaries, alphanumeric) {
const titles = Object.keys(dictionaries);
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
@ -90,7 +102,8 @@ class Translator {
expression: definition.expression,
reading: definition.reading,
glossary: definition.glossary,
tags: dictTagsSort(tags)
tags: dictTagsSort(tags),
sequence: definition.sequence
});
}
}

View File

@ -35,10 +35,6 @@
<label><input type="checkbox" id="show-usage-guide"> Show usage guide on startup</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="group-terms-results"> Group term results</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
</div>
@ -47,6 +43,15 @@
<label><input type="checkbox" id="show-debug-info"> Show debug information</label>
</div>
<div class="form-group">
<label for="result-output-mode">Result output mode</label>
<select class="form-control" id="result-output-mode">
<option value="group">Group results by written form and reading</option>
<option value="merge">Group results by main dictionary entry ID (experimental)</option>
<option value="split">Split definitions to their own results</option>
</select>
</div>
<div class="form-group">
<label for="audio-playback-source">Audio playback source</label>
<select class="form-control" id="audio-playback-source">

View File

@ -234,7 +234,8 @@ class Display {
const params = {
definitions,
addable: options.anki.enable,
grouped: options.general.groupResults,
grouped: options.general.resultOutputMode === 'group',
merged: options.general.resultOutputMode === 'merge',
playback: options.general.audioSource !== 'disabled',
debug: options.general.debugInfo
};