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 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);