34 #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(ANDROID) 35 double log2(
double n) {
36 return log(n) / log(2.0);
46 :
INT_MEMBER(language_model_debug_level, 0,
"Language model debug level",
47 dict->getCCUtil()->params()),
49 "Turn on/off the use of character ngram model",
50 dict->getCCUtil()->params()),
52 "Maximum order of the character ngram model",
53 dict->getCCUtil()->params()),
54 INT_MEMBER(language_model_viterbi_list_max_num_prunable, 10,
55 "Maximum number of prunable (those for which" 56 " PrunablePath() is true) entries in each viterbi list" 57 " recorded in BLOB_CHOICEs",
58 dict->getCCUtil()->params()),
59 INT_MEMBER(language_model_viterbi_list_max_size, 500,
60 "Maximum size of viterbi lists recorded in BLOB_CHOICEs",
61 dict->getCCUtil()->params()),
63 "To avoid overly small denominators use this as the " 64 "floor of the probability returned by the ngram model.",
65 dict->getCCUtil()->params()),
67 "Average classifier score of a non-matching unichar.",
68 dict->getCCUtil()->params()),
69 BOOL_MEMBER(language_model_ngram_use_only_first_uft8_step, false,
70 "Use only the first UTF8 step of the given string" 71 " when computing log probabilities.",
72 dict->getCCUtil()->params()),
74 "Strength of the character ngram model relative to the" 75 " character classifier ",
76 dict->getCCUtil()->params()),
78 "Factor to bring log-probs into the same range as ratings" 79 " when multiplied by outline length ",
80 dict->getCCUtil()->params()),
81 BOOL_MEMBER(language_model_ngram_space_delimited_language, true,
82 "Words are delimited by space",
83 dict->getCCUtil()->params()),
84 INT_MEMBER(language_model_min_compound_length, 3,
85 "Minimum length of compound words",
86 dict->getCCUtil()->params()),
88 "Penalty for words not in the frequent word dictionary",
89 dict->getCCUtil()->params()),
91 "Penalty for non-dictionary words",
92 dict->getCCUtil()->params()),
94 "Penalty for inconsistent punctuation",
95 dict->getCCUtil()->params()),
97 "Penalty for inconsistent case",
98 dict->getCCUtil()->params()),
100 "Penalty for inconsistent script",
101 dict->getCCUtil()->params()),
103 "Penalty for inconsistent character type",
104 dict->getCCUtil()->params()),
108 "Penalty for inconsistent font",
109 dict->getCCUtil()->params()),
111 "Penalty for inconsistent spacing",
112 dict->getCCUtil()->params()),
115 dict->getCCUtil()->params()),
116 INT_MEMBER(wordrec_display_segmentations, 0,
"Display Segmentations",
117 dict->getCCUtil()->params()),
119 "Use sigmoidal score for certainty",
120 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) {
133 bool fixed_pitch,
float max_char_wh_ratio,
134 float rating_cert_scale) {
172 static void ScanParentsForCaseMix(
const UNICHARSET& unicharset,
174 if (parent_node == NULL)
return;
176 for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
183 if (other_case == unichar_id)
continue;
189 for (vit2.mark_cycle_pt(); !vit2.cycled_list() &&
190 vit2.data()->curr_b->unichar_id() != other_case;
192 if (!vit2.cycled_list()) {
203 static bool HasBetterCaseVariant(
const UNICHARSET& unicharset,
205 BLOB_CHOICE_LIST* choices) {
208 if (other_case == choice_id || other_case == INVALID_UNICHAR_ID)
212 BLOB_CHOICE_IT bc_it(choices);
213 for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) {
215 if (better_choice->
unichar_id() == other_case)
217 else if (better_choice == choice)
250 bool just_classified,
251 int curr_col,
int curr_row,
252 BLOB_CHOICE_LIST *curr_list,
259 tprintf(
"\nUpdateState: col=%d row=%d %s",
260 curr_col, curr_row, just_classified ?
"just_classified" :
"");
262 tprintf(
"(parent=%p)\n", parent_node);
268 bool new_changed =
false;
274 bool has_alnum_mix =
false;
275 if (parent_node != NULL) {
279 tprintf(
"No parents found to process\n");
283 has_alnum_mix =
true;
287 has_alnum_mix =
false;;
288 ScanParentsForCaseMix(unicharset, parent_node);
290 parent_node->
Print(
"Parent viterbi list");
295 ViterbiStateEntry_IT vit;
296 BLOB_CHOICE_IT c_it(curr_list);
297 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
309 if (c_it.at_first() || !new_changed)
313 if (first_digit == choice) blob_choice_flags |=
kDigitFlag;
315 if (parent_node == NULL) {
327 if (HasBetterCaseVariant(unicharset, choice, curr_list))
333 blob_choice_flags, denom, word_end, curr_col, curr_row,
334 choice, curr_state, NULL, pain_points,
335 word_res, best_choice_bundle, blamer_bundle);
344 c_it.data(), blob_choice_flags,
345 unicharset, word_res, &vit,
346 &top_choice_flags)) != NULL) {
359 HasBetterCaseVariant(unicharset, choice, curr_list))
364 top_choice_flags, denom, word_end, curr_col, curr_row,
365 c_it.data(), curr_state, parent_vse, pain_points,
366 word_res, best_choice_bundle, blamer_bundle);
383 BLOB_CHOICE_IT c_it(curr_list);
386 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
389 if (first_unichar == NULL) first_unichar = c_it.data();
390 if (*first_lower == NULL && unicharset.
get_islower(unichar_id)) {
391 *first_lower = c_it.data();
393 if (*first_upper == NULL && unicharset.
get_isalpha(unichar_id) &&
395 *first_upper = c_it.data();
397 if (*first_digit == NULL && unicharset.
get_isdigit(unichar_id)) {
398 *first_digit = c_it.data();
402 bool mixed = (*first_lower != NULL || *first_upper != NULL) &&
403 *first_digit != NULL;
404 if (*first_lower == NULL) *first_lower = first_unichar;
405 if (*first_upper == NULL) *first_upper = first_unichar;
406 if (*first_digit == NULL) *first_digit = first_unichar;
421 if (parent_node == NULL)
return -1;
427 float lower_rating = 0.0f;
428 float upper_rating = 0.0f;
429 float digit_rating = 0.0f;
430 float top_rating = 0.0f;
433 for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
440 while (unichar_id == INVALID_UNICHAR_ID &&
446 if (unichar_id != INVALID_UNICHAR_ID) {
448 if (top_lower == NULL || lower_rating > rating) {
450 lower_rating = rating;
453 if (top_upper == NULL || upper_rating > rating) {
455 upper_rating = rating;
458 if (top_digit == NULL || digit_rating > rating) {
460 digit_rating = rating;
464 if (top_choice == NULL || top_rating > rating) {
470 if (top_choice == NULL)
return -1;
471 bool mixed = (top_lower != NULL || top_upper != NULL) &&
473 if (top_lower == NULL) top_lower = top_choice;
475 if (top_upper == NULL) top_upper = top_choice;
477 if (top_digit == NULL) top_digit = top_choice;
488 return mixed ? 1 : 0;
497 bool just_classified,
bool mixed_alnum,
const BLOB_CHOICE* bc,
499 WERD_RES* word_res, ViterbiStateEntry_IT* vse_it,
501 for (; !vse_it->cycled_list(); vse_it->forward()) {
505 if (!just_classified && !parent_vse->
updated)
continue;
507 parent_vse->
Print(
"Considering");
509 *top_choice_flags = blob_choice_flags;
522 (mixed_alnum || *top_choice_flags == 0))
528 (mixed_alnum || *top_choice_flags == 0))
537 tprintf(
"Parent %s has competition %s\n",
561 int curr_col,
int curr_row,
569 ViterbiStateEntry_IT vit;
571 tprintf(
"AddViterbiStateEntry for unichar %s rating=%.4f" 572 " certainty=%.4f top_choice_flags=0x%x",
576 tprintf(
" parent_vse=%p\n", parent_vse);
581 if (curr_state != NULL &&
585 tprintf(
"AddViterbiStateEntry: viterbi list is full!\n");
594 float outline_length =
601 denom, curr_col, curr_row, outline_length, parent_vse);
604 bool liked_by_language_model = dawg_info != NULL ||
605 (ngram_info != NULL && !ngram_info->
pruned);
608 if (!liked_by_language_model && top_choice_flags == 0) {
610 tprintf(
"Language model components very early pruned this entry\n");
631 if (!liked_by_language_model && top_choice_flags == 0) {
633 tprintf(
"Language model components early pruned this entry\n");
642 word_res, &consistency_info);
643 if (dawg_info != NULL && consistency_info.
invalid_punc) {
650 parent_vse, word_res, &associate_stats);
651 if (parent_vse != NULL) {
658 parent_vse, b, 0.0, outline_length,
659 consistency_info, associate_stats, top_choice_flags, dawg_info,
680 tprintf(
"Language model components did not like this entry\n");
694 tprintf(
"Discarded ViterbiEntry with high cost %g max cost %g\n",
705 best_choice_bundle, blamer_bundle);
708 new_vse != best_choice_bundle->
best_vse) {
710 tprintf(
"Discarded ViterbiEntry with high cost %g\n", new_vse->
cost);
733 for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
742 if (prunable_counter > 0 &&
PrunablePath(*curr_vse)) --prunable_counter;
744 if (prunable_counter == 0) {
747 tprintf(
"Set viterbi_state_entries_prunable_max_cost to %g\n",
750 prunable_counter = -1;
757 new_vse->
Print(
"New");
759 curr_state->
Print(
"Updated viterbi list");
769 for (vit.mark_cycle_pt(); !vit.cycled_list() && new_vse->
top_choice_flags &&
770 new_vse->
cost >= vit.data()->cost; vit.forward()) {
776 tprintf(
"GenerateTopChoiceInfo: top_choice_flags=0x%x\n",
783 int curr_col,
int curr_row,
788 if (parent_vse == NULL) {
792 if (parent_vse->
dawg_info == NULL)
return NULL;
812 if (parent_vse == NULL || word_end ||
818 bool has_word_ending =
false;
826 has_word_ending =
true;
830 if (!has_word_ending)
return NULL;
844 for (
int i = 0; i < normed_ids.
size(); ++i) {
846 tprintf(
"Test Letter OK for unichar %d, normed %d\n",
849 word_end && i == normed_ids.
size() - 1);
852 }
else if (i < normed_ids.
size() - 1) {
857 tprintf(
"Letter was OK for unichar %d, normed %d\n",
873 const char *unichar,
float certainty,
float denom,
874 int curr_col,
int curr_row,
float outline_length,
877 const char *pcontext_ptr =
"";
878 int pcontext_unichar_step_len = 0;
879 if (parent_vse == NULL) {
884 pcontext_unichar_step_len =
888 int unichar_step_len = 0;
891 float ngram_and_classifier_cost =
893 pcontext_ptr, &unichar_step_len,
894 &pruned, &ngram_cost);
898 ngram_and_classifier_cost *=
901 if (parent_vse != NULL) {
902 ngram_and_classifier_cost +=
908 int num_remove = (unichar_step_len + pcontext_unichar_step_len -
910 if (num_remove > 0) pcontext_unichar_step_len -= num_remove;
911 while (num_remove > 0 && *pcontext_ptr !=
'\0') {
921 pcontext_ptr, pcontext_unichar_step_len, pruned, ngram_cost,
922 ngram_and_classifier_cost);
923 ngram_info->
context += unichar;
933 int *unichar_step_len,
934 bool *found_small_prob,
936 const char *context_ptr = context;
937 char *modified_context = NULL;
938 char *modified_context_end = NULL;
939 const char *unichar_ptr = unichar;
940 const char *unichar_end = unichar_ptr + strlen(unichar_ptr);
943 while (unichar_ptr < unichar_end &&
946 tprintf(
"prob(%s | %s)=%g\n", unichar_ptr, context_ptr,
950 ++(*unichar_step_len);
956 if (unichar_ptr < unichar_end) {
957 if (modified_context == NULL) {
958 int context_len = strlen(context);
960 new char[context_len + strlen(unichar_ptr) + step + 1];
961 strncpy(modified_context, context, context_len);
962 modified_context_end = modified_context + context_len;
963 context_ptr = modified_context;
965 strncpy(modified_context_end, unichar_ptr - step, step);
966 modified_context_end += step;
967 *modified_context_end =
'\0';
970 prob /=
static_cast<float>(*unichar_step_len);
973 *found_small_prob =
true;
976 *ngram_cost = -1.0*log2(prob);
977 float ngram_and_classifier_cost =
981 tprintf(
"-log [ p(%s) * p(%s | %s) ] = -log2(%g*%g) = %g\n", unichar,
983 ngram_and_classifier_cost);
985 delete[] modified_context;
986 return ngram_and_classifier_cost;
990 if (curr_list->empty())
return 1.0f;
993 BLOB_CHOICE_IT c_it(curr_list);
994 for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
1028 consistency_info->
punc_ref = NO_EDGE;
1031 bool prev_is_numalpha = (parent_b != NULL &&
1037 (is_apos && prev_is_numalpha)) ?
1039 if (consistency_info->
punc_ref == NO_EDGE ||
1047 node, pattern_unichar_id, word_end) : NO_EDGE;
1048 if (consistency_info->
punc_ref == NO_EDGE) {
1063 }
else if ((parent_b != NULL) && unicharset.
get_isupper(unichar_id)) {
1086 if (parent_vse != NULL &&
1092 consistency_info->
script_id = parent_script_id;
1094 if (consistency_info->
script_id != parent_script_id) {
1110 int fontinfo_id = -1;
1119 tprintf(
"pfont %s pfont %s font %s font2 %s common %s(%d)\n",
1131 bool expected_gap_found =
false;
1134 if (fontinfo_id >= 0) {
1135 ASSERT_HOST(fontinfo_id < fontinfo_table_->size());
1137 parent_b->
unichar_id(), unichar_id, &temp_gap)) {
1138 expected_gap = temp_gap;
1139 expected_gap_found =
true;
1144 int num_addends = 0;
1147 for (
int i = 0; i < 4; ++i) {
1150 }
else if (i == 1) {
1152 }
else if (i == 2) {
1157 ASSERT_HOST(temp_fid < 0 || fontinfo_table_->size());
1159 parent_b->
unichar_id(), unichar_id, &temp_gap)) {
1160 expected_gap += temp_gap;
1164 expected_gap_found = (num_addends > 0);
1165 if (num_addends > 0) {
1166 expected_gap /=
static_cast<float>(num_addends);
1169 if (expected_gap_found) {
1171 static_cast<float>(word_res->
GetBlobsGap(curr_col-1));
1172 float gap_ratio = expected_gap / actual_gap;
1178 if (gap_ratio < 0.0f || gap_ratio > 2.0f) {
1182 tprintf(
"spacing for %s(%d) %s(%d) col %d: expected %g actual %g\n",
1185 unichar_id, curr_col, expected_gap, actual_gap);
1199 tprintf(
"ComputeAdjustedPathCost %g ParamsModel features:\n", cost);
1202 tprintf(
"%s=%g\n", kParamsTrainingFeatureTypeName[f], features[f]);
1208 float adjustment = 1.0f;
1221 static_cast<float>(vse->
length);
1242 blamer_bundle, &truth_path);
1250 word->
print(
"UpdateBestChoice() constructed word");
1254 if (blamer_bundle != NULL) {
1261 tprintf(
"Raw features extracted from %s (cost=%g) [ ",
1285 tprintf(
"Updated raw choice\n");
1309 best_choice_bundle->
updated =
true;
1310 best_choice_bundle->
best_vse = vse;
1312 tprintf(
"Updated best choice\n");
1324 if (blamer_bundle != NULL) {
1338 int len = vse.
length <= kMaxSmallWordUnichars ? 0 :
1339 vse.
length <= kMaxMediumWordUnichars ? 1 : 2;
1389 if (truth_path != NULL) {
1391 (blamer_bundle != NULL &&
1402 float full_wh_ratio_mean = 0.0f;
1406 static_cast<float>(vse->
length));
1413 int total_blobs = 0;
1414 for (i = (vse->
length-1); i >= 0; --i) {
1415 if (blamer_bundle != NULL && truth_path != NULL && *truth_path &&
1417 *truth_path =
false;
1421 total_blobs += num_blobs;
1426 if ((full_wh_ratio_mean != 0.0f &&
1427 ((curr_vse != vse && curr_vse->
parent_vse != NULL) ||
1432 tprintf(
"full_wh_ratio_var += (%g-%g)^2\n",
1445 if (curr_vse == NULL)
break;
1446 curr_b = curr_vse->
curr_b;
1451 if (full_wh_ratio_mean != 0.0f) {
bool updated
Flag to indicate whether anything was changed.
bool AcceptablePath(const ViterbiStateEntry &vse)
int language_model_debug_level
static const UNICHAR_ID kPatternUnicharID
DawgPositionVector beginning_active_dawgs_
Bundle together all the things pertaining to the best choice/state.
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
LanguageModel(const UnicityTable< FontInfo > *fontinfo_table, Dict *dict)
static const LanguageModelFlagsType kUpperCaseFlag
int prev_word_unichar_step_len_
LanguageModelDawgInfo * dawg_info
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
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)
bool get_isalpha(UNICHAR_ID unichar_id) const
AssociateStats associate_stats
double language_model_penalty_increment
GenericVector< TBLOB * > blobs
DawgPositionVector * updated_dawgs
bool is_apostrophe(UNICHAR_ID unichar_id)
float ComputeCost(const float features[]) const
const STRING & unichar_string() const
void set_rating(float new_val)
virtual bool end_of_word(EDGE_REF edge_ref) const =0
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)
Struct to store information maintained by various language model components.
bool acceptable_choice_found_
float ComputeDenom(BLOB_CHOICE_LIST *curr_list)
double language_model_penalty_non_dict_word
float ngram_cost
-ln(P_ngram_model(path))
LanguageModelFlagsType top_choice_flags
bool PrunablePath(const ViterbiStateEntry &vse)
ViterbiStateEntry_LIST viterbi_state_entries
Storage for the Viterbi state.
void set_permuter(uinT8 perm)
double language_model_ngram_rating_factor
static const LanguageModelFlagsType kSmallestRatingFlag
static const LanguageModelFlagsType kDigitFlag
ParamsModel params_model_
void ComputeXheightConsistency(const BLOB_CHOICE *b, bool is_punc)
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)
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
const UNICHARSET & getUnicharset() const
void UpdateBestRating(float rating)
int InconsistentXHeight() const
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 viterbi_state_entries_prunable_length
Number and max cost of prunable paths in viterbi_state_entries.
int language_model_min_compound_length
float ComputeNgramCost(const char *unichar, float certainty, float denom, const char *context, int *unichar_step_len, bool *found_small_prob, float *ngram_prob)
PointerVector< LanguageModelState > beam
int language_model_viterbi_list_max_num_prunable
double language_model_ngram_scale_factor
bool GuidedSegsearchStillGoing() const
void set_dangerous_ambig_found_(bool value)
WERD_CHOICE * best_choice
static const LanguageModelFlagsType kLowerCaseFlag
int NumInconsistentChartype() const
static NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref)
Returns the appropriate next node given the EDGE_REF.
bool LogNewCookedChoice(int max_num_choices, bool debug, WERD_CHOICE *word_choice)
void print_state(const char *msg) const
UNICHAR_ID get_other_case(UNICHAR_ID unichar_id) const
const UnicityTable< FontInfo > * fontinfo_table_
static int Compare(const void *e1, const void *e2)
bool PosAndSizeAgree(const BLOB_CHOICE &other, float x_height, bool debug) const
bool get_ispunctuation(UNICHAR_ID unichar_id) const
#define BOOL_INIT_MEMBER(name, val, comment, vec)
UNICHAR_ID unichar_id() const
float BodyMinXHeight() const
void InitForWord(const WERD_CHOICE *prev_word, bool fixed_pitch, float max_char_wh_ratio, float rating_cert_scale)
LanguageModelNgramInfo * GenerateNgramInfo(const char *unichar, float certainty, float denom, int curr_col, int curr_row, float outline_length, const ViterbiStateEntry *parent_vse)
void reset_hyphen_vars(bool last_word_on_line)
WERD_CHOICE * ConstructWord(ViterbiStateEntry *vse, WERD_RES *word_res, DANGERR *fixpt, BlamerBundle *blamer_bundle, bool *truth_path)
float ngram_and_classifier_cost
-[ ln(P_classifier(path)) + scale_factor * ln(P_ngram_model(path)) ]
static float ComputeOutlineLength(float rating_cert_scale, const BLOB_CHOICE &b)
int context_unichar_step_len
bool language_model_ngram_use_only_first_uft8_step
bool language_model_ngram_space_delimited_language
ViterbiStateEntry * competing_vse
const char * string() const
double ProbabilityInContext(const char *context, int context_bytes, const char *character, int character_bytes)
Calls probability_in_context_ member function.
int language_model_ngram_order
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
static const float kMaxAvgNgramCost
void set_certainty(float new_val)
#define BOOL_MEMBER(name, val, comment, vec)
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 DisplaySegmentation(TWERD *word)
static void ExtractFeaturesFromPath(const ViterbiStateEntry &vse, float features[])
bool correct_segmentation_explored_
#define INT_MEMBER(name, val, comment, vec)
inT16 fontinfo_id2() const
int NumInconsistentSpaces() const
DANGERR fixpt
Places to try to fix the word suggested by ambiguity checking.
bool get_isupper(UNICHAR_ID unichar_id) const
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
int tessedit_truncate_wordchoice_log
DawgPositionVector active_dawgs
#define double_MEMBER(name, val, comment, vec)
int num_inconsistent_spaces
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.
int LetterIsOkay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Calls letter_is_okay_ member function.
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.
float viterbi_state_entries_prunable_max_cost
void set_best_choice_is_dict_and_top_choice(bool value)
bool LogNewRawChoice(WERD_CHOICE *word_choice)
static const LanguageModelFlagsType kXhtConsistentFlag
int get_script(UNICHAR_ID unichar_id) const
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
void Print(const char *msg) const
ViterbiStateEntry * parent_vse
int GetBlobsGap(int blob_index)
double language_model_ngram_nonmatch_score
void SetScriptPositions(bool small_caps, TWERD *word)
bool language_model_ngram_on
void set_blob_choice(int index, int blob_count, const BLOB_CHOICE *blob_choice)
const UNICHARSET * uch_set
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)
XHeightConsistencyEnum xht_decision
DawgPositionVector * active_dawgs
float CertaintyScore(float cert)
bool HasAlnumChoice(const UNICHARSET &unicharset)
bool MatrixPositionCorrect(int index, const MATRIX_COORD &coord)
float ComputeAdjustedPathCost(ViterbiStateEntry *vse)
double language_model_ngram_small_prob
static const float kBadRating
bool TESS_API NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
unsigned char LanguageModelFlagsType
Used for expressing various language model flags.
float full_wh_ratio_total
float BodyMaxXHeight() const
const MATRIX_COORD & matrix_cell()
void AddHypothesis(const tesseract::ParamsTrainingHypothesis &hypo)
inT16 fontinfo_id() const
int NumInconsistentCase() const
bool get_isdigit(UNICHAR_ID unichar_id) const
GenericVector< int > blob_widths
bool GetTopLowerUpperDigit(BLOB_CHOICE_LIST *curr_list, BLOB_CHOICE **first_lower, BLOB_CHOICE **first_upper, BLOB_CHOICE **first_digit) const
bool get_islower(UNICHAR_ID unichar_id) const
int viterbi_state_entries_length
Total number of entries in viterbi_state_entries.
ViterbiStateEntry * best_vse
Best ViterbiStateEntry and BLOB_CHOICE.
const char * id_to_unichar(UNICHAR_ID id) const
int correct_segmentation_length() const
bool hyphenated() const
Returns true if we've recorded the beginning of a hyphenated word.
bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const
Check whether the word has a hyphen at the end.
void FillConsistencyInfo(int curr_col, bool word_end, BLOB_CHOICE *b, ViterbiStateEntry *parent_vse, WERD_RES *word_res, LMConsistencyInfo *consistency_info)
static int utf8_step(const char *utf8_str)
float features[PTRAIN_NUM_FEATURE_TYPES]
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
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
void Print(const char *msg)
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)
double language_model_penalty_non_freq_dict_word
LMConsistencyInfo consistency_info
bool SizesDistinct(UNICHAR_ID id1, UNICHAR_ID id2) const
const Dawg * GetPuncDawg() const
Return the points to the punctuation dawg.
float ComputeConsistencyAdjustment(const LanguageModelDawgInfo *dawg_info, const LMConsistencyInfo &consistency_info)
bool compound_marker(UNICHAR_ID unichar_id)
void GenerateTopChoiceInfo(ViterbiStateEntry *new_vse, const ViterbiStateEntry *parent_vse, LanguageModelState *lms)
int SetTopParentLowerUpperDigit(LanguageModelState *parent_node) const