From 58d9593094c251a63895e83e2a55b891488ec669 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 12 Dec 2016 17:23:59 +0100 Subject: [PATCH] wordrec: Replace NULL by nullptr Signed-off-by: Stefan Weil --- wordrec/associate.cpp | 6 +- wordrec/associate.h | 2 +- wordrec/chop.cpp | 30 +++--- wordrec/chopper.cpp | 90 ++++++++-------- wordrec/drawfx.cpp | 4 +- wordrec/findseam.cpp | 30 +++--- wordrec/language_model.cpp | 206 ++++++++++++++++++------------------- wordrec/language_model.h | 18 ++-- wordrec/lm_consistency.cpp | 2 +- wordrec/lm_consistency.h | 2 +- wordrec/lm_pain_points.cpp | 8 +- wordrec/lm_state.cpp | 2 +- wordrec/lm_state.h | 16 +-- wordrec/pieces.cpp | 10 +- wordrec/plotedges.cpp | 6 +- wordrec/render.cpp | 4 +- wordrec/segsearch.cpp | 30 +++--- wordrec/tface.cpp | 4 +- wordrec/wordclass.cpp | 2 +- wordrec/wordrec.cpp | 4 +- wordrec/wordrec.h | 4 +- 21 files changed, 240 insertions(+), 240 deletions(-) diff --git a/wordrec/associate.cpp b/wordrec/associate.cpp index 44389e4be9..0dc3b7a3c9 100644 --- a/wordrec/associate.cpp +++ b/wordrec/associate.cpp @@ -44,7 +44,7 @@ void AssociateUtils::ComputeStats(int col, int row, AssociateStats *stats) { stats->Clear(); - ASSERT_HOST(word_res != NULL); + ASSERT_HOST(word_res != nullptr); if (word_res->blob_widths.empty()) { return; } @@ -55,7 +55,7 @@ void AssociateUtils::ComputeStats(int col, int row, float normalizing_height = kBlnXHeight; ROW* blob_row = word_res->blob_row; // TODO(rays/daria) Can unicharset.script_has_xheight be useful here? - if (fixed_pitch && blob_row != NULL) { + if (fixed_pitch && blob_row != nullptr) { // For fixed pitch language like CJK, we use the full text height // as the normalizing factor so we are not dependent on xheight // calculation. @@ -126,7 +126,7 @@ void AssociateUtils::ComputeStats(int col, int row, // the means and variances are computed for the path so far (not // considering characters to the right of the last character on the path). stats->full_wh_ratio = wh_ratio + right_gap; - if (parent_stats != NULL) { + if (parent_stats != nullptr) { stats->full_wh_ratio_total = (parent_stats->full_wh_ratio_total + stats->full_wh_ratio); float mean = diff --git a/wordrec/associate.h b/wordrec/associate.h index 10b1e0b7d9..12f19c745c 100644 --- a/wordrec/associate.h +++ b/wordrec/associate.h @@ -97,7 +97,7 @@ class AssociateUtils { // information in the (col, row) entry of the ratings matrix is not used). // // Note: the function assumes that word_res, stats and - // associate_cost pointers are not NULL. + // associate_cost pointers are not nullptr. static void ComputeStats(int col, int row, const AssociateStats *parent_stats, int parent_path_length, diff --git a/wordrec/chop.cpp b/wordrec/chop.cpp index 9ef796fbc0..a732895009 100644 --- a/wordrec/chop.cpp +++ b/wordrec/chop.cpp @@ -124,7 +124,7 @@ int Wordrec::angle_change(EDGEPT *point1, EDGEPT *point2, EDGEPT *point3) { EDGEPT *Wordrec::pick_close_point(EDGEPT *critical_point, EDGEPT *vertical_point, int *best_dist) { - EDGEPT *best_point = NULL; + EDGEPT *best_point = nullptr; int this_distance; int found_better; @@ -161,8 +161,8 @@ EDGEPT *Wordrec::pick_close_point(EDGEPT *critical_point, */ void Wordrec::prioritize_points(TESSLINE *outline, PointHeap* points) { EDGEPT *this_point; - EDGEPT *local_min = NULL; - EDGEPT *local_max = NULL; + EDGEPT *local_min = nullptr; + EDGEPT *local_max = nullptr; this_point = outline->loop; local_min = this_point; @@ -170,37 +170,37 @@ void Wordrec::prioritize_points(TESSLINE *outline, PointHeap* points) { do { if (this_point->vec.y < 0) { /* Look for minima */ - if (local_max != NULL) + if (local_max != nullptr) new_max_point(local_max, points); else if (is_inside_angle (this_point)) add_point_to_list(points, this_point); - local_max = NULL; + local_max = nullptr; local_min = this_point->next; } else if (this_point->vec.y > 0) { /* Look for maxima */ - if (local_min != NULL) + if (local_min != nullptr) new_min_point(local_min, points); else if (is_inside_angle (this_point)) add_point_to_list(points, this_point); - local_min = NULL; + local_min = nullptr; local_max = this_point->next; } else { /* Flat area */ - if (local_max != NULL) { + if (local_max != nullptr) { if (local_max->prev->vec.y != 0) { new_max_point(local_max, points); } local_max = this_point->next; - local_min = NULL; + local_min = nullptr; } else { if (local_min->prev->vec.y != 0) { new_min_point(local_min, points); } local_min = this_point->next; - local_max = NULL; + local_max = nullptr; } } @@ -216,7 +216,7 @@ void Wordrec::prioritize_points(TESSLINE *outline, PointHeap* points) { * * Found a new minimum point try to decide whether to save it or not. * Return the new value for the local minimum. If a point is saved then - * the local minimum is reset to NULL. + * the local minimum is reset to nullptr. */ void Wordrec::new_min_point(EDGEPT *local_min, PointHeap* points) { int16_t dir; @@ -240,7 +240,7 @@ void Wordrec::new_min_point(EDGEPT *local_min, PointHeap* points) { * * Found a new minimum point try to decide whether to save it or not. * Return the new value for the local minimum. If a point is saved then - * the local minimum is reset to NULL. + * the local minimum is reset to nullptr. */ void Wordrec::new_max_point(EDGEPT *local_max, PointHeap* points) { int16_t dir; @@ -280,7 +280,7 @@ void Wordrec::vertical_projection_point(EDGEPT *split_point, EDGEPT *target_poin int x = split_point->pos.x; /* X value of vertical */ int best_dist = LARGE_DISTANCE;/* Best point found */ - if (*best_point != NULL) + if (*best_point != nullptr) best_dist = edgept_dist(split_point, *best_point); p = target_point; @@ -291,13 +291,13 @@ void Wordrec::vertical_projection_point(EDGEPT *split_point, EDGEPT *target_poin !same_point(split_point->pos, p->pos) && !same_point(split_point->pos, p->next->pos) && !p->IsChopPt() && - (*best_point == NULL || !same_point((*best_point)->pos, p->pos))) { + (*best_point == nullptr || !same_point((*best_point)->pos, p->pos))) { if (near_point(split_point, p, p->next, &this_edgept)) { new_point_it.add_before_then_move(this_edgept); } - if (*best_point == NULL) + if (*best_point == nullptr) best_dist = edgept_dist (split_point, this_edgept); this_edgept = diff --git a/wordrec/chopper.cpp b/wordrec/chopper.cpp index 1aeee2419c..39db921223 100644 --- a/wordrec/chopper.cpp +++ b/wordrec/chopper.cpp @@ -66,7 +66,7 @@ static const int kMaxNumChunks = 64; void preserve_outline(EDGEPT *start) { EDGEPT *srcpt; - if (start == NULL) + if (start == nullptr) return; srcpt = start; do { @@ -82,7 +82,7 @@ void preserve_outline(EDGEPT *start) { void preserve_outline_tree(TESSLINE *srcline) { TESSLINE *outline; - for (outline = srcline; outline != NULL; outline = outline->next) { + for (outline = srcline; outline != nullptr; outline = outline->next) { preserve_outline (outline->loop); } } @@ -97,8 +97,8 @@ EDGEPT *restore_outline(EDGEPT *start) { EDGEPT *srcpt; EDGEPT *real_start; - if (start == NULL) - return NULL; + if (start == nullptr) + return nullptr; srcpt = start; do { if (srcpt->flags[1] == 2) @@ -122,18 +122,18 @@ EDGEPT *restore_outline(EDGEPT *start) { void restore_outline_tree(TESSLINE *srcline) { TESSLINE *outline; - for (outline = srcline; outline != NULL; outline = outline->next) { + for (outline = srcline; outline != nullptr; outline = outline->next) { outline->loop = restore_outline (outline->loop); outline->start = outline->loop->pos; } } // Helper runs all the checks on a seam to make sure it is valid. -// Returns the seam if OK, otherwise deletes the seam and returns NULL. +// Returns the seam if OK, otherwise deletes the seam and returns nullptr. static SEAM* CheckSeam(int debug_level, int32_t blob_number, TWERD* word, TBLOB* blob, TBLOB* other_blob, const GenericVector& seams, SEAM* seam) { - if (seam == NULL || blob->outlines == NULL || other_blob->outlines == NULL || + if (seam == nullptr || blob->outlines == nullptr || other_blob->outlines == nullptr || total_containment(blob, other_blob) || check_blob(other_blob) || !seam->ContainedByBlob(*blob) || !seam->ContainedByBlob(*other_blob) || any_shared_split_points(seams, seam) || @@ -142,7 +142,7 @@ static SEAM* CheckSeam(int debug_level, int32_t blob_number, TWERD* word, if (seam) { seam->UndoSeam(blob, other_blob); delete seam; - seam = NULL; + seam = nullptr; #ifndef GRAPHICS_DISABLED if (debug_level) { if (debug_level >2) @@ -153,7 +153,7 @@ static SEAM* CheckSeam(int debug_level, int32_t blob_number, TWERD* word, } else { delete other_blob; } - return NULL; + return nullptr; } return seam; } @@ -175,17 +175,17 @@ SEAM *Wordrec::attempt_blob_chop(TWERD *word, TBLOB *blob, int32_t blob_number, // Insert it into the word. word->blobs.insert(other_blob, blob_number + 1); - SEAM *seam = NULL; + SEAM *seam = nullptr; if (prioritize_division) { TPOINT location; if (divisible_blob(blob, italic_blob, &location)) { seam = new SEAM(0.0f, location); } } - if (seam == NULL) + if (seam == nullptr) seam = pick_good_seam(blob); if (chop_debug) { - if (seam != NULL) + if (seam != nullptr) seam->Print("Good seam picked="); else tprintf("\n** no seam picked *** \n"); @@ -196,7 +196,7 @@ SEAM *Wordrec::attempt_blob_chop(TWERD *word, TBLOB *blob, int32_t blob_number, seam = CheckSeam(chop_debug, blob_number, word, blob, other_blob, seams, seam); - if (seam == NULL) { + if (seam == nullptr) { if (repair_unchopped_blobs) restore_outline_tree(blob->outlines); if (allow_blob_division && !prioritize_division) { @@ -212,7 +212,7 @@ SEAM *Wordrec::attempt_blob_chop(TWERD *word, TBLOB *blob, int32_t blob_number, } } } - if (seam != NULL) { + if (seam != nullptr) { // Make sure this seam doesn't get chopped again. seam->Finalize(); } @@ -241,8 +241,8 @@ SEAM *Wordrec::chop_overlapping_blob(const GenericVector& boxes, botright.y = blob->bounding_box().bottom(); TPOINT original_topleft, original_botright; - word_res->denorm.DenormTransform(NULL, topleft, &original_topleft); - word_res->denorm.DenormTransform(NULL, botright, &original_botright); + word_res->denorm.DenormTransform(nullptr, topleft, &original_topleft); + word_res->denorm.DenormTransform(nullptr, botright, &original_botright); TBOX original_box = TBOX(original_topleft.x, original_botright.y, original_botright.x, original_topleft.y); @@ -261,13 +261,13 @@ SEAM *Wordrec::chop_overlapping_blob(const GenericVector& boxes, (!almost_equal_box && num_overlap > 1)) { SEAM *seam = attempt_blob_chop(word, blob, *blob_number, italic_blob, word_res->seam_array); - if (seam != NULL) + if (seam != nullptr) return seam; } } *blob_number = -1; - return NULL; + return nullptr; } } // namespace tesseract @@ -298,15 +298,15 @@ int check_blob(TBLOB *blob) { TESSLINE *outline; EDGEPT *edgept; - for (outline = blob->outlines; outline != NULL; outline = outline->next) { + for (outline = blob->outlines; outline != nullptr; outline = outline->next) { edgept = outline->loop; do { - if (edgept == NULL) + if (edgept == nullptr) break; edgept = edgept->next; } while (edgept != outline->loop); - if (edgept == NULL) + if (edgept == nullptr) return 1; } return 0; @@ -333,7 +333,7 @@ SEAM* Wordrec::improve_one_blob(const GenericVector& blob_choices, WERD_RES* word, int* blob_number) { float rating_ceiling = MAX_FLOAT32; - SEAM *seam = NULL; + SEAM *seam = nullptr; do { *blob_number = select_blob_to_split_from_fixpt(fixpt); if (chop_debug) tprintf("blob_number from fixpt = %d\n", *blob_number); @@ -346,15 +346,15 @@ SEAM* Wordrec::improve_one_blob(const GenericVector& blob_choices, } if (chop_debug) tprintf("blob_number = %d\n", *blob_number); if (*blob_number == -1) - return NULL; + return nullptr; // TODO(rays) it may eventually help to allow italic_blob to be true, seam = chop_numbered_blob(word->chopped_word, *blob_number, italic_blob, word->seam_array); - if (seam != NULL) + if (seam != nullptr) return seam; // Success! - if (blob_choices[*blob_number] == NULL) - return NULL; + if (blob_choices[*blob_number] == nullptr) + return nullptr; if (!split_point_from_dict) { // We chopped the worst rated blob, try something else next time. rating_ceiling = blob_choices[*blob_number]->rating(); @@ -377,7 +377,7 @@ SEAM* Wordrec::chop_one_blob(const GenericVector& boxes, if (prioritize_division) { return chop_overlapping_blob(boxes, true, word_res, blob_number); } else { - return improve_one_blob(blob_choices, NULL, false, true, word_res, + return improve_one_blob(blob_choices, nullptr, false, true, word_res, blob_number); } } @@ -392,10 +392,10 @@ SEAM* Wordrec::chop_one_blob(const GenericVector& boxes, */ void Wordrec::chop_word_main(WERD_RES *word) { int num_blobs = word->chopped_word->NumBlobs(); - if (word->ratings == NULL) { + if (word->ratings == nullptr) { word->ratings = new MATRIX(num_blobs, wordrec_max_join_chunks); } - if (word->ratings->get(0, 0) == NULL) { + if (word->ratings->get(0, 0) == nullptr) { // Run initial classification. for (int b = 0; b < num_blobs; ++b) { BLOB_CHOICE_LIST* choices = classify_piece(word->seam_array, b, b, @@ -409,7 +409,7 @@ void Wordrec::chop_word_main(WERD_RES *word) { for (int row = col; row < word->ratings->dimension() && row < col + word->ratings->bandwidth(); ++row) { BLOB_CHOICE_LIST* choices = word->ratings->get(col, row); - if (choices != NULL) { + if (choices != nullptr) { BLOB_CHOICE_IT bc_it(choices); for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) { bc_it.data()->set_matrix_cell(col, row); @@ -423,7 +423,7 @@ void Wordrec::chop_word_main(WERD_RES *word) { BestChoiceBundle best_choice_bundle(word->ratings->dimension()); SegSearch(word, &best_choice_bundle, word->blamer_bundle); - if (word->best_choice == NULL) { + if (word->best_choice == nullptr) { // SegSearch found no valid paths, so just use the leading diagonal. word->FakeWordFromRatings(TOP_CHOICE_PERM); } @@ -435,7 +435,7 @@ void Wordrec::chop_word_main(WERD_RES *word) { getDict().reset_hyphen_vars(true); } - if (word->blamer_bundle != NULL && this->fill_lattice_ != NULL) { + if (word->blamer_bundle != nullptr && this->fill_lattice_ != nullptr) { CallFillLattice(*word->ratings, word->best_choices, *word->uch_set, word->blamer_bundle); } @@ -467,8 +467,8 @@ void Wordrec::improve_by_chopping(float rating_cert_scale, int num_blobs = word->ratings->dimension(); for (int i = 0; i < num_blobs; ++i) { BLOB_CHOICE_LIST* choices = word->ratings->get(i, i); - if (choices == NULL || choices->empty()) { - blob_choices.push_back(NULL); + if (choices == nullptr || choices->empty()) { + blob_choices.push_back(nullptr); } else { BLOB_CHOICE_IT bc_it(choices); blob_choices.push_back(bc_it.data()); @@ -476,7 +476,7 @@ void Wordrec::improve_by_chopping(float rating_cert_scale, } SEAM* seam = improve_one_blob(blob_choices, &best_choice_bundle->fixpt, false, false, word, &blob_number); - if (seam == NULL) break; + if (seam == nullptr) break; // A chop has been made. We have to correct all the data structures to // take into account the extra bottom-level blob. // Put the seam into the seam_array and correct everything else on the @@ -518,10 +518,10 @@ void Wordrec::improve_by_chopping(float rating_cert_scale, // top choice and is a dictionary word (i.e. language model could not have // helped). Otherwise blame the tradeoff between the classifier and // the old language model (permuters). - if (word->blamer_bundle != NULL && + if (word->blamer_bundle != nullptr && word->blamer_bundle->incorrect_result_reason() == IRR_CORRECT && !word->blamer_bundle->ChoiceIsCorrect(word->best_choice)) { - bool valid_permuter = word->best_choice != NULL && + bool valid_permuter = word->best_choice != nullptr && Dict::valid_word_permuter(word->best_choice->permuter(), false); word->blamer_bundle->BlameClassifierOrLangModel(word, getDict().getUnicharset(), @@ -546,7 +546,7 @@ int Wordrec::select_blob_to_split( int worst_index = -1; float worst_near_fragment = -MAX_FLOAT32; int worst_index_near_fragment = -1; - const CHAR_FRAGMENT **fragments = NULL; + const CHAR_FRAGMENT **fragments = nullptr; if (chop_debug) { if (rating_ceiling < MAX_FLOAT32) @@ -557,27 +557,27 @@ int Wordrec::select_blob_to_split( if (split_next_to_fragment && blob_choices.size() > 0) { fragments = new const CHAR_FRAGMENT *[blob_choices.length()]; - if (blob_choices[0] != NULL) { + if (blob_choices[0] != nullptr) { fragments[0] = getDict().getUnicharset().get_fragment( blob_choices[0]->unichar_id()); } else { - fragments[0] = NULL; + fragments[0] = nullptr; } } for (x = 0; x < blob_choices.size(); ++x) { - if (blob_choices[x] == NULL) { + if (blob_choices[x] == nullptr) { delete[] fragments; return x; } else { blob_choice = blob_choices[x]; // Populate fragments for the following position. if (split_next_to_fragment && x+1 < blob_choices.size()) { - if (blob_choices[x + 1] != NULL) { + if (blob_choices[x + 1] != nullptr) { fragments[x + 1] = getDict().getUnicharset().get_fragment( blob_choices[x + 1]->unichar_id()); } else { - fragments[x + 1] = NULL; + fragments[x + 1] = nullptr; } } if (blob_choice->rating() < rating_ceiling && @@ -591,9 +591,9 @@ int Wordrec::select_blob_to_split( // Update worst_near_fragment and worst_index_near_fragment. bool expand_following_fragment = (x + 1 < blob_choices.size() && - fragments[x+1] != NULL && !fragments[x+1]->is_beginning()); + fragments[x+1] != nullptr && !fragments[x+1]->is_beginning()); bool expand_preceding_fragment = - (x > 0 && fragments[x-1] != NULL && !fragments[x-1]->is_ending()); + (x > 0 && fragments[x-1] != nullptr && !fragments[x-1]->is_ending()); if ((expand_following_fragment || expand_preceding_fragment) && blob_choice->rating() > worst_near_fragment) { worst_index_near_fragment = x; diff --git a/wordrec/drawfx.cpp b/wordrec/drawfx.cpp index be14934919..32604668eb 100644 --- a/wordrec/drawfx.cpp +++ b/wordrec/drawfx.cpp @@ -48,8 +48,8 @@ EXTERN STRING_VAR (fx_debugfile, DEBUG_WIN_NAME, "Name of debugfile"); -EXTERN ScrollView* fx_win = NULL; -EXTERN FILE *fx_debug = NULL; +EXTERN ScrollView* fx_win = nullptr; +EXTERN FILE *fx_debug = nullptr; /********************************************************************** * create_fx_win diff --git a/wordrec/findseam.cpp b/wordrec/findseam.cpp index 66ce7cc0dd..05c800a4aa 100644 --- a/wordrec/findseam.cpp +++ b/wordrec/findseam.cpp @@ -62,13 +62,13 @@ namespace tesseract { **********************************************************************/ void Wordrec::add_seam_to_queue(float new_priority, SEAM *new_seam, SeamQueue* seams) { - if (new_seam == NULL) return; + if (new_seam == nullptr) return; if (chop_debug) { tprintf("Pushing new seam with priority %g :", new_priority); new_seam->Print("seam: "); } if (seams->size() >= MAX_NUM_SEAMS) { - SeamPair old_pair(0, NULL); + SeamPair old_pair(0, nullptr); if (seams->PopWorst(&old_pair) && old_pair.key() <= new_priority) { if (chop_debug) { tprintf("Old seam staying with priority %g\n", old_pair.key()); @@ -96,7 +96,7 @@ void Wordrec::add_seam_to_queue(float new_priority, SEAM *new_seam, * evaluated and combined until a good enough seam is found. If no * further good seams are being found then this function returns to the * caller, who will send more splits. If this function is called with - * a split of NULL, then no further splits can be supplied by the + * a split of nullptr, then no further splits can be supplied by the * caller. **********************************************************************/ void Wordrec::choose_best_seam(SeamQueue *seam_queue, const SPLIT *split, @@ -107,7 +107,7 @@ void Wordrec::choose_best_seam(SeamQueue *seam_queue, const SPLIT *split, float my_priority; /* Add seam of split */ my_priority = priority; - if (split != NULL) { + if (split != nullptr) { TPOINT split_point = split->point1->pos; split_point += split->point2->pos; split_point /= 2; @@ -134,7 +134,7 @@ void Wordrec::choose_best_seam(SeamQueue *seam_queue, const SPLIT *split, seam->Print(str); } - if ((*seam_result == NULL || (*seam_result)->priority() > my_priority) && + if ((*seam_result == nullptr || (*seam_result)->priority() > my_priority) && my_priority < chop_ok_split) { /* No crossing */ if (seam->IsHealthy(*blob, chop_min_outline_points, @@ -144,7 +144,7 @@ void Wordrec::choose_best_seam(SeamQueue *seam_queue, const SPLIT *split, (*seam_result)->set_priority(my_priority); } else { delete seam; - seam = NULL; + seam = nullptr; my_priority = BAD_PRIORITY; } } @@ -216,7 +216,7 @@ SEAM *Wordrec::pick_good_seam(TBLOB *blob) { SeamPile seam_pile(chop_seam_pile_size); EDGEPT *points[MAX_NUM_POINTS]; EDGEPT_CLIST new_points; - SEAM *seam = NULL; + SEAM *seam = nullptr; TESSLINE *outline; int16_t num_points = 0; @@ -233,7 +233,7 @@ SEAM *Wordrec::pick_good_seam(TBLOB *blob) { while (!point_heap.empty() && num_points < MAX_NUM_POINTS) { points[num_points++] = point_heap.PeekTop().data; - point_heap.Pop(NULL); + point_heap.Pop(nullptr); } /* Initialize queue */ @@ -243,17 +243,17 @@ SEAM *Wordrec::pick_good_seam(TBLOB *blob) { try_vertical_splits(points, num_points, &new_points, &seam_queue, &seam_pile, &seam, blob); - if (seam == NULL) { - choose_best_seam(&seam_queue, NULL, BAD_PRIORITY, &seam, blob, &seam_pile); + if (seam == nullptr) { + choose_best_seam(&seam_queue, nullptr, BAD_PRIORITY, &seam, blob, &seam_pile); } else if (seam->priority() > chop_good_split) { - choose_best_seam(&seam_queue, NULL, seam->priority(), &seam, blob, + choose_best_seam(&seam_queue, nullptr, seam->priority(), &seam, blob, &seam_pile); } EDGEPT_C_IT it(&new_points); for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { EDGEPT *inserted_point = it.data(); - if (seam == NULL || !seam->UsesPoint(inserted_point)) { + if (seam == nullptr || !seam->UsesPoint(inserted_point)) { for (outline = blob->outlines; outline; outline = outline->next) { if (outline->loop == inserted_point) { outline->loop = outline->loop->next; @@ -266,7 +266,7 @@ SEAM *Wordrec::pick_good_seam(TBLOB *blob) { if (seam) { if (seam->priority() > chop_ok_split) { delete seam; - seam = NULL; + seam = nullptr; } #ifndef GRAPHICS_DISABLED else if (wordrec_display_splits) { @@ -338,13 +338,13 @@ void Wordrec::try_vertical_splits(EDGEPT * points[MAX_NUM_POINTS], SeamPile* seam_pile, SEAM ** seam, TBLOB * blob) { - EDGEPT *vertical_point = NULL; + EDGEPT *vertical_point = nullptr; int16_t x; PRIORITY priority; TESSLINE *outline; for (x = 0; x < num_points; x++) { - vertical_point = NULL; + vertical_point = nullptr; for (outline = blob->outlines; outline; outline = outline->next) { vertical_projection_point(points[x], outline->loop, &vertical_point, new_points); diff --git a/wordrec/language_model.cpp b/wordrec/language_model.cpp index e1276640cb..e967f37f27 100644 --- a/wordrec/language_model.cpp +++ b/wordrec/language_model.cpp @@ -122,7 +122,7 @@ LanguageModel::LanguageModel(const UnicityTable *fontinfo_table, fixed_pitch_(false), max_char_wh_ratio_(0.0), acceptable_choice_found_(false) { - ASSERT_HOST(dict_ != NULL); + ASSERT_HOST(dict_ != nullptr); } LanguageModel::~LanguageModel() { delete dawg_args_.updated_dawgs; } @@ -145,7 +145,7 @@ void LanguageModel::InitForWord(const WERD_CHOICE *prev_word, // Fill prev_word_str_ with the last language_model_ngram_order // unichars from prev_word. if (language_model_ngram_on) { - if (prev_word != NULL && prev_word->unichar_string() != NULL) { + if (prev_word != nullptr && prev_word->unichar_string() != nullptr) { prev_word_str_ = prev_word->unichar_string(); if (language_model_ngram_space_delimited_language) prev_word_str_ += ' '; } else { @@ -169,11 +169,11 @@ void LanguageModel::InitForWord(const WERD_CHOICE *prev_word, */ static void ScanParentsForCaseMix(const UNICHARSET& unicharset, LanguageModelState* parent_node) { - if (parent_node == NULL) return; + if (parent_node == nullptr) return; ViterbiStateEntry_IT vit(&parent_node->viterbi_state_entries); for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) { ViterbiStateEntry* vse = vit.data(); - vse->competing_vse = NULL; + vse->competing_vse = nullptr; UNICHAR_ID unichar_id = vse->curr_b->unichar_id(); if (unicharset.get_isupper(unichar_id) || unicharset.get_islower(unichar_id)) { @@ -266,11 +266,11 @@ bool LanguageModel::UpdateState( bool new_changed = false; float denom = (language_model_ngram_on) ? ComputeDenom(curr_list) : 1.0f; const UNICHARSET& unicharset = dict_->getUnicharset(); - BLOB_CHOICE *first_lower = NULL; - BLOB_CHOICE *first_upper = NULL; - BLOB_CHOICE *first_digit = NULL; + BLOB_CHOICE *first_lower = nullptr; + BLOB_CHOICE *first_upper = nullptr; + BLOB_CHOICE *first_digit = nullptr; bool has_alnum_mix = false; - if (parent_node != NULL) { + if (parent_node != nullptr) { int result = SetTopParentLowerUpperDigit(parent_node); if (result < 0) { if (language_model_debug_level > 0) @@ -284,7 +284,7 @@ bool LanguageModel::UpdateState( &first_digit)) has_alnum_mix = false;; ScanParentsForCaseMix(unicharset, parent_node); - if (language_model_debug_level > 3 && parent_node != NULL) { + if (language_model_debug_level > 3 && parent_node != nullptr) { parent_node->Print("Parent viterbi list"); } LanguageModelState *curr_state = best_choice_bundle->beam[curr_row]; @@ -296,7 +296,7 @@ bool LanguageModel::UpdateState( BLOB_CHOICE* choice = c_it.data(); // TODO(antonova): make sure commenting this out if ok for ngram // model scoring (I think this was introduced to fix ngram model quirks). - // Skip NULL unichars unless it is the only choice. + // Skip nullptr unichars unless it is the only choice. //if (!curr_list->singleton() && c_it.data()->unichar_id() == 0) continue; UNICHAR_ID unichar_id = choice->unichar_id(); if (unicharset.get_fragment(unichar_id)) { @@ -310,7 +310,7 @@ bool LanguageModel::UpdateState( if (first_upper == choice) blob_choice_flags |= kUpperCaseFlag; if (first_digit == choice) blob_choice_flags |= kDigitFlag; - if (parent_node == NULL) { + if (parent_node == nullptr) { // Process the beginning of a word. // If there is a better case variant that is not distinguished by size, // skip this blob choice, as we have no choice but to accept the result @@ -329,19 +329,19 @@ bool LanguageModel::UpdateState( blob_choice_flags |= kLowerCaseFlag; new_changed |= AddViterbiStateEntry( blob_choice_flags, denom, word_end, curr_col, curr_row, - choice, curr_state, NULL, pain_points, + choice, curr_state, nullptr, pain_points, word_res, best_choice_bundle, blamer_bundle); } else { // Get viterbi entries from each parent ViterbiStateEntry. vit.set_to_list(&parent_node->viterbi_state_entries); int vit_counter = 0; vit.mark_cycle_pt(); - ViterbiStateEntry* parent_vse = NULL; + ViterbiStateEntry* parent_vse = nullptr; LanguageModelFlagsType top_choice_flags; while ((parent_vse = GetNextParentVSE(just_classified, has_alnum_mix, c_it.data(), blob_choice_flags, unicharset, word_res, &vit, - &top_choice_flags)) != NULL) { + &top_choice_flags)) != nullptr) { // Skip pruned entries and do not look at prunable entries if already // examined language_model_viterbi_list_max_num_prunable of those. if (PrunablePath(*parent_vse) && @@ -380,28 +380,28 @@ bool LanguageModel::GetTopLowerUpperDigit(BLOB_CHOICE_LIST *curr_list, BLOB_CHOICE **first_digit) const { BLOB_CHOICE_IT c_it(curr_list); const UNICHARSET &unicharset = dict_->getUnicharset(); - BLOB_CHOICE *first_unichar = NULL; + BLOB_CHOICE *first_unichar = nullptr; for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) { UNICHAR_ID unichar_id = c_it.data()->unichar_id(); if (unicharset.get_fragment(unichar_id)) continue; // skip fragments - if (first_unichar == NULL) first_unichar = c_it.data(); - if (*first_lower == NULL && unicharset.get_islower(unichar_id)) { + if (first_unichar == nullptr) first_unichar = c_it.data(); + if (*first_lower == nullptr && unicharset.get_islower(unichar_id)) { *first_lower = c_it.data(); } - if (*first_upper == NULL && unicharset.get_isalpha(unichar_id) && + if (*first_upper == nullptr && unicharset.get_isalpha(unichar_id) && !unicharset.get_islower(unichar_id)) { *first_upper = c_it.data(); } - if (*first_digit == NULL && unicharset.get_isdigit(unichar_id)) { + if (*first_digit == nullptr && unicharset.get_isdigit(unichar_id)) { *first_digit = c_it.data(); } } - ASSERT_HOST(first_unichar != NULL); - bool mixed = (*first_lower != NULL || *first_upper != NULL) && - *first_digit != NULL; - if (*first_lower == NULL) *first_lower = first_unichar; - if (*first_upper == NULL) *first_upper = first_unichar; - if (*first_digit == NULL) *first_digit = first_unichar; + ASSERT_HOST(first_unichar != nullptr); + bool mixed = (*first_lower != nullptr || *first_upper != nullptr) && + *first_digit != nullptr; + if (*first_lower == nullptr) *first_lower = first_unichar; + if (*first_upper == nullptr) *first_upper = first_unichar; + if (*first_digit == nullptr) *first_digit = first_unichar; return mixed; } @@ -416,12 +416,12 @@ bool LanguageModel::GetTopLowerUpperDigit(BLOB_CHOICE_LIST *curr_list, */ int LanguageModel::SetTopParentLowerUpperDigit( LanguageModelState *parent_node) const { - if (parent_node == NULL) return -1; + if (parent_node == nullptr) return -1; UNICHAR_ID top_id = INVALID_UNICHAR_ID; - ViterbiStateEntry* top_lower = NULL; - ViterbiStateEntry* top_upper = NULL; - ViterbiStateEntry* top_digit = NULL; - ViterbiStateEntry* top_choice = NULL; + ViterbiStateEntry* top_lower = nullptr; + ViterbiStateEntry* top_upper = nullptr; + ViterbiStateEntry* top_digit = nullptr; + ViterbiStateEntry* top_choice = nullptr; float lower_rating = 0.0f; float upper_rating = 0.0f; float digit_rating = 0.0f; @@ -436,43 +436,43 @@ int LanguageModel::SetTopParentLowerUpperDigit( UNICHAR_ID unichar_id = unichar_vse->curr_b->unichar_id(); float rating = unichar_vse->curr_b->rating(); while (unichar_id == INVALID_UNICHAR_ID && - unichar_vse->parent_vse != NULL) { + unichar_vse->parent_vse != nullptr) { unichar_vse = unichar_vse->parent_vse; unichar_id = unichar_vse->curr_b->unichar_id(); rating = unichar_vse->curr_b->rating(); } if (unichar_id != INVALID_UNICHAR_ID) { if (unicharset.get_islower(unichar_id)) { - if (top_lower == NULL || lower_rating > rating) { + if (top_lower == nullptr || lower_rating > rating) { top_lower = vse; lower_rating = rating; } } else if (unicharset.get_isalpha(unichar_id)) { - if (top_upper == NULL || upper_rating > rating) { + if (top_upper == nullptr || upper_rating > rating) { top_upper = vse; upper_rating = rating; } } else if (unicharset.get_isdigit(unichar_id)) { - if (top_digit == NULL || digit_rating > rating) { + if (top_digit == nullptr || digit_rating > rating) { top_digit = vse; digit_rating = rating; } } } - if (top_choice == NULL || top_rating > rating) { + if (top_choice == nullptr || top_rating > rating) { top_choice = vse; top_rating = rating; top_id = unichar_id; } } - if (top_choice == NULL) return -1; - bool mixed = (top_lower != NULL || top_upper != NULL) && - top_digit != NULL; - if (top_lower == NULL) top_lower = top_choice; + if (top_choice == nullptr) return -1; + bool mixed = (top_lower != nullptr || top_upper != nullptr) && + top_digit != nullptr; + if (top_lower == nullptr) top_lower = top_choice; top_lower->top_choice_flags |= kLowerCaseFlag; - if (top_upper == NULL) top_upper = top_choice; + if (top_upper == nullptr) top_upper = top_choice; top_upper->top_choice_flags |= kUpperCaseFlag; - if (top_digit == NULL) top_digit = top_choice; + if (top_digit == nullptr) top_digit = top_choice; top_digit->top_choice_flags |= kDigitFlag; top_choice->top_choice_flags |= kSmallestRatingFlag; if (top_id != INVALID_UNICHAR_ID && dict_->compound_marker(top_id) && @@ -528,7 +528,7 @@ ViterbiStateEntry* LanguageModel::GetNextParentVSE( // If there is a case mix of the same alpha in the parent list, then // competing_vse is non-null and will be used to determine whether // or not to bind the current blob choice. - if (parent_vse->competing_vse != NULL) { + if (parent_vse->competing_vse != nullptr) { const BLOB_CHOICE* competing_b = parent_vse->competing_vse->curr_b; UNICHAR_ID other_id = competing_b->unichar_id(); if (language_model_debug_level >= 5) { @@ -549,7 +549,7 @@ ViterbiStateEntry* LanguageModel::GetNextParentVSE( vse_it->forward(); return parent_vse; // This one is good! } - return NULL; // Ran out of possibilities. + return nullptr; // Ran out of possibilities. } bool LanguageModel::AddViterbiStateEntry( @@ -576,7 +576,7 @@ bool LanguageModel::AddViterbiStateEntry( tprintf("\n"); } // Check whether the list is full. - if (curr_state != NULL && + if (curr_state != nullptr && curr_state->viterbi_state_entries_length >= language_model_viterbi_list_max_size) { if (language_model_debug_level > 1) { @@ -592,15 +592,15 @@ bool LanguageModel::AddViterbiStateEntry( float outline_length = AssociateUtils::ComputeOutlineLength(rating_cert_scale_, *b); // Invoke Ngram language model component. - LanguageModelNgramInfo *ngram_info = NULL; + LanguageModelNgramInfo *ngram_info = nullptr; if (language_model_ngram_on) { ngram_info = GenerateNgramInfo( dict_->getUnicharset().id_to_unichar(b->unichar_id()), b->certainty(), denom, curr_col, curr_row, outline_length, parent_vse); - ASSERT_HOST(ngram_info != NULL); + ASSERT_HOST(ngram_info != nullptr); } - bool liked_by_language_model = dawg_info != NULL || - (ngram_info != NULL && !ngram_info->pruned); + bool liked_by_language_model = dawg_info != nullptr || + (ngram_info != nullptr && !ngram_info->pruned); // Quick escape if not liked by the language model, can't be consistent // xheight, and not top choice. if (!liked_by_language_model && top_choice_flags == 0) { @@ -614,7 +614,7 @@ bool LanguageModel::AddViterbiStateEntry( // Check consistency of the path and set the relevant consistency_info. LMConsistencyInfo consistency_info( - parent_vse != NULL ? &parent_vse->consistency_info : NULL); + parent_vse != nullptr ? &parent_vse->consistency_info : nullptr); // Start with just the x-height consistency, as it provides significant // pruning opportunity. consistency_info.ComputeXheightConsistency( @@ -638,7 +638,7 @@ bool LanguageModel::AddViterbiStateEntry( // Compute the rest of the consistency info. FillConsistencyInfo(curr_col, word_end, b, parent_vse, word_res, &consistency_info); - if (dawg_info != NULL && consistency_info.invalid_punc) { + if (dawg_info != nullptr && consistency_info.invalid_punc) { consistency_info.invalid_punc = false; // do not penalize dict words } @@ -646,7 +646,7 @@ bool LanguageModel::AddViterbiStateEntry( AssociateStats associate_stats; ComputeAssociateStats(curr_col, curr_row, max_char_wh_ratio_, parent_vse, word_res, &associate_stats); - if (parent_vse != NULL) { + if (parent_vse != nullptr) { associate_stats.shape_cost += parent_vse->associate_stats.shape_cost; associate_stats.bad_shape |= parent_vse->associate_stats.bad_shape; } @@ -656,7 +656,7 @@ bool LanguageModel::AddViterbiStateEntry( parent_vse, b, 0.0, outline_length, consistency_info, associate_stats, top_choice_flags, dawg_info, ngram_info, (language_model_debug_level > 0) ? - dict_->getUnicharset().id_to_unichar(b->unichar_id()) : NULL); + dict_->getUnicharset().id_to_unichar(b->unichar_id()) : nullptr); new_vse->cost = ComputeAdjustedPathCost(new_vse); if (language_model_debug_level >= 3) tprintf("Adjusted cost = %g\n", new_vse->cost); @@ -781,13 +781,13 @@ LanguageModelDawgInfo *LanguageModel::GenerateDawgInfo( int curr_col, int curr_row, const BLOB_CHOICE &b, const ViterbiStateEntry *parent_vse) { - // Initialize active_dawgs from parent_vse if it is not NULL. + // Initialize active_dawgs from parent_vse if it is not nullptr. // Otherwise use very_beginning_active_dawgs_. - if (parent_vse == NULL) { + if (parent_vse == nullptr) { dawg_args_.active_dawgs = &very_beginning_active_dawgs_; dawg_args_.permuter = NO_PERM; } else { - if (parent_vse->dawg_info == NULL) return NULL; // not a dict word path + if (parent_vse->dawg_info == nullptr) return nullptr; // not a dict word path dawg_args_.active_dawgs = &parent_vse->dawg_info->active_dawgs; dawg_args_.permuter = parent_vse->dawg_info->permuter; } @@ -800,16 +800,16 @@ LanguageModelDawgInfo *LanguageModel::GenerateDawgInfo( // Deal with compound words. if (dict_->compound_marker(b.unichar_id()) && - (parent_vse == NULL || parent_vse->dawg_info->permuter != NUMBER_PERM)) { + (parent_vse == nullptr || parent_vse->dawg_info->permuter != NUMBER_PERM)) { if (language_model_debug_level > 0) tprintf("Found compound marker\n"); // Do not allow compound operators at the beginning and end of the word. // Do not allow more than one compound operator per word. // Do not allow compounding of words with lengths shorter than // language_model_min_compound_length - if (parent_vse == NULL || word_end || + if (parent_vse == nullptr || word_end || dawg_args_.permuter == COMPOUND_PERM || parent_vse->length < language_model_min_compound_length) - return NULL; + return nullptr; int i; // Check a that the path terminated before the current character is a word. @@ -817,21 +817,21 @@ LanguageModelDawgInfo *LanguageModel::GenerateDawgInfo( for (i = 0; i < parent_vse->dawg_info->active_dawgs.size(); ++i) { const DawgPosition &pos = parent_vse->dawg_info->active_dawgs[i]; const Dawg *pdawg = pos.dawg_index < 0 - ? NULL : dict_->GetDawg(pos.dawg_index); - if (pdawg == NULL || pos.back_to_punc) continue;; + ? nullptr : dict_->GetDawg(pos.dawg_index); + if (pdawg == nullptr || pos.back_to_punc) continue;; if (pdawg->type() == DAWG_TYPE_WORD && pos.dawg_ref != NO_EDGE && pdawg->end_of_word(pos.dawg_ref)) { has_word_ending = true; break; } } - if (!has_word_ending) return NULL; + if (!has_word_ending) return nullptr; if (language_model_debug_level > 0) tprintf("Compound word found\n"); return new LanguageModelDawgInfo(&beginning_active_dawgs_, COMPOUND_PERM); } // done dealing with compound words - LanguageModelDawgInfo *dawg_info = NULL; + LanguageModelDawgInfo *dawg_info = nullptr; // Call LetterIsOkay(). // Use the normalized IDs so that all shapes of ' can be allowed in words @@ -874,7 +874,7 @@ LanguageModelNgramInfo *LanguageModel::GenerateNgramInfo( // Initialize parent context. const char *pcontext_ptr = ""; int pcontext_unichar_step_len = 0; - if (parent_vse == NULL) { + if (parent_vse == nullptr) { pcontext_ptr = prev_word_str_.string(); pcontext_unichar_step_len = prev_word_unichar_step_len_; } else { @@ -896,7 +896,7 @@ LanguageModelNgramInfo *LanguageModel::GenerateNgramInfo( ngram_and_classifier_cost *= outline_length / language_model_ngram_rating_factor; // Add the ngram_cost of the parent. - if (parent_vse != NULL) { + if (parent_vse != nullptr) { ngram_and_classifier_cost += parent_vse->ngram_info->ngram_and_classifier_cost; ngram_cost += parent_vse->ngram_info->ngram_cost; @@ -912,7 +912,7 @@ LanguageModelNgramInfo *LanguageModel::GenerateNgramInfo( } // Decide whether to prune this ngram path and update changed accordingly. - if (parent_vse != NULL && parent_vse->ngram_info->pruned) pruned = true; + if (parent_vse != nullptr && parent_vse->ngram_info->pruned) pruned = true; // Construct and return the new LanguageModelNgramInfo. LanguageModelNgramInfo *ngram_info = new LanguageModelNgramInfo( @@ -932,8 +932,8 @@ float LanguageModel::ComputeNgramCost(const char *unichar, bool *found_small_prob, float *ngram_cost) { const char *context_ptr = context; - char *modified_context = NULL; - char *modified_context_end = NULL; + char *modified_context = nullptr; + char *modified_context_end = nullptr; const char *unichar_ptr = unichar; const char *unichar_end = unichar_ptr + strlen(unichar_ptr); float prob = 0.0f; @@ -952,7 +952,7 @@ float LanguageModel::ComputeNgramCost(const char *unichar, // updated to include the previously examined characters from str, // unless use_only_first_uft8_step is true. if (unichar_ptr < unichar_end) { - if (modified_context == NULL) { + if (modified_context == nullptr) { size_t context_len = strlen(context); modified_context = new char[context_len + strlen(unichar_ptr) + step + 1]; @@ -990,7 +990,7 @@ float LanguageModel::ComputeDenom(BLOB_CHOICE_LIST *curr_list) { int len = 0; BLOB_CHOICE_IT c_it(curr_list); for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) { - ASSERT_HOST(c_it.data() != NULL); + ASSERT_HOST(c_it.data() != nullptr); ++len; denom += CertaintyScore(c_it.data()->certainty()); } @@ -1014,19 +1014,19 @@ void LanguageModel::FillConsistencyInfo( LMConsistencyInfo *consistency_info) { const UNICHARSET &unicharset = dict_->getUnicharset(); UNICHAR_ID unichar_id = b->unichar_id(); - BLOB_CHOICE* parent_b = parent_vse != NULL ? parent_vse->curr_b : NULL; + BLOB_CHOICE* parent_b = parent_vse != nullptr ? parent_vse->curr_b : nullptr; // Check punctuation validity. if (unicharset.get_ispunctuation(unichar_id)) consistency_info->num_punc++; - if (dict_->GetPuncDawg() != NULL && !consistency_info->invalid_punc) { - if (dict_->compound_marker(unichar_id) && parent_b != NULL && + if (dict_->GetPuncDawg() != nullptr && !consistency_info->invalid_punc) { + if (dict_->compound_marker(unichar_id) && parent_b != nullptr && (unicharset.get_isalpha(parent_b->unichar_id()) || unicharset.get_isdigit(parent_b->unichar_id()))) { // reset punc_ref for compound words consistency_info->punc_ref = NO_EDGE; } else { bool is_apos = dict_->is_apostrophe(unichar_id); - bool prev_is_numalpha = (parent_b != NULL && + bool prev_is_numalpha = (parent_b != nullptr && (unicharset.get_isalpha(parent_b->unichar_id()) || unicharset.get_isdigit(parent_b->unichar_id()))); UNICHAR_ID pattern_unichar_id = @@ -1051,14 +1051,14 @@ void LanguageModel::FillConsistencyInfo( } // Update case related counters. - if (parent_vse != NULL && !word_end && dict_->compound_marker(unichar_id)) { + if (parent_vse != nullptr && !word_end && dict_->compound_marker(unichar_id)) { // Reset counters if we are dealing with a compound word. consistency_info->num_lower = 0; consistency_info->num_non_first_upper = 0; } else if (unicharset.get_islower(unichar_id)) { consistency_info->num_lower++; - } else if ((parent_b != NULL) && unicharset.get_isupper(unichar_id)) { + } else if ((parent_b != nullptr) && unicharset.get_isupper(unichar_id)) { if (unicharset.get_isupper(parent_b->unichar_id()) || consistency_info->num_lower > 0 || consistency_info->num_non_first_upper > 0) { @@ -1081,7 +1081,7 @@ void LanguageModel::FillConsistencyInfo( } } - if (parent_vse != NULL && + if (parent_vse != nullptr && (parent_vse->consistency_info.script_id != dict_->getUnicharset().common_sid())) { int parent_script_id = parent_vse->consistency_info.script_id; @@ -1104,7 +1104,7 @@ void LanguageModel::FillConsistencyInfo( } // Check font and spacing consistency. - if (fontinfo_table_->size() > 0 && parent_b != NULL) { + if (fontinfo_table_->size() > 0 && parent_b != nullptr) { int fontinfo_id = -1; if (parent_b->fontinfo_id() == b->fontinfo_id() || parent_b->fontinfo_id2() == b->fontinfo_id()) { @@ -1188,7 +1188,7 @@ void LanguageModel::FillConsistencyInfo( } float LanguageModel::ComputeAdjustedPathCost(ViterbiStateEntry *vse) { - ASSERT_HOST(vse != NULL); + ASSERT_HOST(vse != nullptr); if (params_model_.Initialized()) { float features[PTRAIN_NUM_FEATURE_TYPES]; ExtractFeaturesFromPath(*vse, features); @@ -1204,10 +1204,10 @@ float LanguageModel::ComputeAdjustedPathCost(ViterbiStateEntry *vse) { return cost * vse->outline_length; } else { float adjustment = 1.0f; - if (vse->dawg_info == NULL || vse->dawg_info->permuter != FREQ_DAWG_PERM) { + if (vse->dawg_info == nullptr || vse->dawg_info->permuter != FREQ_DAWG_PERM) { adjustment += language_model_penalty_non_freq_dict_word; } - if (vse->dawg_info == NULL) { + if (vse->dawg_info == nullptr) { adjustment += language_model_penalty_non_dict_word; if (vse->length > language_model_min_compound_length) { adjustment += ((vse->length - language_model_min_compound_length) * @@ -1219,7 +1219,7 @@ float LanguageModel::ComputeAdjustedPathCost(ViterbiStateEntry *vse) { static_cast(vse->length); } if (language_model_ngram_on) { - ASSERT_HOST(vse->ngram_info != NULL); + ASSERT_HOST(vse->ngram_info != nullptr); return vse->ngram_info->ngram_and_classifier_cost * adjustment; } else { adjustment += ComputeConsistencyAdjustment(vse->dawg_info, @@ -1238,10 +1238,10 @@ void LanguageModel::UpdateBestChoice( bool truth_path; WERD_CHOICE *word = ConstructWord(vse, word_res, &best_choice_bundle->fixpt, blamer_bundle, &truth_path); - ASSERT_HOST(word != NULL); + ASSERT_HOST(word != nullptr); if (dict_->stopper_debug_level >= 1) { STRING word_str; - word->string_and_lengths(&word_str, NULL); + word->string_and_lengths(&word_str, nullptr); vse->Print(word_str.string()); } if (language_model_debug_level > 0) { @@ -1249,11 +1249,11 @@ void LanguageModel::UpdateBestChoice( } // Record features from the current path if necessary. ParamsTrainingHypothesis curr_hyp; - if (blamer_bundle != NULL) { - if (vse->dawg_info != NULL) vse->dawg_info->permuter = + if (blamer_bundle != nullptr) { + if (vse->dawg_info != nullptr) vse->dawg_info->permuter = static_cast(word->permuter()); ExtractFeaturesFromPath(*vse, curr_hyp.features); - word->string_and_lengths(&(curr_hyp.str), NULL); + word->string_and_lengths(&(curr_hyp.str), nullptr); curr_hyp.cost = vse->cost; // record cost for error rate computations if (language_model_debug_level > 0) { tprintf("Raw features extracted from %s (cost=%g) [ ", @@ -1268,16 +1268,16 @@ void LanguageModel::UpdateBestChoice( if (truth_path) blamer_bundle->UpdateBestRating(word->rating()); } - if (blamer_bundle != NULL && blamer_bundle->GuidedSegsearchStillGoing()) { + if (blamer_bundle != nullptr && blamer_bundle->GuidedSegsearchStillGoing()) { // The word was constructed solely for blamer_bundle->AddHypothesis, so // we no longer need it. delete word; return; } - if (word_res->chopped_word != NULL && !word_res->chopped_word->blobs.empty()) + if (word_res->chopped_word != nullptr && !word_res->chopped_word->blobs.empty()) word->SetScriptPositions(false, word_res->chopped_word); // Update and log new raw_choice if needed. - if (word_res->raw_choice == NULL || + if (word_res->raw_choice == nullptr || word->rating() < word_res->raw_choice->rating()) { if (word_res->LogNewRawChoice(word) && language_model_debug_level > 0) tprintf("Updated raw choice\n"); @@ -1288,7 +1288,7 @@ void LanguageModel::UpdateBestChoice( // computes adjust_factor that is used by the adaption code (e.g. by // ClassifyAdaptableWord() to compute adaption acceptance thresholds). // Note: the rating of the word is not adjusted. - dict_->adjust_word(word, vse->dawg_info == NULL, + dict_->adjust_word(word, vse->dawg_info == nullptr, vse->consistency_info.xht_decision, 0.0, false, language_model_debug_level > 0); // Hand ownership of the word over to the word_res. @@ -1311,7 +1311,7 @@ void LanguageModel::UpdateBestChoice( word->print_state("New state "); } // Update hyphen state if we are dealing with a dictionary word. - if (vse->dawg_info != NULL) { + if (vse->dawg_info != nullptr) { if (dict_->has_hyphen_end(*word)) { dict_->set_hyphen_word(*word, *(dawg_args_.active_dawgs)); } else { @@ -1319,12 +1319,12 @@ void LanguageModel::UpdateBestChoice( } } - if (blamer_bundle != NULL) { + if (blamer_bundle != nullptr) { blamer_bundle->set_best_choice_is_dict_and_top_choice( - vse->dawg_info != NULL && vse->top_choice_flags); + vse->dawg_info != nullptr && vse->top_choice_flags); } } - if (wordrec_display_segmentations && word_res->chopped_word != NULL) { + if (wordrec_display_segmentations && word_res->chopped_word != nullptr) { word->DisplaySegmentation(word_res->chopped_word); } } @@ -1335,7 +1335,7 @@ void LanguageModel::ExtractFeaturesFromPath( // Record dictionary match info. int len = vse.length <= kMaxSmallWordUnichars ? 0 : vse.length <= kMaxMediumWordUnichars ? 1 : 2; - if (vse.dawg_info != NULL) { + if (vse.dawg_info != nullptr) { int permuter = vse.dawg_info->permuter; if (permuter == NUMBER_PERM || permuter == USER_PATTERN_PERM) { if (vse.consistency_info.num_digits == vse.length) { @@ -1357,7 +1357,7 @@ void LanguageModel::ExtractFeaturesFromPath( vse.associate_stats.shape_cost / static_cast(vse.length); // Record ngram cost. (normalized by the path length). features[PTRAIN_NGRAM_COST_PER_CHAR] = 0.0; - if (vse.ngram_info != NULL) { + if (vse.ngram_info != nullptr) { features[PTRAIN_NGRAM_COST_PER_CHAR] = vse.ngram_info->ngram_cost / static_cast(vse.length); } @@ -1366,7 +1366,7 @@ void LanguageModel::ExtractFeaturesFromPath( // features[PTRAIN_NUM_BAD_PUNC] = vse.consistency_info.NumInconsistentPunc(); features[PTRAIN_NUM_BAD_CASE] = vse.consistency_info.NumInconsistentCase(); features[PTRAIN_XHEIGHT_CONSISTENCY] = vse.consistency_info.xht_decision; - features[PTRAIN_NUM_BAD_CHAR_TYPE] = vse.dawg_info == NULL ? + features[PTRAIN_NUM_BAD_CHAR_TYPE] = vse.dawg_info == nullptr ? vse.consistency_info.NumInconsistentChartype() : 0.0; features[PTRAIN_NUM_BAD_SPACING] = vse.consistency_info.NumInconsistentSpaces(); @@ -1384,9 +1384,9 @@ WERD_CHOICE *LanguageModel::ConstructWord( DANGERR *fixpt, BlamerBundle *blamer_bundle, bool *truth_path) { - if (truth_path != NULL) { + if (truth_path != nullptr) { *truth_path = - (blamer_bundle != NULL && + (blamer_bundle != nullptr && vse->length == blamer_bundle->correct_segmentation_length()); } BLOB_CHOICE *curr_b = vse->curr_b; @@ -1410,7 +1410,7 @@ WERD_CHOICE *LanguageModel::ConstructWord( word->set_length(vse->length); int total_blobs = 0; for (i = (vse->length-1); i >= 0; --i) { - if (blamer_bundle != NULL && truth_path != NULL && *truth_path && + if (blamer_bundle != nullptr && truth_path != nullptr && *truth_path && !blamer_bundle->MatrixPositionCorrect(i, curr_b->matrix_cell())) { *truth_path = false; } @@ -1422,7 +1422,7 @@ WERD_CHOICE *LanguageModel::ConstructWord( // languages to ensure that the blobs are of uniform width. // Skip leading and trailing punctuation when computing the variance. if ((full_wh_ratio_mean != 0.0f && - ((curr_vse != vse && curr_vse->parent_vse != NULL) || + ((curr_vse != vse && curr_vse->parent_vse != nullptr) || !dict_->getUnicharset().get_ispunctuation(curr_b->unichar_id())))) { vse->associate_stats.full_wh_ratio_var += pow(full_wh_ratio_mean - curr_vse->associate_stats.full_wh_ratio, 2); @@ -1440,7 +1440,7 @@ WERD_CHOICE *LanguageModel::ConstructWord( // Update curr_* pointers. curr_vse = curr_vse->parent_vse; - if (curr_vse == NULL) break; + if (curr_vse == nullptr) break; curr_b = curr_vse->curr_b; } ASSERT_HOST(i == 0); // check that we recorded all the unichar ids. @@ -1454,7 +1454,7 @@ WERD_CHOICE *LanguageModel::ConstructWord( word->set_certainty(vse->min_certainty); word->set_x_heights(vse->consistency_info.BodyMinXHeight(), vse->consistency_info.BodyMaxXHeight()); - if (vse->dawg_info != NULL) { + if (vse->dawg_info != nullptr) { word->set_permuter(compound ? COMPOUND_PERM : vse->dawg_info->permuter); } else if (language_model_ngram_on && !vse->ngram_info->pruned) { word->set_permuter(NGRAM_PERM); diff --git a/wordrec/language_model.h b/wordrec/language_model.h index 7448a5881a..9b5552e506 100644 --- a/wordrec/language_model.h +++ b/wordrec/language_model.h @@ -127,7 +127,7 @@ class LanguageModel { inline float ComputeConsistencyAdjustment( const LanguageModelDawgInfo *dawg_info, const LMConsistencyInfo &consistency_info) { - if (dawg_info != NULL) { + if (dawg_info != nullptr) { return ComputeAdjustment(consistency_info.NumInconsistentCase(), language_model_penalty_case) + (consistency_info.inconsistent_script ? @@ -192,7 +192,7 @@ class LanguageModel { // updates changed accordingly. // // Note: The function assumes that b, top_choice_flags and changed - // are not NULL. + // are not nullptr. void GenerateTopChoiceInfo(ViterbiStateEntry *new_vse, const ViterbiStateEntry *parent_vse, LanguageModelState *lms); @@ -209,7 +209,7 @@ class LanguageModel { // Computes p(unichar | parent context) and records it in ngram_cost. // If b.unichar_id() is an unlikely continuation of the parent context - // sets found_small_prob to true and returns NULL. + // sets found_small_prob to true and returns nullptr. // Otherwise creates a new LanguageModelNgramInfo entry containing the // updated context (that includes b.unichar_id() at the end) and returns it. // @@ -258,7 +258,7 @@ class LanguageModel { // Constructs a WERD_CHOICE by tracing parent pointers starting with // the given LanguageModelStateEntry. Returns the constructed word. // Updates best_char_choices, certainties and state if they are not - // NULL (best_char_choices and certainties are assumed to have the + // nullptr (best_char_choices and certainties are assumed to have the // length equal to lmse->length). // The caller is responsible for freeing memory associated with the // returned WERD_CHOICE. @@ -276,8 +276,8 @@ class LanguageModel { AssociateStats *associate_stats) { AssociateUtils::ComputeStats( col, row, - (parent_vse != NULL) ? &(parent_vse->associate_stats) : NULL, - (parent_vse != NULL) ? parent_vse->length : 0, + (parent_vse != nullptr) ? &(parent_vse->associate_stats) : nullptr, + (parent_vse != nullptr) ? parent_vse->length : 0, fixed_pitch_, max_char_wh_ratio, word_res, language_model_debug_level > 2, associate_stats); } @@ -290,7 +290,7 @@ class LanguageModel { // so paths with non-empty dawg_info are considered prunable. inline bool PrunablePath(const ViterbiStateEntry &vse) { if (vse.top_choice_flags) return false; - if (vse.dawg_info != NULL && + if (vse.dawg_info != nullptr && (vse.dawg_info->permuter == SYSTEM_DAWG_PERM || vse.dawg_info->permuter == USER_DAWG_PERM || vse.dawg_info->permuter == FREQ_DAWG_PERM)) return false; @@ -299,8 +299,8 @@ class LanguageModel { // Returns true if the given ViterbiStateEntry represents an acceptable path. inline bool AcceptablePath(const ViterbiStateEntry &vse) { - return (vse.dawg_info != NULL || vse.Consistent() || - (vse.ngram_info != NULL && !vse.ngram_info->pruned)); + return (vse.dawg_info != nullptr || vse.Consistent() || + (vse.ngram_info != nullptr && !vse.ngram_info->pruned)); } public: diff --git a/wordrec/lm_consistency.cpp b/wordrec/lm_consistency.cpp index 3d77c7b8b8..bc7308a1b7 100644 --- a/wordrec/lm_consistency.cpp +++ b/wordrec/lm_consistency.cpp @@ -51,7 +51,7 @@ void LMConsistencyInfo::ComputeXheightConsistency( // For the first character not y-shifted, we only care if it is too small. // Too large is common in drop caps and small caps. // int16_t small_xht = b->min_xheight(); - // if (parent_vse == NULL && sp == LanguageModelConsistencyInfo::kNORM) { + // if (parent_vse == nullptr && sp == LanguageModelConsistencyInfo::kNORM) { // small_xht = 0; // } IntersectRange(b->min_xheight(), b->max_xheight(), diff --git a/wordrec/lm_consistency.h b/wordrec/lm_consistency.h index e44483c886..8f2cf41872 100644 --- a/wordrec/lm_consistency.h +++ b/wordrec/lm_consistency.h @@ -51,7 +51,7 @@ struct LMConsistencyInfo { static const int kNumPos = 3; explicit LMConsistencyInfo(const LMConsistencyInfo* parent_info) { - if (parent_info == NULL) { + if (parent_info == nullptr) { // Initialize from scratch. num_alphas = 0; num_digits = 0; diff --git a/wordrec/lm_pain_points.cpp b/wordrec/lm_pain_points.cpp index 12c70ea712..e482cf9939 100644 --- a/wordrec/lm_pain_points.cpp +++ b/wordrec/lm_pain_points.cpp @@ -39,7 +39,7 @@ LMPainPointsType LMPainPoints::Deque(MATRIX_COORD *pp, float *priority) { if (pain_points_heaps_[h].empty()) continue; *priority = pain_points_heaps_[h].PeekTop().key; *pp = pain_points_heaps_[h].PeekTop().data; - pain_points_heaps_[h].Pop(NULL); + pain_points_heaps_[h].Pop(nullptr); return static_cast(h); } return LM_PPTYPE_NUM; @@ -86,7 +86,7 @@ void LMPainPoints::GenerateFromPath(float rating_cert_scale, // combining them will be beneficial. Blobs with high ratings might be // over-joined pieces of characters, but also could be blobs from an unseen // font or chopped pieces of complex characters. - while (curr_vse->parent_vse != NULL) { + while (curr_vse->parent_vse != nullptr) { ViterbiStateEntry* parent_vse = curr_vse->parent_vse; const MATRIX_COORD& curr_cell = curr_b->matrix_cell(); const MATRIX_COORD& parent_cell = parent_vse->curr_b->matrix_cell(); @@ -158,7 +158,7 @@ bool LMPainPoints::GeneratePainPoint( } // Compute associate stats. AssociateStats associate_stats; - AssociateUtils::ComputeStats(col, row, NULL, 0, fixed_pitch_, + AssociateUtils::ComputeStats(col, row, nullptr, 0, fixed_pitch_, max_char_wh_ratio, word_res, debug_level_, &associate_stats); // For fixed-pitch fonts/languages: if the current combined blob overlaps @@ -169,7 +169,7 @@ bool LMPainPoints::GeneratePainPoint( while (associate_stats.bad_fixed_pitch_right_gap && row + 1 < word_res->ratings->dimension() && !associate_stats.bad_fixed_pitch_wh_ratio) { - AssociateUtils::ComputeStats(col, ++row, NULL, 0, fixed_pitch_, + AssociateUtils::ComputeStats(col, ++row, nullptr, 0, fixed_pitch_, max_char_wh_ratio, word_res, debug_level_, &associate_stats); } diff --git a/wordrec/lm_state.cpp b/wordrec/lm_state.cpp index ee5560daa4..a2004b7260 100644 --- a/wordrec/lm_state.cpp +++ b/wordrec/lm_state.cpp @@ -27,7 +27,7 @@ ELISTIZE(ViterbiStateEntry) void ViterbiStateEntry::Print(const char *msg) const { tprintf("%s ViterbiStateEntry", msg); if (updated) tprintf("(NEW)"); - if (this->debug_str != NULL) { + if (this->debug_str != nullptr) { tprintf(" str=%s", this->debug_str->string()); } tprintf(" with ratings_sum=%.4f length=%d cost=%.6f", diff --git a/wordrec/lm_state.h b/wordrec/lm_state.h index 7a3d23ee5d..bc084f653e 100644 --- a/wordrec/lm_state.h +++ b/wordrec/lm_state.h @@ -97,14 +97,14 @@ struct ViterbiStateEntry : public ELIST_LINK { LanguageModelDawgInfo *d, LanguageModelNgramInfo *n, const char *debug_uch) - : cost(c), curr_b(b), parent_vse(pe), competing_vse(NULL), + : cost(c), curr_b(b), parent_vse(pe), competing_vse(nullptr), ratings_sum(b->rating()), min_certainty(b->certainty()), adapted(b->IsAdapted()), length(1), outline_length(ol), consistency_info(ci), associate_stats(as), top_choice_flags(tcf), dawg_info(d), ngram_info(n), updated(true) { - debug_str = (debug_uch == NULL) ? NULL : new STRING(); - if (pe != NULL) { + debug_str = (debug_uch == nullptr) ? nullptr : new STRING(); + if (pe != nullptr) { ratings_sum += pe->ratings_sum; if (pe->min_certainty < min_certainty) { min_certainty = pe->min_certainty; @@ -112,9 +112,9 @@ struct ViterbiStateEntry : public ELIST_LINK { adapted += pe->adapted; length += pe->length; outline_length += pe->outline_length; - if (debug_uch != NULL) *debug_str += *(pe->debug_str); + if (debug_uch != nullptr) *debug_str += *(pe->debug_str); } - if (debug_str != NULL && debug_uch != NULL) *debug_str += debug_uch; + if (debug_str != nullptr && debug_uch != nullptr) *debug_str += debug_uch; } ~ViterbiStateEntry() { delete dawg_info; @@ -131,7 +131,7 @@ struct ViterbiStateEntry : public ELIST_LINK { return (ve1->cost < ve2->cost) ? -1 : 1; } inline bool Consistent() const { - if (dawg_info != NULL && consistency_info.NumInconsistentCase() == 0) { + if (dawg_info != nullptr && consistency_info.NumInconsistentCase() == 0) { return true; } return consistency_info.Consistent(); @@ -139,7 +139,7 @@ struct ViterbiStateEntry : public ELIST_LINK { /// Returns true if this VSE has an alphanumeric character as its classifier /// result. bool HasAlnumChoice(const UNICHARSET& unicharset) { - if (curr_b == NULL) return false; + if (curr_b == nullptr) return false; UNICHAR_ID unichar_id = curr_b->unichar_id(); if (unicharset.get_isalpha(unichar_id) || unicharset.get_isdigit(unichar_id)) @@ -214,7 +214,7 @@ struct LanguageModelState { /// Bundle together all the things pertaining to the best choice/state. struct BestChoiceBundle { explicit BestChoiceBundle(int matrix_dimension) - : updated(false), best_vse(NULL) { + : updated(false), best_vse(nullptr) { beam.reserve(matrix_dimension); for (int i = 0; i < matrix_dimension; ++i) beam.push_back(new LanguageModelState); diff --git a/wordrec/pieces.cpp b/wordrec/pieces.cpp index 21e8ca7860..8c2409fc26 100644 --- a/wordrec/pieces.cpp +++ b/wordrec/pieces.cpp @@ -114,7 +114,7 @@ void Wordrec::fill_filtered_fragment_list(BLOB_CHOICE_LIST *choices, UNICHAR_ID choice_unichar_id = choices_it.data()->unichar_id(); const CHAR_FRAGMENT *frag = unicharset.get_fragment(choice_unichar_id); - if (frag != NULL && frag->get_pos() == fragment_pos && + if (frag != nullptr && frag->get_pos() == fragment_pos && frag->get_total() == num_frag_parts) { // Recover the unichar_id of the unichar that this fragment is // a part of @@ -147,7 +147,7 @@ void Wordrec::merge_and_put_fragment_lists(int16_t row, int16_t column, } BLOB_CHOICE_LIST *merged_choice = ratings->get(row, column); - if (merged_choice == NULL) + if (merged_choice == nullptr) merged_choice = new BLOB_CHOICE_LIST; bool end_of_list = false; @@ -290,7 +290,7 @@ void Wordrec::get_fragment_lists(int16_t current_frag, int16_t current_row, for (int16_t x = current_row; x < num_blobs; x++) { BLOB_CHOICE_LIST *choices = ratings->get(current_row, x); - if (choices == NULL) + if (choices == nullptr) continue; fill_filtered_fragment_list(choices, current_frag, num_frag_parts, @@ -324,14 +324,14 @@ void Wordrec::merge_fragments(MATRIX *ratings, int16_t num_blobs) { for (int16_t x = 0; x < num_blobs; x++) { for (int16_t y = x; y < num_blobs; y++) { BLOB_CHOICE_LIST *choices = ratings->get(x, y); - if (choices != NULL) { + if (choices != nullptr) { BLOB_CHOICE_IT choices_it(choices); for (choices_it.mark_cycle_pt(); !choices_it.cycled_list(); choices_it.forward()) { UNICHAR_ID choice_unichar_id = choices_it.data()->unichar_id(); const CHAR_FRAGMENT *frag = unicharset.get_fragment(choice_unichar_id); - if (frag != NULL) + if (frag != nullptr) delete choices_it.extract(); } } diff --git a/wordrec/plotedges.cpp b/wordrec/plotedges.cpp index 45adf4de94..43ac0d65f3 100644 --- a/wordrec/plotedges.cpp +++ b/wordrec/plotedges.cpp @@ -40,7 +40,7 @@ /*---------------------------------------------------------------------- V a r i a b l e s ----------------------------------------------------------------------*/ -ScrollView *edge_window = NULL; +ScrollView *edge_window = nullptr; /*---------------------------------------------------------------------- F u n c t i o n s @@ -53,7 +53,7 @@ ScrollView *edge_window = NULL; void display_edgepts(LIST outlines) { void *window; /* Set up window */ - if (edge_window == NULL) { + if (edge_window == nullptr) { edge_window = c_create_window ("Edges", 750, 150, 400, 128, -400.0, 400.0, 0.0, 256.0); } @@ -79,7 +79,7 @@ void draw_blob_edges(TBLOB *blob) { LIST edge_list = NIL_LIST; if (wordrec_display_splits) { - for (ol = blob->outlines; ol != NULL; ol = ol->next) + for (ol = blob->outlines; ol != nullptr; ol = ol->next) push_on (edge_list, ol->loop); display_edgepts(edge_list); destroy(edge_list); diff --git a/wordrec/render.cpp b/wordrec/render.cpp index d33b949875..0427f8389a 100644 --- a/wordrec/render.cpp +++ b/wordrec/render.cpp @@ -40,7 +40,7 @@ /*---------------------------------------------------------------------- V a r i a b l e s ----------------------------------------------------------------------*/ -ScrollView *blob_window = NULL; +ScrollView *blob_window = nullptr; C_COL color_list[] = { Red, Cyan, Yellow, Blue, Green, White @@ -63,7 +63,7 @@ BOOL_VAR(wordrec_blob_pause, 0, "Blob pause"); **********************************************************************/ void display_blob(TBLOB *blob, C_COL color) { /* Size of drawable */ - if (blob_window == NULL) { + if (blob_window == nullptr) { blob_window = c_create_window ("Blobs", 520, 10, 500, 256, -1000.0, 1000.0, 0.0, 256.0); } diff --git a/wordrec/segsearch.cpp b/wordrec/segsearch.cpp index 1009120f0b..520ed7d762 100644 --- a/wordrec/segsearch.cpp +++ b/wordrec/segsearch.cpp @@ -31,7 +31,7 @@ namespace tesseract { void Wordrec::DoSegSearch(WERD_RES* word_res) { BestChoiceBundle best_choice_bundle(word_res->ratings->dimension()); // Run Segmentation Search. - SegSearch(word_res, &best_choice_bundle, NULL); + SegSearch(word_res, &best_choice_bundle, nullptr); } void Wordrec::SegSearch(WERD_RES* word_res, @@ -49,13 +49,13 @@ void Wordrec::SegSearch(WERD_RES* word_res, blamer_bundle); if (!SegSearchDone(0)) { // find a better choice - if (chop_enable && word_res->chopped_word != NULL) { + if (chop_enable && word_res->chopped_word != nullptr) { improve_by_chopping(rating_cert_scale, word_res, best_choice_bundle, blamer_bundle, &pain_points, &pending); } if (chop_debug) SEAM::PrintSeams("Final seam list:", word_res->seam_array); - if (blamer_bundle != NULL && + if (blamer_bundle != nullptr && !blamer_bundle->ChoiceIsCorrect(word_res->best_choice)) { blamer_bundle->SetChopperBlame(word_res, wordrec_debug_blamer); } @@ -68,7 +68,7 @@ void Wordrec::SegSearch(WERD_RES* word_res, STRING blamer_debug; while (wordrec_enable_assoc && (!SegSearchDone(num_futile_classifications) || - (blamer_bundle != NULL && + (blamer_bundle != nullptr && blamer_bundle->GuidedSegsearchStillGoing()))) { // Get the next valid "pain point". bool found_nothing = true; @@ -108,13 +108,13 @@ void Wordrec::SegSearch(WERD_RES* word_res, // See if it's time to terminate SegSearch or time for starting a guided // search for the true path to find the blame for the incorrect best_choice. if (SegSearchDone(num_futile_classifications) && - blamer_bundle != NULL && + blamer_bundle != nullptr && blamer_bundle->GuidedSegsearchNeeded(word_res->best_choice)) { InitBlamerForSegSearch(word_res, &pain_points, blamer_bundle, &blamer_debug); } } // end while loop exploring alternative paths - if (blamer_bundle != NULL) { + if (blamer_bundle != nullptr) { blamer_bundle->FinishSegSearch(word_res->best_choice, wordrec_debug_blamer, &blamer_debug); } @@ -152,7 +152,7 @@ void Wordrec::InitialSegSearch(WERD_RES* word_res, LMPainPoints* pain_points, // blamer_bundle->norm_truth_word to the corresponding i,j indices in the // ratings matrix. We expect this step to succeed, since when running the // chopper we checked that the correct chops are present. - if (blamer_bundle != NULL) { + if (blamer_bundle != nullptr) { blamer_bundle->SetupCorrectSegmentation(word_res->chopped_word, wordrec_debug_blamer); } @@ -201,8 +201,8 @@ void Wordrec::UpdateSegSearchNodes( // Update language model state of this child+parent pair. BLOB_CHOICE_LIST *current_node = ratings->get(col, row); LanguageModelState *parent_node = - col == 0 ? NULL : best_choice_bundle->beam[col - 1]; - if (current_node != NULL && + col == 0 ? nullptr : best_choice_bundle->beam[col - 1]; + if (current_node != nullptr && language_model_->UpdateState((*pending)[col].IsRowJustClassified(row), col, row, current_node, parent_node, pain_points, word_res, @@ -217,7 +217,7 @@ void Wordrec::UpdateSegSearchNodes( } // end if UpdateState. } // end for row. } // end for col. - if (best_choice_bundle->best_vse != NULL) { + if (best_choice_bundle->best_vse != nullptr) { ASSERT_HOST(word_res->StatesAllValid()); if (best_choice_bundle->best_vse->updated) { pain_points->GenerateFromPath(rating_cert_scale, @@ -250,7 +250,7 @@ void Wordrec::ProcessSegSearchPainPoint( pain_point_type, pain_point_priority, pain_point.col, pain_point.row); } - ASSERT_HOST(pain_points != NULL); + ASSERT_HOST(pain_points != nullptr); MATRIX *ratings = word_res->ratings; // Classify blob [pain_point.col pain_point.row] if (!pain_point.Valid(*ratings)) { @@ -263,7 +263,7 @@ void Wordrec::ProcessSegSearchPainPoint( word_res->chopped_word, blamer_bundle); BLOB_CHOICE_LIST *lst = ratings->get(pain_point.col, pain_point.row); - if (lst == NULL) { + if (lst == nullptr) { ratings->put(pain_point.col, pain_point.row, classified); } else { // We can not delete old BLOB_CHOICEs, since they might contain @@ -273,7 +273,7 @@ void Wordrec::ProcessSegSearchPainPoint( BLOB_CHOICE_IT it(lst); it.add_list_before(classified); delete classified; // safe to delete, since empty after add_list_before() - classified = NULL; + classified = nullptr; } if (segsearch_debug_level > 0) { @@ -285,7 +285,7 @@ void Wordrec::ProcessSegSearchPainPoint( // Insert initial "pain points" to join the newly classified blob // with its left and right neighbors. - if (classified != NULL && !classified->empty()) { + if (classified != nullptr && !classified->empty()) { if (pain_point.col > 0) { pain_points->GeneratePainPoint( pain_point.col - 1, pain_point.row, LM_PPTYPE_SHAPE, 0.0, @@ -313,7 +313,7 @@ void Wordrec::ResetNGramSearch(WERD_RES* word_res, } // Reset best_choice_bundle. word_res->ClearWordChoices(); - best_choice_bundle->best_vse = NULL; + best_choice_bundle->best_vse = nullptr; // Clear out all existing pendings and add a new one for the first column. (*pending)[0].SetColumnClassified(); for (int i = 1; i < pending->size(); ++i) diff --git a/wordrec/tface.cpp b/wordrec/tface.cpp index eb93fe8b54..7b5ae8de7d 100644 --- a/wordrec/tface.cpp +++ b/wordrec/tface.cpp @@ -46,7 +46,7 @@ namespace tesseract { void Wordrec::program_editup(const char *textbase, TessdataManager *init_classifier, TessdataManager *init_dict) { - if (textbase != NULL) imagefile = textbase; + if (textbase != nullptr) imagefile = textbase; InitFeatureDefs(&feature_defs_); InitAdaptiveClassifier(init_classifier); if (init_dict) { @@ -138,7 +138,7 @@ int Wordrec::dict_word(const WERD_CHOICE &word) { BLOB_CHOICE_LIST *Wordrec::call_matcher(TBLOB *tessblob) { // Rotate the blob for classification if necessary. TBLOB* rotated_blob = tessblob->ClassifyNormalizeIfNeeded(); - if (rotated_blob == NULL) { + if (rotated_blob == nullptr) { rotated_blob = tessblob; } BLOB_CHOICE_LIST *ratings = new BLOB_CHOICE_LIST(); // matcher result diff --git a/wordrec/wordclass.cpp b/wordrec/wordclass.cpp index 5bedfe96e3..fc206b9dbf 100644 --- a/wordrec/wordclass.cpp +++ b/wordrec/wordclass.cpp @@ -65,7 +65,7 @@ BLOB_CHOICE_LIST *Wordrec::classify_blob(TBLOB *blob, // If a blob with the same bounding box as one of the truth character // bounding boxes is not classified as the corresponding truth character // blame character classifier for incorrect answer. - if (blamer_bundle != NULL) { + if (blamer_bundle != nullptr) { blamer_bundle->BlameClassifier(getDict().getUnicharset(), blob->bounding_box(), *choices, diff --git a/wordrec/wordrec.cpp b/wordrec/wordrec.cpp index cd151694a6..03beedc098 100644 --- a/wordrec/wordrec.cpp +++ b/wordrec/wordrec.cpp @@ -114,10 +114,10 @@ Wordrec::Wordrec() : "Save alternative paths found during chopping" " and segmentation search", params()) { - prev_word_best_choice_ = NULL; + prev_word_best_choice_ = nullptr; language_model_ = new LanguageModel(&get_fontinfo_table(), &(getDict())); - fill_lattice_ = NULL; + fill_lattice_ = nullptr; } Wordrec::~Wordrec() { diff --git a/wordrec/wordrec.h b/wordrec/wordrec.h index f70081f1bb..e372e18d18 100644 --- a/wordrec/wordrec.h +++ b/wordrec/wordrec.h @@ -191,7 +191,7 @@ class Wordrec : public Classify { const UNICHARSET &unicharset, BlamerBundle *blamer_bundle); // Calls fill_lattice_ member function - // (assumes that fill_lattice_ is not NULL). + // (assumes that fill_lattice_ is not nullptr). void CallFillLattice(const MATRIX &ratings, const WERD_CHOICE_LIST &best_choices, const UNICHARSET &unicharset, @@ -266,7 +266,7 @@ class Wordrec : public Classify { // on the classifications already recorded in chunks_record.ratings. // // Note: this function assumes that word_res, best_choice_bundle arguments - // are not NULL. + // are not nullptr. void SegSearch(WERD_RES* word_res, BestChoiceBundle* best_choice_bundle, BlamerBundle* blamer_bundle);