Refactors the function to filter and transform unigrams in McBopomofoLM.

This commit is contained in:
zonble 2022-01-15 20:34:02 +08:00
parent b627e8e3b6
commit 5c0a14deeb
2 changed files with 7 additions and 4 deletions

View File

@ -136,7 +136,7 @@ void McBopomofoLM::setExternalConvrter(std::function<string(string)> externalCon
m_externalConverter = externalConverter;
}
const vector<Unigram> McBopomofoLM::filterAndTransformUnigrams(vector<Unigram> unigrams, const unordered_set<string>& excludedValues, unordered_set<string>& insertedValues)
const vector<Unigram> McBopomofoLM::filterAndTransformUnigrams(const vector<Unigram> unigrams, const unordered_set<string>& excludedValues, unordered_set<string>& insertedValues)
{
vector<Unigram> results;
@ -159,9 +159,12 @@ const vector<Unigram> McBopomofoLM::filterAndTransformUnigrams(vector<Unigram> u
string replacement = m_externalConverter(value);
value = replacement;
}
unigram.keyValue.value = value;
if (insertedValues.find(value) == insertedValues.end()) {
results.push_back(unigram);
Unigram g;
g.keyValue.value = value;
g.keyValue.key = unigram.keyValue.key;
g.score = unigram.score;
results.push_back(g);
insertedValues.insert(value);
}
}

View File

@ -55,7 +55,7 @@ public:
void setExternalConvrter(std::function<string(string)> externalConverter);
protected:
const vector<Unigram> filterAndTransformUnigrams(vector<Unigram> unigrams,
const vector<Unigram> filterAndTransformUnigrams(const vector<Unigram> unigrams,
const std::unordered_set<string>& excludedValues,
std::unordered_set<string>& insertedValues);