aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 14:18:57 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 14:18:57 -0400
commiteea95eb130e8c444b93353f68f417ad2390795d7 (patch)
tree91f778807f6c3de84ee0462bd8187d81a380b8c9 /ext/bg/js
parent96e4bf1735cef3881e5284ff624ed2114709af82 (diff)
Simplify score to term frequency conversion
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/translator.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index de7ebc2b..ee012d96 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -135,19 +135,12 @@ class Translator {
for (const expression of result.expressions.keys()) {
for (const reading of result.expressions.get(expression).keys()) {
const termTags = result.expressions.get(expression).get(reading);
+ const score = termTags.map(tag => tag.score).reduce((p, v) => p + v, 0);
expressions.push({
expression: expression,
reading: reading,
termTags: dictTagsSort(termTags),
- termFrequency: (score => {
- if (score > 0) {
- return 'popular';
- } else if (score < 0) {
- return 'rare';
- } else {
- return 'normal';
- }
- })(termTags.map(tag => tag.score).reduce((p, v) => p + v, 0))
+ termFrequency: Translator.scoreToTermFrequency(score)
});
}
}
@@ -470,6 +463,16 @@ class Translator {
return tagMetaList;
}
+ static scoreToTermFrequency(score) {
+ if (score > 0) {
+ return 'popular';
+ } else if (score < 0) {
+ return 'rare';
+ } else {
+ return 'normal';
+ }
+ }
+
static getNameBase(name) {
const pos = name.indexOf(':');
return (pos >= 0 ? name.substr(0, pos) : name);