Fix FP division by zero in LanguageModel::ExtractFeaturesFromPath (issue #3995)

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2023-01-19 18:15:05 +01:00
parent 1852afe9f8
commit 3bedea1bdd

View File

@ -1375,7 +1375,12 @@ void LanguageModel::ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float
// features[PTRAIN_NUM_BAD_FONT] = vse.consistency_info.inconsistent_font;
// Classifier-related features.
features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length;
if (vse.outline_length > 0.0f) {
features[PTRAIN_RATING_PER_CHAR] = vse.ratings_sum / vse.outline_length;
} else {
// Avoid FP division by 0.
features[PTRAIN_RATING_PER_CHAR] = 0.0f;
}
}
WERD_CHOICE *LanguageModel::ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res,