Simplify score to term frequency conversion

This commit is contained in:
toasted-nutbread 2019-10-19 14:18:57 -04:00
parent 96e4bf1735
commit eea95eb130

View File

@ -135,19 +135,12 @@ class Translator {
for (const expression of result.expressions.keys()) { for (const expression of result.expressions.keys()) {
for (const reading of result.expressions.get(expression).keys()) { for (const reading of result.expressions.get(expression).keys()) {
const termTags = result.expressions.get(expression).get(reading); const termTags = result.expressions.get(expression).get(reading);
const score = termTags.map(tag => tag.score).reduce((p, v) => p + v, 0);
expressions.push({ expressions.push({
expression: expression, expression: expression,
reading: reading, reading: reading,
termTags: dictTagsSort(termTags), termTags: dictTagsSort(termTags),
termFrequency: (score => { termFrequency: Translator.scoreToTermFrequency(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))
}); });
} }
} }
@ -470,6 +463,16 @@ class Translator {
return tagMetaList; return tagMetaList;
} }
static scoreToTermFrequency(score) {
if (score > 0) {
return 'popular';
} else if (score < 0) {
return 'rare';
} else {
return 'normal';
}
}
static getNameBase(name) { static getNameBase(name) {
const pos = name.indexOf(':'); const pos = name.indexOf(':');
return (pos >= 0 ? name.substr(0, pos) : name); return (pos >= 0 ? name.substr(0, pos) : name);