From f54f909701453bac563c9cb5ec75fde23e087e8e Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 19 Oct 2017 18:35:42 +0300 Subject: [PATCH] merged mode: rewrite term frequency (use score) --- ext/bg/js/dictionary.js | 29 ++++++++++++++++------------- ext/bg/js/templates.js | 2 +- ext/bg/js/translator.js | 8 ++++---- tmpl/terms.html | 2 +- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 97716e65..ee056273 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -318,21 +318,24 @@ function dictTagsSort(tags) { }); } -function dictJmdictTermTagsRare(tags) { - const rareTags = [ - 'ik', - 'iK', - 'ok', - 'oK', - 'io', - 'oik' - ]; +function dictTermTagScore(tags) { + let score = 0; + + const tagScores = { + 'ik': -5, + 'iK': -5, + 'ok': -5, + 'oK': -5, + 'io': -5, + 'oik': -5, + 'P': 10 + }; + for (const tag of tags) { - if (rareTags.includes(tag)) { - return true; - } + score += tagScores[tag] || 0; } - return false; + + return score; } function dictFieldSplit(field) { diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index d2aa1ee0..e5640394 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -313,7 +313,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"29":function(container,depth0,helpers,partials,data,blockParams,depths) { var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", buffer = "
\n "; stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper)); if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)} diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 4394e172..22c5022f 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -113,15 +113,15 @@ class Translator { expression: expression, reading: reading, termTags: dictTagsSort(tags), - jmdictTermFrequency: (tags => { - if (tags.has('P')) { + termFrequency: (score => { + if (score > 0) { return 'popular'; - } else if (dictJmdictTermTagsRare(tags)) { + } else if (score < 0) { return 'rare'; } else { return 'normal'; } - })(result.expressions.get(expression).get(reading)) + })(dictTermTagScore(result.expressions.get(expression).get(reading))) }); } } diff --git a/tmpl/terms.html b/tmpl/terms.html index c83a4b15..b5b1325d 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -45,7 +45,7 @@ {{#if merged}} {{#each expressions}}
- {{#kanjiLinks}}{{#furigana}}{{{.}}}{{/furigana}}{{/kanjiLinks}}
{{~#if ../playback~}}