40 SegSearch(word_res, &best_choice_bundle,
nullptr);
60 blamer_bundle, &pain_points, &pending);
64 if (blamer_bundle !=
nullptr &&
72 float pain_point_priority;
73 int num_futile_classifications = 0;
77 (blamer_bundle !=
nullptr &&
80 bool found_nothing =
true;
82 while ((pp_type = pain_points.
Deque(&pain_point, &pain_point_priority)) !=
86 pain_point.
row - pain_point.
col + 1);
91 found_nothing =
false;
101 &pending, word_res, &pain_points, blamer_bundle);
104 word_res, &pain_points, best_choice_bundle,
106 if (!best_choice_bundle->
updated) ++num_futile_classifications;
109 tprintf(
"num_futile_classifications %d\n", num_futile_classifications);
112 best_choice_bundle->
updated =
false;
117 blamer_bundle !=
nullptr &&
123 if (blamer_bundle !=
nullptr) {
129 tprintf(
"Done with SegSearch (AcceptableChoiceFound: %d)\n",
142 tprintf(
"Starting SegSearch on ratings matrix%s:\n",
161 if (blamer_bundle !=
nullptr) {
176 (*pending)[0].SetColumnClassified();
178 pain_points, best_choice_bundle, blamer_bundle);
182 float rating_cert_scale,
192 for (
int col = starting_col; col < ratings->
dimension(); ++col) {
193 if (!(*pending)[col].WorkToDo())
continue;
195 int last_row = std::min(ratings->
dimension() - 1,
197 if ((*pending)[col].SingleRow() >= 0) {
198 first_row = last_row = (*pending)[col].SingleRow();
201 tprintf(
"\n\nUpdateSegSearchNodes: col=%d, rows=[%d,%d], alljust=%d\n",
202 col, first_row, last_row,
203 (*pending)[col].IsRowJustClassified(INT32_MAX));
206 for (
int row = first_row; row <= last_row; ++row) {
208 BLOB_CHOICE_LIST *current_node = ratings->
get(col, row);
210 col == 0 ? nullptr : best_choice_bundle->
beam[col - 1];
211 if (current_node !=
nullptr &&
213 col, row, current_node, parent_node,
214 pain_points, word_res,
215 best_choice_bundle, blamer_bundle) &&
219 (*pending)[row + 1].RevisitWholeColumn();
221 tprintf(
"Added child col=%d to pending\n", row + 1);
226 if (best_choice_bundle->
best_vse !=
nullptr) {
230 best_choice_bundle->
best_vse, word_res);
233 best_choice_bundle->
best_vse, word_res);
239 for (
int col = 0; col < pending->
size(); ++col) {
240 (*pending)[col].Clear();
242 vse_it(&best_choice_bundle->
beam[col]->viterbi_state_entries);
243 for (vse_it.mark_cycle_pt(); !vse_it.cycled_list(); vse_it.forward()) {
244 vse_it.data()->updated =
false;
250 float pain_point_priority,
251 const MATRIX_COORD &pain_point,
const char* pain_point_type,
255 tprintf(
"Classifying pain point %s priority=%.4f, col=%d, row=%d\n",
256 pain_point_type, pain_point_priority,
257 pain_point.
col, pain_point.
row);
262 if (!pain_point.
Valid(*ratings)) {
267 pain_point.
col, pain_point.
row,
271 BLOB_CHOICE_LIST *lst = ratings->
get(pain_point.
col, pain_point.
row);
272 if (lst ==
nullptr) {
273 ratings->
put(pain_point.
col, pain_point.
row, classified);
279 BLOB_CHOICE_IT it(lst);
280 it.add_list_before(classified);
282 classified =
nullptr;
287 ratings->
get(pain_point.
col, pain_point.
row),
294 if (classified !=
nullptr && !classified->empty()) {
295 if (pain_point.
col > 0) {
306 (*pending)[pain_point.
col].SetBlobClassified(pain_point.
row);
317 for (
int col = 0; col < best_choice_bundle->
beam.size(); ++col) {
318 best_choice_bundle->
beam[col]->Clear();
322 best_choice_bundle->
best_vse =
nullptr;
324 (*pending)[0].SetColumnClassified();
325 for (
int i = 1; i < pending->
size(); ++i)
326 (*pending)[i].Clear();
333 pain_points->
Clear();
339 blamer_debug, pp_cb);
void print(const UNICHARSET &unicharset) const
bool GuidedSegsearchStillGoing() const
bool GeneratePainPoint(int col, int row, LMPainPointsType pp_type, float special_priority, bool ok_to_extend, float max_char_wh_ratio, WERD_RES *word_res)
double segsearch_max_char_wh_ratio
WERD_CHOICE * prev_word_best_choice_
void ProcessSegSearchPainPoint(float pain_point_priority, const MATRIX_COORD &pain_point, const char *pain_point_type, GenericVector< SegSearchPending > *pending, WERD_RES *word_res, LMPainPoints *pain_points, BlamerBundle *blamer_bundle)
int segsearch_max_pain_points
void SetChopperBlame(const WERD_RES *word, bool debug)
Struct to store information maintained by various language model components.
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
bool Valid(const MATRIX &m) const
void ResetNGramSearch(WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, GenericVector< SegSearchPending > *pending)
bool ChoiceIsCorrect(const WERD_CHOICE *word_choice) const
void InitForSegSearch(const WERD_CHOICE *best_choice, MATRIX *ratings, UNICHAR_ID wildcard_id, bool debug, STRING *debug_str, TessResultCallback2< bool, int, int > *pp_cb)
static const char * PainPointDescription(LMPainPointsType type)
bool GuidedSegsearchNeeded(const WERD_CHOICE *best_choice) const
void IncreaseBandSize(int bandwidth)
PointerVector< LanguageModelState > beam
std::unique_ptr< LanguageModel > language_model_
LMPainPointsType Deque(MATRIX_COORD *pp, float *priority)
void init_to_size(int size, const T &t)
void InitBlamerForSegSearch(WERD_RES *word_res, LMPainPoints *pain_points, BlamerBundle *blamer_bundle, STRING *blamer_debug)
void GenerateInitial(WERD_RES *word_res)
DLLSYM void tprintf(const char *format,...)
void put(ICOORD pos, const T &thing)
DANGERR fixpt
Places to try to fix the word suggested by ambiguity checking.
void DoSegSearch(WERD_RES *word_res)
void GenerateFromPath(float rating_cert_scale, ViterbiStateEntry *vse, WERD_RES *word_res)
void UpdateSegSearchNodes(float rating_cert_scale, int starting_col, GenericVector< SegSearchPending > *pending, WERD_RES *word_res, LMPainPoints *pain_points, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
GenericVector< SEAM * > seam_array
Bundle together all the things pertaining to the best choice/state.
void SetupCorrectSegmentation(const TWERD *word, bool debug)
bool Classified(int col, int row, int wildcard_id) const
ViterbiStateEntry * best_vse
Best ViterbiStateEntry and BLOB_CHOICE.
void InitialSegSearch(WERD_RES *word_res, LMPainPoints *pain_points, GenericVector< SegSearchPending > *pending, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
bool updated
Flag to indicate whether anything was changed.
bool assume_fixed_pitch_char_segment
bool SegSearchDone(int num_futile_classifications)
const UNICHARSET & getUnicharset() const
int segsearch_debug_level
bool wordrec_enable_assoc
void improve_by_chopping(float rating_cert_scale, WERD_RES *word, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle, LMPainPoints *pain_points, GenericVector< SegSearchPending > *pending)
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET ¤t_unicharset)
static void PrintSeams(const char *label, const GenericVector< SEAM *> &seams)
void FinishSegSearch(const WERD_CHOICE *best_choice, bool debug, STRING *debug_str)
bool wordrec_debug_blamer
virtual BLOB_CHOICE_LIST * classify_piece(const GenericVector< SEAM *> &seams, int16_t start, int16_t end, const char *description, TWERD *word, BlamerBundle *blamer_bundle)
void SegSearch(WERD_RES *word_res, BestChoiceBundle *best_choice_bundle, BlamerBundle *blamer_bundle)
WERD_CHOICE * best_choice
void GenerateFromAmbigs(const DANGERR &fixpt, ViterbiStateEntry *vse, WERD_RES *word_res)
bool GenerateForBlamer(double max_char_wh_ratio, WERD_RES *word_res, int col, int row)