diff options
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/dictionary.js | 29 | ||||
-rw-r--r-- | ext/bg/js/templates.js | 2 | ||||
-rw-r--r-- | ext/bg/js/translator.js | 8 |
3 files changed, 21 insertions, 18 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 = " <div class=\"expression\">\n <span class=\"expression-" - + container.escapeExpression(((helper = (helper = helpers.jmdictTermFrequency || (depth0 != null ? depth0.jmdictTermFrequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"jmdictTermFrequency","hash":{},"data":data}) : helper))) + + container.escapeExpression(((helper = (helper = helpers.termFrequency || (depth0 != null ? depth0.termFrequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"termFrequency","hash":{},"data":data}) : helper))) + "\">"; 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))) }); } } |