22 #ifndef TESSERACT_WORDREC_LANGUAGE_MODEL_H_ 23 #define TESSERACT_WORDREC_LANGUAGE_MODEL_H_ 69 bool fixed_pitch,
float max_char_wh_ratio,
70 float rating_cert_scale);
86 int curr_col,
int curr_row,
87 BLOB_CHOICE_LIST *curr_list,
110 return 1.0f / (1.0f + exp(10.0f * cert));
112 return (-1.0f / cert);
117 if (num_problems == 0)
return 0.0f;
118 if (num_problems == 1)
return penalty;
120 static_cast<float>(num_problems-1)));
130 if (dawg_info != NULL) {
175 bool just_classified,
bool mixed_alnum,
178 ViterbiStateEntry_IT* vse_it,
206 int curr_col,
int curr_row,
218 const char *unichar,
float certainty,
float denom,
219 int curr_col,
int curr_row,
float outline_length,
230 const char *context,
int *unichar_step_len,
231 bool *found_small_prob,
float *ngram_prob);
273 float max_char_wh_ratio,
280 (parent_vse != NULL) ? parent_vse->
length : 0,
310 "Turn on/off the use of character ngram model");
312 "Maximum order of the character ngram model");
314 "Maximum number of prunable (those for which PrunablePath() is" 315 " true) entries in each viterbi list recorded in BLOB_CHOICEs");
317 "Maximum size of viterbi lists recorded in BLOB_CHOICEs");
319 "To avoid overly small denominators use this as the floor" 320 " of the probability returned by the ngram model");
322 "Average classifier score of a non-matching unichar");
324 "Use only the first UTF8 step of the given string" 325 " when computing log probabilities");
327 "Strength of the character ngram model relative to the" 328 " character classifier ");
330 "Factor to bring log-probs into the same range as ratings" 331 " when multiplied by outline length ");
333 "Words are delimited by space");
335 "Minimum length of compound words");
338 "Penalty for words not in the frequent word dictionary");
340 "Penalty for non-dictionary words");
342 "Penalty for inconsistent punctuation");
344 "Penalty for inconsistent case");
346 "Penalty for inconsistent script");
348 "Penalty for inconsistent character type");
350 "Penalty for inconsistent font");
352 "Penalty for inconsistent spacing");
356 "Use sigmoidal score for certainty");
418 #endif // TESSERACT_WORDREC_LANGUAGE_MODEL_H_ bool language_model_use_sigmoidal_certainty
bool AcceptablePath(const ViterbiStateEntry &vse)
int language_model_debug_level
DawgPositionVector beginning_active_dawgs_
Bundle together all the things pertaining to the best choice/state.
LanguageModel(const UnicityTable< FontInfo > *fontinfo_table, Dict *dict)
static const LanguageModelFlagsType kUpperCaseFlag
int prev_word_unichar_step_len_
LanguageModelDawgInfo * dawg_info
int wordrec_display_segmentations
LanguageModelNgramInfo * ngram_info
LanguageModelDawgInfo * GenerateDawgInfo(bool word_end, int curr_col, int curr_row, const BLOB_CHOICE &b, const ViterbiStateEntry *parent_vse)
AssociateStats associate_stats
double language_model_penalty_increment
int NumInconsistentPunc() const
int language_model_viterbi_list_max_size
void UpdateBestChoice(ViterbiStateEntry *vse, LMPainPoints *pain_points, WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
ParamsModel & getParamsModel()
bool AcceptableChoiceFound()
Struct to store information maintained by various language model components.
double language_model_penalty_script
double language_model_penalty_spacing
bool acceptable_choice_found_
float ComputeDenom(BLOB_CHOICE_LIST *curr_list)
double language_model_penalty_non_dict_word
LanguageModelFlagsType top_choice_flags
double language_model_penalty_punc
bool PrunablePath(const ViterbiStateEntry &vse)
#define INT_VAR_H(name, val, comment)
double language_model_ngram_rating_factor
static const LanguageModelFlagsType kSmallestRatingFlag
static const LanguageModelFlagsType kDigitFlag
ParamsModel params_model_
bool UpdateState(bool just_classified, int curr_col, int curr_row, BLOB_CHOICE_LIST *curr_list, LanguageModelState *parent_node, LMPainPoints *pain_points, WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
bool AddViterbiStateEntry(LanguageModelFlagsType top_choice_flags, float denom, bool word_end, int curr_col, int curr_row, BLOB_CHOICE *b, LanguageModelState *curr_state, ViterbiStateEntry *parent_vse, LMPainPoints *pain_points, WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
int language_model_min_compound_length
double language_model_penalty_font
float ComputeNgramCost(const char *unichar, float certainty, float denom, const char *context, int *unichar_step_len, bool *found_small_prob, float *ngram_prob)
int language_model_viterbi_list_max_num_prunable
double language_model_ngram_scale_factor
static const LanguageModelFlagsType kLowerCaseFlag
int NumInconsistentChartype() const
const UnicityTable< FontInfo > * fontinfo_table_
void InitForWord(const WERD_CHOICE *prev_word, bool fixed_pitch, float max_char_wh_ratio, float rating_cert_scale)
double language_model_penalty_chartype
LanguageModelNgramInfo * GenerateNgramInfo(const char *unichar, float certainty, float denom, int curr_col, int curr_row, float outline_length, const ViterbiStateEntry *parent_vse)
WERD_CHOICE * ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res, DANGERR *fixpt, BlamerBundle *blamer_bundle, bool *truth_path)
bool language_model_ngram_use_only_first_uft8_step
bool language_model_ngram_space_delimited_language
#define BOOL_VAR_H(name, val, comment)
int language_model_ngram_order
static const float kMaxAvgNgramCost
static void ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float features[])
bool correct_segmentation_explored_
int NumInconsistentSpaces() const
static const LanguageModelFlagsType kXhtConsistentFlag
float ComputeAdjustment(int num_problems, float penalty)
double language_model_ngram_nonmatch_score
bool language_model_ngram_on
DawgPositionVector very_beginning_active_dawgs_
void ComputeAssociateStats(int col, int row, float max_char_wh_ratio, ViterbiStateEntry *parent_vse, WERD_RES *word_res, AssociateStats *associate_stats)
float CertaintyScore(float cert)
double language_model_penalty_case
float ComputeAdjustedPathCost(ViterbiStateEntry *vse)
double language_model_ngram_small_prob
unsigned char LanguageModelFlagsType
Used for expressing various language model flags.
void SetAcceptableChoiceFound(bool val)
int NumInconsistentCase() const
bool GetTopLowerUpperDigit(BLOB_CHOICE_LIST *curr_list, BLOB_CHOICE **first_lower, BLOB_CHOICE **first_upper, BLOB_CHOICE **first_digit) const
void FillConsistencyInfo(int curr_col, bool word_end, BLOB_CHOICE *b, ViterbiStateEntry *parent_vse, WERD_RES *word_res, LMConsistencyInfo *consistency_info)
ViterbiStateEntry * GetNextParentVSE(bool just_classified, bool mixed_alnum, const BLOB_CHOICE *bc, LanguageModelFlagsType blob_choice_flags, const UNICHARSET &unicharset, WERD_RES *word_res, ViterbiStateEntry_IT *vse_it, LanguageModelFlagsType *top_choice_flags) const
#define double_VAR_H(name, val, comment)
static void ComputeStats(int col, int row, const AssociateStats *parent_stats, int parent_path_length, bool fixed_pitch, float max_char_wh_ratio, WERD_RES *word_res, bool debug, AssociateStats *stats)
double language_model_penalty_non_freq_dict_word
float ComputeConsistencyAdjustment(const LanguageModelDawgInfo *dawg_info, const LMConsistencyInfo &consistency_info)
void GenerateTopChoiceInfo(ViterbiStateEntry *new_vse, const ViterbiStateEntry *parent_vse, LanguageModelState *lms)
int SetTopParentLowerUpperDigit(LanguageModelState *parent_node) const