35 #if defined(_MSC_VER) || defined(ANDROID)
36 double log2(
double n) {
37 return log(n) / log(2.0);
47 :
INT_MEMBER(language_model_debug_level, 0,
"Language model debug level",
48 dict->getCCUtil()->params()),
50 "Turn on/off the use of character ngram model",
51 dict->getCCUtil()->params()),
53 "Maximum order of the character ngram model",
54 dict->getCCUtil()->params()),
55 INT_MEMBER(language_model_viterbi_list_max_num_prunable, 10,
56 "Maximum number of prunable (those for which"
57 " PrunablePath() is true) entries in each viterbi list"
58 " recorded in BLOB_CHOICEs",
59 dict->getCCUtil()->params()),
60 INT_MEMBER(language_model_viterbi_list_max_size, 500,
61 "Maximum size of viterbi lists recorded in BLOB_CHOICEs",
62 dict->getCCUtil()->params()),
64 "To avoid overly small denominators use this as the "
65 "floor of the probability returned by the ngram model.",
66 dict->getCCUtil()->params()),
68 "Average classifier score of a non-matching unichar.",
69 dict->getCCUtil()->params()),
70 BOOL_MEMBER(language_model_ngram_use_only_first_uft8_step, false,
71 "Use only the first UTF8 step of the given string"
72 " when computing log probabilities.",
73 dict->getCCUtil()->params()),
75 "Strength of the character ngram model relative to the"
76 " character classifier ",
77 dict->getCCUtil()->params()),
79 "Factor to bring log-probs into the same range as ratings"
80 " when multiplied by outline length ",
81 dict->getCCUtil()->params()),
82 BOOL_MEMBER(language_model_ngram_space_delimited_language, true,
83 "Words are delimited by space",
84 dict->getCCUtil()->params()),
85 INT_MEMBER(language_model_min_compound_length, 3,
86 "Minimum length of compound words",
87 dict->getCCUtil()->params()),
89 "Penalty for words not in the frequent word dictionary",
90 dict->getCCUtil()->params()),
92 "Penalty for non-dictionary words",
93 dict->getCCUtil()->params()),
95 "Penalty for inconsistent punctuation",
96 dict->getCCUtil()->params()),
98 "Penalty for inconsistent case",
99 dict->getCCUtil()->params()),
101 "Penalty for inconsistent script",
102 dict->getCCUtil()->params()),
104 "Penalty for inconsistent character type",
105 dict->getCCUtil()->params()),
109 "Penalty for inconsistent font",
110 dict->getCCUtil()->params()),
112 "Penalty for inconsistent spacing",
113 dict->getCCUtil()->params()),
116 dict->getCCUtil()->params()),
117 INT_MEMBER(wordrec_display_segmentations, 0,
"Display Segmentations",
118 dict->getCCUtil()->params()),
120 "Use sigmoidal score for certainty",
121 dict->getCCUtil()->params()),
122 fontinfo_table_(fontinfo_table), dict_(dict),
123 fixed_pitch_(false), max_char_wh_ratio_(0.0),
124 acceptable_choice_found_(false) {
139 bool fixed_pitch,
float max_char_wh_ratio,
140 float rating_cert_scale) {
178 static void ScanParentsForCaseMix(
const UNICHARSET& unicharset,
180 if (parent_node ==
NULL)
return;
182 for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
189 if (other_case == unichar_id)
continue;
195 for (vit2.mark_cycle_pt(); !vit2.cycled_list() &&
196 vit2.data()->curr_b->unichar_id() != other_case;
198 if (!vit2.cycled_list()) {
209 static bool HasBetterCaseVariant(
const UNICHARSET& unicharset,
211 BLOB_CHOICE_LIST* choices) {
214 if (other_case == choice_id || other_case == INVALID_UNICHAR_ID)
218 BLOB_CHOICE_IT bc_it(choices);
219 for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) {
221 if (better_choice->
unichar_id() == other_case)
223 else if (better_choice == choice)
256 bool just_classified,
257 int curr_col,
int curr_row,
258 BLOB_CHOICE_LIST *curr_list,
265 tprintf(
"\nUpdateState: col=%d row=%d %s",
266 curr_col, curr_row, just_classified ?
"just_classified" :
"");
268 tprintf(
"(parent=%p)\n", parent_node);
274 bool new_changed =
false;
280 bool has_alnum_mix =
false;
281 if (parent_node !=
NULL) {
285 tprintf(
"No parents found to process\n");
289 has_alnum_mix =
true;
293 has_alnum_mix =
false;;
294 ScanParentsForCaseMix(unicharset, parent_node);
296 parent_node->
Print(
"Parent viterbi list");
301 ViterbiStateEntry_IT vit;
302 BLOB_CHOICE_IT c_it(curr_list);
303 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
315 if (c_it.at_first() || !new_changed)
319 if (first_digit == choice) blob_choice_flags |=
kDigitFlag;
321 if (parent_node ==
NULL) {
333 if (HasBetterCaseVariant(unicharset, choice, curr_list))
339 blob_choice_flags, denom, word_end, curr_col, curr_row,
340 choice, curr_state,
NULL, pain_points,
341 word_res, best_choice_bundle, blamer_bundle);
350 c_it.data(), blob_choice_flags,
351 unicharset, word_res, &vit,
352 &top_choice_flags)) !=
NULL) {
365 HasBetterCaseVariant(unicharset, choice, curr_list))
370 top_choice_flags, denom, word_end, curr_col, curr_row,
371 c_it.data(), curr_state, parent_vse, pain_points,
372 word_res, best_choice_bundle, blamer_bundle);
389 BLOB_CHOICE_IT c_it(curr_list);
392 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
393 UNICHAR_ID unichar_id = c_it.data()->unichar_id();
395 if (first_unichar ==
NULL) first_unichar = c_it.data();
397 *first_lower = c_it.data();
401 *first_upper = c_it.data();
404 *first_digit = c_it.data();
408 bool mixed = (*first_lower !=
NULL || *first_upper !=
NULL) &&
409 *first_digit !=
NULL;
410 if (*first_lower ==
NULL) *first_lower = first_unichar;
411 if (*first_upper ==
NULL) *first_upper = first_unichar;
412 if (*first_digit ==
NULL) *first_digit = first_unichar;
427 if (parent_node ==
NULL)
return -1;
433 float lower_rating = 0.0f;
434 float upper_rating = 0.0f;
435 float digit_rating = 0.0f;
436 float top_rating = 0.0f;
439 for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
446 while (unichar_id == INVALID_UNICHAR_ID &&
452 if (unichar_id != INVALID_UNICHAR_ID) {
454 if (top_lower ==
NULL || lower_rating > rating) {
456 lower_rating = rating;
459 if (top_upper ==
NULL || upper_rating > rating) {
461 upper_rating = rating;
464 if (top_digit ==
NULL || digit_rating > rating) {
466 digit_rating = rating;
470 if (top_choice ==
NULL || top_rating > rating) {
476 if (top_choice ==
NULL)
return -1;
479 if (top_lower ==
NULL) top_lower = top_choice;
481 if (top_upper ==
NULL) top_upper = top_choice;
483 if (top_digit ==
NULL) top_digit = top_choice;
494 return mixed ? 1 : 0;
503 bool just_classified,
bool mixed_alnum,
const BLOB_CHOICE* bc,
505 WERD_RES* word_res, ViterbiStateEntry_IT* vse_it,
507 for (; !vse_it->cycled_list(); vse_it->forward()) {
511 if (!just_classified && !parent_vse->
updated)
continue;
513 parent_vse->
Print(
"Considering");
515 *top_choice_flags = blob_choice_flags;
528 (mixed_alnum || *top_choice_flags == 0))
534 (mixed_alnum || *top_choice_flags == 0))
543 tprintf(
"Parent %s has competition %s\n",
567 int curr_col,
int curr_row,
575 ViterbiStateEntry_IT vit;
577 tprintf(
"AddViterbiStateEntry for unichar %s rating=%.4f"
578 " certainty=%.4f top_choice_flags=0x%x",
582 tprintf(
" parent_vse=%p\n", parent_vse);
587 if (curr_state !=
NULL &&
591 tprintf(
"AddViterbiStateEntry: viterbi list is full!\n");
600 float outline_length =
607 denom, curr_col, curr_row, outline_length, parent_vse);
610 bool liked_by_language_model = dawg_info !=
NULL ||
614 if (!liked_by_language_model && top_choice_flags == 0) {
616 tprintf(
"Language model components very early pruned this entry\n");
637 if (!liked_by_language_model && top_choice_flags == 0) {
639 tprintf(
"Language model components early pruned this entry\n");
648 word_res, &consistency_info);
649 if (dawg_info != NULL && consistency_info.
invalid_punc) {
656 parent_vse, word_res, &associate_stats);
657 if (parent_vse != NULL) {
664 parent_vse, b, 0.0, outline_length,
665 consistency_info, associate_stats, top_choice_flags, dawg_info,
686 tprintf(
"Language model components did not like this entry\n");
700 tprintf(
"Discarded ViterbiEntry with high cost %g max cost %g\n",
711 best_choice_bundle, blamer_bundle);
714 new_vse != best_choice_bundle->
best_vse) {
716 tprintf(
"Discarded ViterbiEntry with high cost %g\n", new_vse->
cost);
739 for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
748 if (prunable_counter > 0 &&
PrunablePath(*curr_vse)) --prunable_counter;
750 if (prunable_counter == 0) {
753 tprintf(
"Set viterbi_state_entries_prunable_max_cost to %g\n",
756 prunable_counter = -1;
763 new_vse->
Print(
"New");
765 curr_state->
Print(
"Updated viterbi list");
775 for (vit.mark_cycle_pt(); !vit.cycled_list() && new_vse->
top_choice_flags &&
776 new_vse->
cost >= vit.data()->cost; vit.forward()) {
782 tprintf(
"GenerateTopChoiceInfo: top_choice_flags=0x%x\n",
789 int curr_col,
int curr_row,
794 if (parent_vse ==
NULL) {
818 if (parent_vse ==
NULL || word_end ||
824 bool has_word_ending =
false;
832 has_word_ending =
true;
836 if (!has_word_ending)
return NULL;
850 for (
int i = 0; i < normed_ids.
size(); ++i) {
852 tprintf(
"Test Letter OK for unichar %d, normed %d\n",
855 word_end && i == normed_ids.
size() - 1);
858 }
else if (i < normed_ids.
size() - 1) {
863 tprintf(
"Letter was OK for unichar %d, normed %d\n",
879 const char *unichar,
float certainty,
float denom,
880 int curr_col,
int curr_row,
float outline_length,
883 const char *pcontext_ptr =
"";
884 int pcontext_unichar_step_len = 0;
885 if (parent_vse ==
NULL) {
890 pcontext_unichar_step_len =
894 int unichar_step_len = 0;
897 float ngram_and_classifier_cost =
899 pcontext_ptr, &unichar_step_len,
900 &pruned, &ngram_cost);
904 ngram_and_classifier_cost *=
907 if (parent_vse !=
NULL) {
908 ngram_and_classifier_cost +=
914 int num_remove = (unichar_step_len + pcontext_unichar_step_len -
916 if (num_remove > 0) pcontext_unichar_step_len -= num_remove;
917 while (num_remove > 0 && *pcontext_ptr !=
'\0') {
927 pcontext_ptr, pcontext_unichar_step_len, pruned, ngram_cost,
928 ngram_and_classifier_cost);
929 ngram_info->
context += unichar;
939 int *unichar_step_len,
940 bool *found_small_prob,
942 const char *context_ptr = context;
943 char *modified_context =
NULL;
944 char *modified_context_end =
NULL;
945 const char *unichar_ptr = unichar;
946 const char *unichar_end = unichar_ptr + strlen(unichar_ptr);
949 while (unichar_ptr < unichar_end &&
952 tprintf(
"prob(%s | %s)=%g\n", unichar_ptr, context_ptr,
956 ++(*unichar_step_len);
962 if (unichar_ptr < unichar_end) {
963 if (modified_context ==
NULL) {
964 int context_len = strlen(context);
966 new char[context_len + strlen(unichar_ptr) + step + 1];
967 strncpy(modified_context, context, context_len);
968 modified_context_end = modified_context + context_len;
969 context_ptr = modified_context;
971 strncpy(modified_context_end, unichar_ptr - step, step);
972 modified_context_end += step;
973 *modified_context_end =
'\0';
976 prob /=
static_cast<float>(*unichar_step_len);
979 *found_small_prob =
true;
982 *ngram_cost = -1.0*log2(prob);
983 float ngram_and_classifier_cost =
987 tprintf(
"-log [ p(%s) * p(%s | %s) ] = -log2(%g*%g) = %g\n", unichar,
989 ngram_and_classifier_cost);
991 if (modified_context !=
NULL)
delete[] modified_context;
992 return ngram_and_classifier_cost;
996 if (curr_list->empty())
return 1.0f;
999 BLOB_CHOICE_IT c_it(curr_list);
1000 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
1034 consistency_info->
punc_ref = NO_EDGE;
1037 bool prev_is_numalpha = (parent_b !=
NULL &&
1043 (is_apos && prev_is_numalpha)) ?
1045 if (consistency_info->
punc_ref == NO_EDGE ||
1053 node, pattern_unichar_id, word_end) : NO_EDGE;
1054 if (consistency_info->
punc_ref == NO_EDGE) {
1069 }
else if ((parent_b !=
NULL) && unicharset.
get_isupper(unichar_id)) {
1092 if (parent_vse !=
NULL &&
1098 consistency_info->
script_id = parent_script_id;
1100 if (consistency_info->
script_id != parent_script_id) {
1116 int fontinfo_id = -1;
1125 tprintf(
"pfont %s pfont %s font %s font2 %s common %s(%d)\n",
1137 bool expected_gap_found =
false;
1140 if (fontinfo_id >= 0) {
1141 ASSERT_HOST(fontinfo_id < fontinfo_table_->size());
1143 parent_b->
unichar_id(), unichar_id, &temp_gap)) {
1144 expected_gap = temp_gap;
1145 expected_gap_found =
true;
1150 int num_addends = 0;
1153 for (
int i = 0; i < 4; ++i) {
1156 }
else if (i == 1) {
1158 }
else if (i == 2) {
1163 ASSERT_HOST(temp_fid < 0 || fontinfo_table_->size());
1165 parent_b->
unichar_id(), unichar_id, &temp_gap)) {
1166 expected_gap += temp_gap;
1170 expected_gap_found = (num_addends > 0);
1171 if (num_addends > 0) {
1172 expected_gap /=
static_cast<float>(num_addends);
1175 if (expected_gap_found) {
1177 static_cast<float>(word_res->
GetBlobsGap(curr_col-1));
1178 float gap_ratio = expected_gap / actual_gap;
1184 if (gap_ratio < 0.0f || gap_ratio > 2.0f) {
1188 tprintf(
"spacing for %s(%d) %s(%d) col %d: expected %g actual %g\n",
1191 unichar_id, curr_col, expected_gap, actual_gap);
1205 tprintf(
"ComputeAdjustedPathCost %g ParamsModel features:\n", cost);
1208 tprintf(
"%s=%g\n", kParamsTrainingFeatureTypeName[f], features[f]);
1214 float adjustment = 1.0f;
1227 static_cast<float>(vse->
length);
1248 blamer_bundle, &truth_path);
1256 word->
print(
"UpdateBestChoice() constructed word");
1260 if (blamer_bundle !=
NULL) {
1267 tprintf(
"Raw features extracted from %s (cost=%g) [ ",
1291 tprintf(
"Updated raw choice\n");
1315 best_choice_bundle->
updated =
true;
1316 best_choice_bundle->
best_vse = vse;
1318 tprintf(
"Updated best choice\n");
1330 if (blamer_bundle !=
NULL) {
1344 int len = vse.
length <= kMaxSmallWordUnichars ? 0 :
1345 vse.
length <= kMaxMediumWordUnichars ? 1 : 2;
1395 if (truth_path !=
NULL) {
1397 (blamer_bundle !=
NULL &&
1408 float full_wh_ratio_mean = 0.0f;
1412 static_cast<float>(vse->
length));
1419 int total_blobs = 0;
1420 for (i = (vse->
length-1); i >= 0; --i) {
1421 if (blamer_bundle !=
NULL && truth_path !=
NULL && *truth_path &&
1423 *truth_path =
false;
1427 total_blobs += num_blobs;
1432 if ((full_wh_ratio_mean != 0.0f &&
1438 tprintf(
"full_wh_ratio_var += (%g-%g)^2\n",
1451 if (curr_vse ==
NULL)
break;
1452 curr_b = curr_vse->
curr_b;
1457 if (full_wh_ratio_mean != 0.0f) {
DawgPositionVector * active_dawgs
int context_unichar_step_len
static const float kBadRating
bool LogNewRawChoice(WERD_CHOICE *word_choice)
LMConsistencyInfo consistency_info
bool SizesDistinct(UNICHAR_ID id1, UNICHAR_ID id2) const
bool GetTopLowerUpperDigit(BLOB_CHOICE_LIST *curr_list, BLOB_CHOICE **first_lower, BLOB_CHOICE **first_upper, BLOB_CHOICE **first_digit) const
int language_model_viterbi_list_max_size
int viterbi_state_entries_prunable_length
Number and max cost of prunable paths in viterbi_state_entries.
void DisplaySegmentation(TWERD *word)
void SetScriptPositions(bool small_caps, TWERD *word)
static void ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float features[])
void set_certainty(float new_val)
double language_model_ngram_nonmatch_score
double language_model_ngram_small_prob
ViterbiStateEntry * best_vse
Best ViterbiStateEntry and BLOB_CHOICE.
virtual bool end_of_word(EDGE_REF edge_ref) const =0
double language_model_ngram_rating_factor
WERD_CHOICE * best_choice
static const LanguageModelFlagsType kDigitFlag
int prev_word_unichar_step_len_
const UnicityTable< FontInfo > * fontinfo_table_
int num_inconsistent_spaces
int language_model_ngram_order
float CertaintyScore(float cert)
bool LogNewCookedChoice(int max_num_choices, bool debug, WERD_CHOICE *word_choice)
bool get_isupper(UNICHAR_ID unichar_id) const
BLOB_CHOICE * curr_b
Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this).
void set_x_heights(float min_height, float max_height)
void UpdateBestRating(float rating)
void set_permuter(uinT8 perm)
int wordrec_display_segmentations
void reset_hyphen_vars(bool last_word_on_line)
bool language_model_ngram_space_delimited_language
void Print(const char *msg)
float ComputeCost(const float features[]) const
bool acceptable_choice_found_
double language_model_penalty_non_freq_dict_word
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
int language_model_debug_level
#define BOOL_MEMBER(name, val, comment, vec)
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
bool language_model_ngram_on
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
LanguageModelNgramInfo * ngram_info
WERD_CHOICE * ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res, DANGERR *fixpt, BlamerBundle *blamer_bundle, bool *truth_path)
LanguageModelDawgInfo * dawg_info
LanguageModelNgramInfo * GenerateNgramInfo(const char *unichar, float certainty, float denom, int curr_col, int curr_row, float outline_length, const ViterbiStateEntry *parent_vse)
void print_state(const char *msg) const
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)
int SetTopParentLowerUpperDigit(LanguageModelState *parent_node) const
const STRING & unichar_string() const
static const UNICHAR_ID kPatternUnicharID
bool PrunablePath(const ViterbiStateEntry &vse)
ViterbiStateEntry * parent_vse
double language_model_ngram_scale_factor
static const LanguageModelFlagsType kSmallestRatingFlag
bool AcceptableChoice(const WERD_CHOICE &best_choice, XHeightConsistencyEnum xheight_consistency)
Returns true if the given best_choice is good enough to stop.
virtual EDGE_REF edge_char_of(NODE_REF node, UNICHAR_ID unichar_id, bool word_end) const =0
Returns the edge that corresponds to the letter out of this node.
DawgPositionVector * beginning_active_dawgs_
float BodyMaxXHeight() const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
bool get_isdigit(UNICHAR_ID unichar_id) const
LanguageModelFlagsType top_choice_flags
int GetBlobsGap(int blob_index)
static const float kMaxAvgNgramCost
double language_model_penalty_non_dict_word
bool GuidedSegsearchStillGoing() const
#define BOOL_INIT_MEMBER(name, val, comment, vec)
float ngram_and_classifier_cost
-[ ln(P_classifier(path)) + scale_factor * ln(P_ngram_model(path)) ]
inT16 fontinfo_id() const
void set_best_choice_is_dict_and_top_choice(bool value)
float full_wh_ratio_total
int get_script(UNICHAR_ID unichar_id) const
bool HasAlnumChoice(const UNICHARSET &unicharset)
void FillConsistencyInfo(int curr_col, bool word_end, BLOB_CHOICE *b, ViterbiStateEntry *parent_vse, WERD_RES *word_res, LMConsistencyInfo *consistency_info)
const char *const id_to_unichar(UNICHAR_ID id) const
bool compound_marker(UNICHAR_ID unichar_id)
AssociateStats associate_stats
const UNICHARSET * uch_set
int NumInconsistentChartype() const
bool NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
XHeightConsistencyEnum xht_decision
const Dawg * GetPuncDawg() const
Return the points to the punctuation dawg.
bool hyphenated() const
Returns true if we've recorded the beginning of a hyphenated word.
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
int NumInconsistentCase() const
#define INT_MEMBER(name, val, comment, vec)
DawgPositionVector * very_beginning_active_dawgs_
DawgPositionVector * active_dawgs
void GenerateTopChoiceInfo(ViterbiStateEntry *new_vse, const ViterbiStateEntry *parent_vse, LanguageModelState *lms)
static int utf8_step(const char *utf8_str)
static const LanguageModelFlagsType kUpperCaseFlag
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)
static int Compare(const void *e1, const void *e2)
int LetterIsOkay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Calls letter_is_okay_ member function.
inT16 fontinfo_id2() const
int NumInconsistentSpaces() const
bool get_islower(UNICHAR_ID unichar_id) const
void ComputeXheightConsistency(const BLOB_CHOICE *b, bool is_punc)
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
bool correct_segmentation_explored_
bool get_ispunctuation(UNICHAR_ID unichar_id) const
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
bool MatrixPositionCorrect(int index, const MATRIX_COORD &coord)
double ProbabilityInContext(const char *context, int context_bytes, const char *character, int character_bytes)
Calls probability_in_context_ member function.
static const LanguageModelFlagsType kLowerCaseFlag
DANGERR fixpt
Places to try to fix the word suggested by ambiguity checking.
int language_model_viterbi_list_max_num_prunable
float viterbi_state_entries_prunable_max_cost
int viterbi_state_entries_length
Total number of entries in viterbi_state_entries.
PointerVector< LanguageModelState > beam
ViterbiStateEntry * competing_vse
static float ComputeOutlineLength(float rating_cert_scale, const BLOB_CHOICE &b)
int language_model_min_compound_length
void set_blob_choice(int index, int blob_count, const BLOB_CHOICE *blob_choice)
void AddHypothesis(const tesseract::ParamsTrainingHypothesis &hypo)
GenericVector< TBLOB * > blobs
const UNICHARSET & getUnicharset() const
static const LanguageModelFlagsType kXhtConsistentFlag
float ComputeConsistencyAdjustment(const LanguageModelDawgInfo *dawg_info, const LMConsistencyInfo &consistency_info)
bool get_isalpha(UNICHAR_ID unichar_id) const
bool PosAndSizeAgree(const BLOB_CHOICE &other, float x_height, bool debug) const
float BodyMinXHeight() const
LanguageModelDawgInfo * GenerateDawgInfo(bool word_end, int curr_col, int curr_row, const BLOB_CHOICE &b, const ViterbiStateEntry *parent_vse)
int InconsistentXHeight() const
unsigned char LanguageModelFlagsType
Used for expressing various language model flags.
void InitForWord(const WERD_CHOICE *prev_word, bool fixed_pitch, float max_char_wh_ratio, float rating_cert_scale)
bool AcceptablePath(const ViterbiStateEntry &vse)
bool updated
Flag to indicate whether anything was changed.
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
#define double_MEMBER(name, val, comment, vec)
DawgPositionVector * updated_dawgs
void Print(const char *msg) const
Struct to store information maintained by various language model components.
void ComputeAssociateStats(int col, int row, float max_char_wh_ratio, ViterbiStateEntry *parent_vse, WERD_RES *word_res, AssociateStats *associate_stats)
virtual UNICHAR_ID edge_letter(EDGE_REF edge_ref) const =0
Returns UNICHAR_ID stored in the edge indicated by the given EDGE_REF.
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
float ComputeNgramCost(const char *unichar, float certainty, float denom, const char *context, int *unichar_step_len, bool *found_small_prob, float *ngram_prob)
float ngram_cost
-ln(P_ngram_model(path))
int tessedit_truncate_wordchoice_log
GenericVector< int > blob_widths
ViterbiStateEntry_LIST viterbi_state_entries
Storage for the Viterbi state.
float ComputeDenom(BLOB_CHOICE_LIST *curr_list)
bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const
Check whether the word has a hyphen at the end.
ParamsModel params_model_
const char * string() const
int correct_segmentation_length() const
bool is_apostrophe(UNICHAR_ID unichar_id)
bool language_model_ngram_use_only_first_uft8_step
float ComputeAdjustedPathCost(ViterbiStateEntry *vse)
const MATRIX_COORD & matrix_cell()
LanguageModel(const UnicityTable< FontInfo > *fontinfo_table, Dict *dict)
static NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref)
Returns the appropriate next node given the EDGE_REF.
void adjust_word(WERD_CHOICE *word, bool nonword, XHeightConsistencyEnum xheight_consistency, float additional_adjust, bool modify_rating, bool debug)
Adjusts the rating of the given word.
UNICHAR_ID unichar_id() const
void UpdateBestChoice(ViterbiStateEntry *vse, LMPainPoints *pain_points, WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
float features[PTRAIN_NUM_FEATURE_TYPES]
void set_rating(float new_val)
Bundle together all the things pertaining to the best choice/state.
void set_dangerous_ambig_found_(bool value)
double language_model_penalty_increment