36 static const
double kStopperAmbiguityThresholdGain = 8.0;
39 static const
double kStopperAmbiguityThresholdOffset = 1.5;
53 static
double StopperAmbigThreshold(
double f1,
double f2) {
54 return (f2 - f1) * kStopperAmbiguityThresholdGain -
55 kStopperAmbiguityThresholdOffset;
64 bool merge_similar_words,
65 BLOCK_LIST *the_block_list,
68 BLOCK_IT block_it(the_block_list);
70 for (block_it.mark_cycle_pt();
71 !block_it.cycled_list(); block_it.forward()) {
72 block_res_it.add_to_end(
new BLOCK_RES(merge_similar_words,
85 ROW_IT row_it (the_block->
row_list ());
86 ROW_RES_IT row_res_it(&row_res_list);
92 font_assigned =
FALSE;
99 for (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {
100 row_res_it.add_to_end(
new ROW_RES(merge_similar_words, row_it.data()));
112 WERD_RES_IT word_res_it(&word_res_list);
118 whole_word_rej_count = 0;
121 bool add_next_word =
false;
125 for (word_it.mark_cycle_pt(); !word_it.cycled_list(); word_it.forward()) {
133 }
else if (merge_similar_words) {
137 word_res->
odd_size = !add_next_word;
139 WERD* next_word = word_it.data_relative(1);
140 if (merge_similar_words) {
148 int prev_right = union_box.
right();
149 union_box += next_box;
153 add_next_word =
false;
162 copy_word =
new WERD;
163 *copy_word = *(word_it.data());
167 word_res_it.add_to_end(combo);
173 word_res_it.add_to_end(word_res);
183 *word = *(source.
word);
206 WERD_CHOICE_IT wc_it(const_cast<WERD_CHOICE_LIST*>(&source.
best_choices));
207 WERD_CHOICE_IT wc_dest_it(&best_choices);
208 for (wc_it.mark_cycle_pt(); !wc_it.cycled_list(); wc_it.forward()) {
210 wc_dest_it.add_after_then_move(
new WERD_CHOICE(*choice));
212 if (!wc_dest_it.empty()) {
213 wc_dest_it.move_to_first();
214 best_choice = wc_dest_it.data();
232 CopySimpleFields(source);
271 CopySimpleFields(source);
297 const TBOX* norm_box,
300 bool allow_detailed_fx,
307 word->cblob_list()->empty()) || (pb !=
NULL && !pb->
IsText())) {
310 SetupFake(unicharset_in);
315 SetupWordScript(unicharset_in);
317 float word_xheight = use_body_size && row !=
NULL && row->
body_size() > 0.0f
319 chopped_word->BLNormalize(block, row, pix, word->flag(
W_INVERSE),
320 word_xheight, baseline_shift, numeric_mode,
321 norm_mode_hint, norm_box, &denorm);
323 SetupBasicsFromChoppedWord(unicharset_in);
325 int num_blobs = chopped_word->NumBlobs();
337 SetupBlobWidthsAndGaps();
345 SetupWordScript(unicharset_in);
346 chopped_word =
new TWERD;
347 rebuild_word =
new TWERD;
350 int blob_count = word->cblob_list()->
length();
351 if (blob_count > 0) {
355 C_BLOB_IT b_it(word->cblob_list());
357 for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
358 TBOX box = b_it.data()->bounding_box();
359 box_word->InsertBox(box_word->length(), box);
362 FakeClassifyWord(blob_count, fake_choices);
363 delete [] fake_choices;
367 LogNewRawChoice(word);
369 LogNewCookedChoice(1,
false, word);
378 word->set_script_id(script);
385 if (blamer_bundle !=
NULL) {
386 blamer_bundle->SetupNormTruthWord(denorm);
392 blob_widths.truncate(0);
393 blob_gaps.truncate(0);
394 int num_blobs = chopped_word->NumBlobs();
395 for (
int b = 0; b < num_blobs; ++b) {
396 TBLOB *blob = chopped_word->blobs[b];
398 blob_widths.push_back(box.
width());
399 if (b + 1 < num_blobs) {
401 chopped_word->blobs[b + 1]->bounding_box().left() - box.
right());
412 seam_array.insert(seam, blob_number);
413 if (ratings !=
NULL) {
415 ratings = ratings->ConsumeAndMakeBigger(blob_number);
417 if (raw_choice !=
NULL)
418 raw_choice->UpdateStateForSplit(blob_number);
419 WERD_CHOICE_IT wc_it(&best_choices);
420 for (wc_it.mark_cycle_pt(); !wc_it.cycled_list(); wc_it.forward()) {
424 SetupBlobWidthsAndGaps();
432 WERD_CHOICE_IT wc_it(const_cast<WERD_CHOICE_LIST*>(&best_choices));
433 for (wc_it.forward(); !wc_it.at_first(); wc_it.forward()) {
444 return !best_choices.singleton() || best_choice->dangerous_ambig_found();
450 int ratings_dim = ratings->dimension();
451 if (raw_choice->TotalOfStates() != ratings_dim) {
452 tprintf(
"raw_choice has total of states = %d vs ratings dim of %d\n",
453 raw_choice->TotalOfStates(), ratings_dim);
456 WERD_CHOICE_IT it(&best_choices);
458 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward(), ++index) {
461 tprintf(
"Cooked #%d has total of states = %d vs ratings dim of %d\n",
473 (word_to_debug !=
NULL && *word_to_debug !=
'\0' && best_choice !=
NULL &&
474 best_choice->unichar_string() ==
STRING(word_to_debug))) {
475 if (raw_choice !=
NULL)
476 raw_choice->print(
"\nBest Raw Choice");
478 WERD_CHOICE_IT it(&best_choices);
480 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward(), ++index) {
491 tprintf(
"Best choice: accepted=%d, adaptable=%d, done=%d : ",
492 tess_accepted, tess_would_adapt, done);
493 if (best_choice ==
NULL)
496 best_choice->print(msg);
505 if (best_choice ==
NULL || best_choices.singleton())
508 if (debug_level >= 2)
509 best_choice->print(
"\nFiltering against best choice");
510 WERD_CHOICE_IT it(&best_choices);
512 for (it.forward(); !it.at_first(); it.forward(), ++index) {
514 float threshold = StopperAmbigThreshold(best_choice->adjust_factor(),
521 int i = 0, j = 0, chunk = 0;
526 int choice_chunk = choice->
state(0), best_chunk = best_choice->state(0);
527 while (i < choice->length() && j < best_choice->length()) {
528 if (choice->
unichar_id(i) != best_choice->unichar_id(j) &&
529 choice->
certainty(i) - best_choice->certainty(j) < threshold) {
530 if (debug_level >= 2) {
532 label.
add_str_int(
"\nDiscarding bad choice #", index);
534 tprintf(
"i %d j %d Chunk %d Choice->Blob[i].Certainty %.4g" 535 " BestChoice->ChunkCertainty[Chunk] %g Threshold %g\n",
537 best_choice->certainty(j), threshold);
544 while (choice_chunk < chunk && ++i < choice->length())
545 choice_chunk += choice->
state(i);
547 while (best_chunk < chunk && ++j < best_choice->length())
548 best_chunk += best_choice->state(j);
559 int end_chunk = best_choice->state(0);
560 int end_raw_chunk = raw_choice->state(0);
562 for (
int i = 0; i < best_choice->length(); i++, thresholds++) {
563 float avg_rating = 0.0f;
564 int num_error_chunks = 0;
567 while (chunk < end_chunk) {
568 if (chunk >= end_raw_chunk) {
570 end_raw_chunk += raw_choice->state(raw_blob);
572 if (best_choice->unichar_id(i) !=
573 raw_choice->unichar_id(raw_blob)) {
574 avg_rating += raw_choice->certainty(raw_blob);
580 if (num_error_chunks > 0) {
581 avg_rating /= num_error_chunks;
582 *thresholds = (avg_rating / -certainty_scale) * (1.0 - rating_margin);
584 *thresholds = max_rating;
587 if (*thresholds > max_rating)
588 *thresholds = max_rating;
589 if (*thresholds < min_rating)
590 *thresholds = min_rating;
597 if (raw_choice ==
NULL || word_choice->
rating() < raw_choice->rating()) {
614 if (best_choice !=
NULL) {
620 float max_certainty_delta =
621 StopperAmbigThreshold(best_choice->adjust_factor(),
623 if (max_certainty_delta > -kStopperAmbiguityThresholdOffset)
624 max_certainty_delta = -kStopperAmbiguityThresholdOffset;
625 if (word_choice->
certainty() - best_choice->certainty() <
626 max_certainty_delta) {
630 tprintf(
"Discarding choice \"%s\" with an overly low certainty" 631 " %.3f vs best choice certainty %.3f (Threshold: %.3f)\n",
633 best_choice->certainty(),
634 max_certainty_delta + best_choice->certainty());
643 WERD_CHOICE_IT it(&best_choices);
645 bool inserted =
false;
650 if (choice->
rating() > word_choice->
rating() && !inserted) {
652 it.add_before_stay_put(word_choice);
654 if (num_choices == 0)
655 best_choice = word_choice;
665 tprintf(
"Discarding duplicate choice \"%s\", rating %g vs %g\n",
673 if (num_choices > max_num_choices)
677 }
while (!it.at_first());
679 if (!inserted && num_choices < max_num_choices) {
680 it.add_to_end(word_choice);
682 if (num_choices == 0)
683 best_choice = word_choice;
687 tprintf(
"New %s", best_choice == word_choice ?
"Best" :
"Secondary");
690 word_choice->
print(
" Word Choice");
702 template<
class T>
static void MovePointerData(T** dest, T**src) {
711 WERD_CHOICE_IT it(const_cast<WERD_CHOICE_LIST*>(&best_choices));
712 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
713 if (!it.at_first()) alternates_str +=
"\", \"";
714 alternates_str += it.data()->unichar_string();
716 tprintf(
"Alternates for \"%s\": {\"%s\"}\n",
717 best_choice->unichar_string().string(), alternates_str.
string());
724 for (
int b = start_blob; b <= last_blob; ++b) {
725 result += blob_widths[b];
727 result += blob_gaps[b];
733 if (blob_index < 0 || blob_index >= blob_gaps.size())
735 return blob_gaps[blob_index];
743 if (index < 0 || index >= best_choice->length())
return NULL;
744 BLOB_CHOICE_LIST* choices = GetBlobChoices(index);
752 return best_choice->blob_choices(index, ratings);
762 MovePointerData(&box_word, &word->
box_word);
763 seam_array.delete_data_pointers();
770 if (ratings !=
NULL) ratings->delete_matrix_pointers();
771 MovePointerData(&ratings, &word->
ratings);
773 MovePointerData(&raw_choice, &word->
raw_choice);
774 best_choices.clear();
775 WERD_CHOICE_IT wc_it(&best_choices);
779 assert(blamer_bundle !=
NULL);
782 CopySimpleFields(*word);
788 best_choice = choice;
793 reject_map.initialise(best_state.length());
794 done = tess_accepted = tess_would_adapt =
true;
795 SetScriptPositions();
802 if (rebuild_word !=
NULL)
804 rebuild_word =
new TWERD;
805 if (seam_array.empty())
807 best_state.truncate(0);
809 for (
int i = 0; i < best_choice->length(); ++i) {
810 int length = best_choice->state(i);
811 best_state.push_back(length);
816 TBLOB* blob = chopped_word->blobs[start];
817 rebuild_word->blobs.push_back(
new TBLOB(*blob));
829 if (rebuild_word !=
NULL)
831 rebuild_word =
new TWERD(*chopped_word);
833 int word_len = box_word->length();
834 best_state.reserve(word_len);
835 correct_text.reserve(word_len);
836 for (
int i = 0; i < word_len; ++i) {
837 best_state.push_back(1);
838 correct_text.push_back(
STRING(
""));
844 if (box_word !=
NULL)
846 rebuild_word->ComputeBoundingBoxes();
848 box_word->ClipToOriginalWord(denorm.block(), word);
854 best_choice->SetScriptPositions(small_caps, chopped_word);
861 raw_choice->SetAllScriptPositions(position);
862 WERD_CHOICE_IT wc_it(&best_choices);
863 for (wc_it.mark_cycle_pt(); !wc_it.cycled_list(); wc_it.forward())
864 wc_it.data()->SetAllScriptPositions(position);
878 ratings =
new MATRIX(blob_count, 1);
879 for (
int c = 0; c < blob_count; ++c) {
880 BLOB_CHOICE_LIST* choice_list =
new BLOB_CHOICE_LIST;
881 BLOB_CHOICE_IT choice_it(choice_list);
882 choice_it.add_after_then_move(choices[c]);
883 ratings->put(c, c, choice_list);
885 FakeWordFromRatings();
886 reject_map.initialise(blob_count);
893 int num_blobs = ratings->dimension();
896 for (
int b = 0; b < num_blobs; ++b) {
900 BLOB_CHOICE_LIST* choices = ratings->get(b, b);
901 if (choices !=
NULL && !choices->empty()) {
902 BLOB_CHOICE_IT bc_it(choices);
905 rating = choice->
rating();
911 LogNewRawChoice(word_choice);
913 LogNewCookedChoice(1,
false, word_choice);
918 correct_text.clear();
920 for (
int i = 0; i < best_choice->length(); ++i) {
921 UNICHAR_ID choice_id = best_choice->unichar_id(i);
922 const char* blob_choice = uch_set->id_to_unichar(choice_id);
923 correct_text.push_back(
STRING(blob_choice));
936 bool modified =
false;
937 for (
int i = 0; i + 1 < best_choice->length(); ++i) {
938 UNICHAR_ID new_id = class_cb->
Run(best_choice->unichar_id(i),
939 best_choice->unichar_id(i+1));
940 if (new_id != INVALID_UNICHAR_ID &&
941 (box_cb ==
NULL || box_cb->
Run(box_word->BlobBox(i),
942 box_word->BlobBox(i + 1)))) {
944 best_choice->set_unichar_id(new_id, i);
946 MergeAdjacentBlobs(i);
947 const MATRIX_COORD& coord = best_choice->MatrixCoord(i);
948 if (!coord.
Valid(*ratings)) {
949 ratings->IncreaseBandSize(coord.
row + 1 - coord.
col);
951 BLOB_CHOICE_LIST* blob_choices = GetBlobChoices(i);
956 BLOB_CHOICE_IT bc_it(blob_choices);
957 bc_it.add_before_then_move(blob_choice);
969 if (reject_map.length() == best_choice->length())
970 reject_map.remove_pos(index);
971 best_choice->remove_unichar_id(index + 1);
972 rebuild_word->MergeBlobs(index, index + 2);
973 box_word->MergeBoxes(index, index + 2);
974 if (index + 1 < best_state.length()) {
975 best_state[index] += best_state[index + 1];
976 best_state.remove(index + 1);
986 static int is_simple_quote(
const char* signed_str,
int length) {
987 const unsigned char* str =
988 reinterpret_cast<const unsigned char*
>(signed_str);
990 return (length == 1 && (*str ==
'\'' || *str ==
'`')) ||
992 (length == 3 && ((*str == 0xe2 &&
993 *(str + 1) == 0x80 &&
994 *(str + 2) == 0x98) ||
996 *(str + 1) == 0x80 &&
997 *(str + 2) == 0x99)));
1003 const char *ch = uch_set->id_to_unichar(id1);
1004 const char *next_ch = uch_set->id_to_unichar(id2);
1005 if (is_simple_quote(ch, strlen(ch)) &&
1006 is_simple_quote(next_ch, strlen(next_ch)))
1007 return uch_set->unichar_to_id(
"\"");
1008 return INVALID_UNICHAR_ID;
1013 if (!uch_set->contains_unichar(
"\"") ||
1014 !uch_set->get_enabled(uch_set->unichar_to_id(
"\"")))
1017 ConditionalBlobMerge(
1025 const char *ch = uch_set->id_to_unichar(id1);
1026 const char *next_ch = uch_set->id_to_unichar(id2);
1027 if (strlen(ch) == 1 && strlen(next_ch) == 1 &&
1028 (*ch ==
'-' || *ch ==
'~') && (*next_ch ==
'-' || *next_ch ==
'~'))
1029 return uch_set->unichar_to_id(
"-");
1030 return INVALID_UNICHAR_ID;
1042 if (!uch_set->contains_unichar(
"-") ||
1043 !uch_set->get_enabled(uch_set->unichar_to_id(
"-")))
1046 ConditionalBlobMerge(
1054 if (id1 == id2 && id1 == uch_set->unichar_to_id(
" "))
1057 return INVALID_UNICHAR_ID;
1062 if (ConditionalBlobMerge(
1064 int len = best_choice->length();
1074 for (
int index = start; index < start + count - 1; ++index) {
1075 if (index >= 0 && index < seam_array.size()) {
1076 SEAM* seam = seam_array[index];
1089 tess_failed =
FALSE;
1090 tess_accepted =
FALSE;
1091 tess_would_adapt =
FALSE;
1103 fontinfo_id_count = 0;
1104 fontinfo_id2_count = 0;
1107 baseline_shift = 0.0f;
1108 guessed_x_ht =
TRUE;
1109 guessed_caps_ht =
TRUE;
1110 combination =
FALSE;
1111 part_of_combo =
FALSE;
1112 reject_spaces =
FALSE;
1120 chopped_word =
NULL;
1121 rebuild_word =
NULL;
1127 blamer_bundle =
NULL;
1131 if (word !=
NULL && combination) {
1135 delete blamer_bundle;
1136 blamer_bundle =
NULL;
1144 fontinfo_id_count = 0;
1145 fontinfo_id2_count = 0;
1146 if (bln_boxes !=
NULL) {
1151 if (chopped_word !=
NULL) {
1152 delete chopped_word;
1153 chopped_word =
NULL;
1155 if (rebuild_word !=
NULL) {
1156 delete rebuild_word;
1157 rebuild_word =
NULL;
1159 if (box_word !=
NULL) {
1164 correct_text.clear();
1165 seam_array.delete_data_pointers();
1167 blob_widths.clear();
1171 if (blamer_bundle !=
NULL) blamer_bundle->ClearResults();
1175 if (raw_choice !=
NULL) {
1179 best_choices.clear();
1180 if (ep_choice !=
NULL) {
1186 if (ratings !=
NULL) {
1187 ratings->delete_matrix_pointers();
1195 return word_res == other.word_res &&
1196 row_res == other.row_res &&
1197 block_res == other.block_res;
1202 if (other.block_res ==
NULL) {
1204 if (block_res ==
NULL)
1208 if (block_res ==
NULL) {
1211 if (block_res == other.block_res) {
1212 if (other.row_res ==
NULL || row_res ==
NULL) {
1216 if (row_res == other.row_res) {
1219 if (word_res == other.word_res) {
1224 WERD_RES_IT word_res_it(&row_res->word_res_list);
1225 for (word_res_it.mark_cycle_pt(); !word_res_it.cycled_list();
1226 word_res_it.forward()) {
1227 if (word_res_it.data() == word_res) {
1229 }
else if (word_res_it.data() == other.word_res) {
1237 ROW_RES_IT row_res_it(&block_res->row_res_list);
1238 for (row_res_it.mark_cycle_pt(); !row_res_it.cycled_list();
1239 row_res_it.forward()) {
1240 if (row_res_it.data() == row_res) {
1242 }
else if (row_res_it.data() == other.row_res) {
1250 BLOCK_RES_IT block_res_it(&page_res->block_res_list);
1251 for (block_res_it.mark_cycle_pt();
1252 !block_res_it.cycled_list(); block_res_it.forward()) {
1253 if (block_res_it.data() == block_res) {
1255 }
else if (block_res_it.data() == other.block_res) {
1275 WERD_RES_IT wr_it(&row()->word_res_list);
1276 for (wr_it.mark_cycle_pt(); !wr_it.cycled_list(); wr_it.forward()) {
1278 if (word == word_res)
1282 wr_it.add_before_then_move(new_res);
1283 if (wr_it.at_first()) {
1286 ResetWordIterator();
1294 static void ComputeBlobEnds(
const WERD_RES& word, C_BLOB_LIST* next_word_blobs,
1300 TBOX blob_box = blob_it.data()->bounding_box();
1302 for (
int b = 1; b < length; ++b) {
1303 blob_box += blob_it.data()->bounding_box();
1309 if (!blob_it.at_first() || next_word_blobs !=
NULL) {
1310 if (blob_it.at_first())
1311 blob_it.set_to_list(next_word_blobs);
1312 blob_end = (blob_box.
right() + blob_it.data()->bounding_box().left()) / 2;
1323 if (words->
empty()) {
1324 DeleteCurrentWord();
1330 (*words)[0]->word->set_flag(
W_BOL,
true);
1332 (*words)[0]->word->set_blanks(1);
1342 WERD_IT w_it(row()->row->word_list());
1344 for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
1345 WERD* word = w_it.data();
1346 if (word == input_word->
word)
1353 WERD_RES_IT wr_it(&row()->word_res_list);
1354 for (wr_it.mark_cycle_pt(); !wr_it.cycled_list(); wr_it.forward()) {
1356 if (word == input_word)
1366 for (
int w = 0; w < words->
size(); ++w) {
1370 C_BLOB_LIST* next_word_blobs =
1371 w + 1 < words->
size() ? (*words)[w + 1]->word->cblob_list() :
NULL;
1372 ComputeBlobEnds(*word_w, next_word_blobs, &blob_ends);
1378 for (
int i = 0; i < blob_ends.
size(); ++i) {
1379 int end_x = blob_ends[i];
1382 while (!src_b_it.empty() &&
1383 src_b_it.data()->bounding_box().x_middle() < end_x) {
1384 blob_box += src_b_it.data()->bounding_box();
1385 dest_it.add_after_then_move(src_b_it.extract());
1388 while (!rej_b_it.empty() &&
1389 rej_b_it.data()->bounding_box().x_middle() < end_x) {
1390 blob_box += rej_b_it.data()->bounding_box();
1391 dest_it.add_after_then_move(rej_b_it.extract());
1397 if (i > 0 && blob_box.
left() < blob_ends[i - 1])
1398 blob_box.
set_left(blob_ends[i - 1]);
1399 if (blob_box.
right() > end_x)
1401 box_word->InsertBox(i, blob_box);
1406 for (
int i = 0; i < box_word->length(); ++i) {
1407 TBOX box = box_word->BlobBox(i);
1411 for (dest_it.mark_cycle_pt(); !dest_it.cycled_list();
1412 dest_it.forward()) {
1413 TBOX blob_box = dest_it.data()->bounding_box();
1414 if (blob_box.
left() < blob_ends[i] &&
1415 (i == 0 || blob_box.
right() >= blob_ends[i - 1])) {
1416 if (i > 0 && blob_box.
left() < blob_ends[i - 1])
1417 blob_box.
set_left(blob_ends[i - 1]);
1418 if (blob_box.
right() > blob_ends[i])
1420 box_word->ChangeBox(i, blob_box);
1431 w_it.add_before_stay_put(word_w->
word);
1435 wr_it.add_before_stay_put(word_w);
1443 delete w_it.extract();
1444 delete wr_it.extract();
1445 ResetWordIterator();
1453 if (!word_res->combination) {
1457 WERD_IT w_it(row()->row->word_list());
1458 for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
1459 if (w_it.data() == word_res->word) {
1464 delete w_it.extract();
1468 WERD_RES_IT wr_it(&row()->word_res_list);
1469 for (wr_it.mark_cycle_pt(); !wr_it.cycled_list(); wr_it.forward()) {
1470 if (wr_it.data() == word_res) {
1476 delete wr_it.extract();
1477 ResetWordIterator();
1483 WERD* real_word = word_res->word;
1486 if (word_res->combination) {
1489 WERD_RES_IT wr_it(&row()->word_res_list);
1490 for (wr_it.mark_cycle_pt();
1491 !wr_it.cycled_list() && wr_it.data() != word_res; wr_it.forward()) {
1495 real_word = wr_it.data()->word;
1510 block_res_it.set_to_list(&page_res->block_res_list);
1511 block_res_it.mark_cycle_pt();
1512 prev_block_res =
NULL;
1513 prev_row_res =
NULL;
1514 prev_word_res =
NULL;
1518 next_block_res =
NULL;
1519 next_row_res =
NULL;
1520 next_word_res =
NULL;
1521 internal_forward(
true, empty_ok);
1522 return internal_forward(
false, empty_ok);
1533 if (row_res == next_row_res) {
1536 word_res_it.move_to_first();
1537 for (word_res_it.mark_cycle_pt();
1538 !word_res_it.cycled_list() && word_res_it.data() != next_word_res;
1539 word_res_it.forward()) {
1540 if (!word_res_it.data()->part_of_combo) {
1541 if (prev_row_res == row_res) prev_word_res = word_res;
1542 word_res = word_res_it.data();
1546 word_res_it.forward();
1549 WERD_RES_IT wr_it(&row_res->word_res_list);
1550 for (wr_it.mark_cycle_pt(); !wr_it.cycled_list(); wr_it.forward()) {
1551 if (!wr_it.data()->part_of_combo) {
1552 if (prev_row_res == row_res) prev_word_res = word_res;
1553 word_res = wr_it.data();
1574 WERD_RES *PAGE_RES_IT::internal_forward(
bool new_block,
bool empty_ok) {
1575 bool new_row =
false;
1577 prev_block_res = block_res;
1578 prev_row_res = row_res;
1579 prev_word_res = word_res;
1580 block_res = next_block_res;
1581 row_res = next_row_res;
1582 word_res = next_word_res;
1583 next_block_res =
NULL;
1584 next_row_res =
NULL;
1585 next_word_res =
NULL;
1587 while (!block_res_it.cycled_list()) {
1590 row_res_it.set_to_list(&block_res_it.data()->row_res_list);
1591 row_res_it.mark_cycle_pt();
1592 if (row_res_it.empty() && empty_ok) {
1593 next_block_res = block_res_it.data();
1598 while (!row_res_it.cycled_list()) {
1601 word_res_it.set_to_list(&row_res_it.data()->word_res_list);
1602 word_res_it.mark_cycle_pt();
1605 while (!word_res_it.cycled_list() && word_res_it.data()->part_of_combo)
1606 word_res_it.forward();
1607 if (!word_res_it.cycled_list()) {
1608 next_block_res = block_res_it.data();
1609 next_row_res = row_res_it.data();
1610 next_word_res = word_res_it.data();
1611 word_res_it.forward();
1615 row_res_it.forward();
1619 block_res_it.forward();
1624 if (page_res !=
NULL && page_res->prev_word_best_choice !=
NULL) {
1625 *page_res->prev_word_best_choice =
1626 (new_block || prev_word_res ==
NULL) ?
NULL : prev_word_res->best_choice;
1638 if (!row)
return NULL;
1639 for (restart_page(); this->row() != row; forward()) {
1652 while (block_res == next_block_res &&
1653 (next_row_res !=
NULL && next_row_res->row !=
NULL &&
1654 row_res->row->para() == next_row_res->row->para())) {
1655 internal_forward(
false,
true);
1657 return internal_forward(
false,
true);
1667 while (block_res == next_block_res) {
1668 internal_forward(
false,
true);
1670 return internal_forward(
false,
true);
1674 inT16 chars_in_word;
1675 inT16 rejects_in_word = 0;
1677 chars_in_word = word_res->reject_map.length ();
1678 page_res->char_count += chars_in_word;
1679 block_res->char_count += chars_in_word;
1680 row_res->char_count += chars_in_word;
1682 rejects_in_word = word_res->reject_map.reject_count ();
1684 page_res->rej_count += rejects_in_word;
1685 block_res->rej_count += rejects_in_word;
1686 row_res->rej_count += rejects_in_word;
1687 if (chars_in_word == rejects_in_word)
1688 row_res->whole_word_rej_count += rejects_in_word;
BLOB_CHOICE_LIST * GetBlobChoices(int index) const
const double kMaxWordSizeRatio
void SetupWordScript(const UNICHARSET &unicharset_in)
static void BreakPieces(const GenericVector< SEAM * > &seams, const GenericVector< TBLOB * > &blobs, int first, int last)
TBOX bounding_box() const
void InitForRetryRecognition(const WERD_RES &source)
GenericVector< STRING > correct_text
bool SetupForRecognition(const UNICHARSET &unicharset_in, tesseract::Tesseract *tesseract, Pix *pix, int norm_mode, const TBOX *norm_box, bool numeric_mode, bool use_body_size, bool allow_detailed_fx, ROW *row, const BLOCK *block)
void ReplaceBestChoice(WERD_CHOICE *choice)
BOOL8 flag(WERD_FLAGS mask) const
void ConsumeWordResults(WERD_RES *word)
void DebugWordChoices(bool debug, const char *word_to_debug)
GenericVector< int > blob_widths
void start_seam_list(TWERD *word, GenericVector< SEAM * > *seam_array)
WERD_CHOICE ** prev_word_best_choice
TBOX bounding_box() const
static int SortByXMiddle(const void *v1, const void *v2)
UNICHAR_ID BothHyphens(UNICHAR_ID id1, UNICHAR_ID id2)
bool HyphenBoxesOverlap(const TBOX &box1, const TBOX &box2)
static void JoinPieces(const GenericVector< SEAM * > &seams, const GenericVector< TBLOB * > &blobs, int first, int last)
void FakeWordFromRatings()
void DebugTopChoice(const char *msg) const
BlamerBundle * blamer_bundle
int cmp(const PAGE_RES_IT &other) const
C_BLOB_LIST * cblob_list()
int GetBlobsGap(int blob_index)
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
void FakeClassifyWord(int blob_count, BLOB_CHOICE **choices)
WERD_RES & operator=(const WERD_RES &source)
bool LogNewRawChoice(WERD_CHOICE *word_choice)
WERD_CHOICE_LIST best_choices
void SetupBasicsFromChoppedWord(const UNICHARSET &unicharset_in)
const UNICHARSET * uch_set
const FontInfo * fontinfo
WERD_RES * forward_block()
tesseract::Tesseract * tesseract
void ComputeAdaptionThresholds(float certainty_scale, float min_rating, float max_rating, float rating_margin, float *thresholds)
bool PiecesAllNatural(int start, int count) const
void set_unichar_id(UNICHAR_ID newunichar_id)
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
const UNICHAR_ID unichar_id(int index) const
void ReplaceCurrentWord(tesseract::PointerVector< WERD_RES > *words)
bool PrepareToInsertSeam(const GenericVector< SEAM * > &seams, const GenericVector< TBLOB * > &blobs, int insert_index, bool modify)
#define ELISTIZE(CLASSNAME)
void make_bad()
Set the fields in this choice to be default (bad) values.
bool operator==(const PAGE_RES_IT &other) const
UNICHAR_ID BothSpaces(UNICHAR_ID id1, UNICHAR_ID id2)
void operator=(const ELIST_LINK &)
const char * string() const
WERD_RES * forward_paragraph()
WERD_RES * start_page(bool empty_ok)
int state(int index) const
const STRING & unichar_string() const
bool ConditionalBlobMerge(TessResultCallback2< UNICHAR_ID, UNICHAR_ID, UNICHAR_ID > *class_cb, TessResultCallback2< bool, const TBOX &, const TBOX & > *box_cb)
void CloneChoppedToRebuild()
void PrintBestChoices() const
GenericVector< SEAM * > seam_array
const double kMaxLineSizeRatio
void FilterWordChoices(int debug_level)
const FontInfo * fontinfo2
ROW_LIST * row_list()
get rows
void SetAllScriptPositions(tesseract::ScriptPos position)
void MergeAdjacentBlobs(int index)
static BoxWord * CopyFromNormalized(TWERD *tessword)
GenericVector< int > blob_gaps
CRUNCH_MODE unlv_crunch_mode
void SetupBlobWidthsAndGaps()
void copy_on(WERD_RES *word_res)
void MakeCurrentWordFuzzy()
bool AlternativeChoiceAdjustmentsWorseThan(float threshold) const
tesseract::BoxWord * bln_boxes
void BestChoiceToCorrectText()
bool script_has_xheight() const
C_BLOB_LIST * rej_cblob_list()
void SetupFake(const UNICHARSET &uch)
POLY_BLOCK * poly_block() const
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
UNICHAR_ID unichar_id() const
bool Valid(const MATRIX &m) const
tesseract::BoxWord * box_word
float adjust_factor() const
UNICHAR_ID BothQuotes(UNICHAR_ID id1, UNICHAR_ID id2)
BLOB_CHOICE * FindMatchingChoice(UNICHAR_ID char_id, BLOB_CHOICE_LIST *bc_list)
BLOCK_RES_LIST block_res_list
void add_str_int(const char *str, int number)
const double kMaxWordGapRatio
const int kWordrecMaxNumJoinChunks
void UpdateStateForSplit(int blob_position)
void InsertSeam(int blob_number, SEAM *seam)
GenericVector< int > best_state
WERD_CHOICE * best_choice
int GetBlobsWidth(int start_blob, int last_blob)
BLOB_CHOICE * GetBlobChoice(int index) const
bool LogNewCookedChoice(int max_num_choices, bool debug, WERD_CHOICE *word_choice)
CLISTIZE(BLOCK_RES) ELISTIZE(ROW_RES) ELISTIZE(WERD_RES) static const double kStopperAmbiguityThresholdGain
WERD_RES * InsertSimpleCloneWord(const WERD_RES &clone_res, WERD *new_word)
bool HasAnySplits() const
static TWERD * PolygonalCopy(bool allow_detailed_fx, WERD *src)
void CopySimpleFields(const WERD_RES &source)
void SetScriptPositions()
int TotalOfStates() const
void set_flag(WERD_FLAGS mask, BOOL8 value)
void set_permuter(uinT8 perm)