summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2017-10-19 18:35:42 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2017-10-19 18:35:42 +0300
commitf54f909701453bac563c9cb5ec75fde23e087e8e (patch)
tree856e4253b6fc51a2df8421a5c69fe84b36f53092
parent04def645214b4c0ae2833f5ea7d9c3274192aa09 (diff)
merged mode: rewrite term frequency (use score)
-rw-r--r--ext/bg/js/dictionary.js29
-rw-r--r--ext/bg/js/templates.js2
-rw-r--r--ext/bg/js/translator.js8
-rw-r--r--tmpl/terms.html2
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 =
" <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)))
});
}
}
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}}
<div class="expression">
- <span class="expression-{{jmdictTermFrequency}}">{{#kanjiLinks}}{{#furigana}}{{{.}}}{{/furigana}}{{/kanjiLinks}}</span><!--
+ <span class="expression-{{termFrequency}}">{{#kanjiLinks}}{{#furigana}}{{{.}}}{{/furigana}}{{/kanjiLinks}}</span><!--
--><div class="peek-wrapper">
{{~#if ../playback~}}
<a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio" alt></a>