Skip to content

Commit

Permalink
Format code (2nd iteration)
Browse files Browse the repository at this point in the history
It was formatted using
clang-format-7 -i -style=Google $(find -name "*.h" -o -name "*.cpp")

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed May 24, 2018
1 parent 99ef870 commit dc4d672
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 150 deletions.
222 changes: 110 additions & 112 deletions src/ccmain/reject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,132 +43,130 @@
CLISTIZEH(STRING)
CLISTIZE(STRING)

/*************************************************************************
* set_done()
*
* Set the done flag based on the word acceptability criteria
*************************************************************************/

namespace tesseract {
void Tesseract::set_done(WERD_RES * word, int16_t pass) {
word->done =
word->tess_accepted &&
(strchr(word->best_choice->unichar_string().string(), ' ') == nullptr);
bool word_is_ambig = word->best_choice->dangerous_ambig_found();
bool word_from_dict = word->best_choice->permuter() == SYSTEM_DAWG_PERM ||
word->best_choice->permuter() == FREQ_DAWG_PERM ||
word->best_choice->permuter() == USER_DAWG_PERM;
if (word->done && (pass == 1) && (!word_from_dict || word_is_ambig) &&
one_ell_conflict(word, false)) {
if (tessedit_rejection_debug) tprintf("one_ell_conflict detected\n");
word->done = FALSE;
}
if (word->done &&
((!word_from_dict && word->best_choice->permuter() != NUMBER_PERM) ||
word_is_ambig)) {
if (tessedit_rejection_debug)
tprintf("non-dict or ambig word detected\n");
word->done = FALSE;
}
if (tessedit_rejection_debug) {
tprintf("set_done(): done=%d\n", word->done);
word->best_choice->print("");
}
/*************************************************************************
* set_done()
*
* Set the done flag based on the word acceptability criteria
*************************************************************************/

namespace tesseract {
void Tesseract::set_done(WERD_RES *word, int16_t pass) {
word->done =
word->tess_accepted &&
(strchr(word->best_choice->unichar_string().string(), ' ') == nullptr);
bool word_is_ambig = word->best_choice->dangerous_ambig_found();
bool word_from_dict = word->best_choice->permuter() == SYSTEM_DAWG_PERM ||
word->best_choice->permuter() == FREQ_DAWG_PERM ||
word->best_choice->permuter() == USER_DAWG_PERM;
if (word->done && (pass == 1) && (!word_from_dict || word_is_ambig) &&
one_ell_conflict(word, false)) {
if (tessedit_rejection_debug) tprintf("one_ell_conflict detected\n");
word->done = FALSE;
}
if (word->done &&
((!word_from_dict && word->best_choice->permuter() != NUMBER_PERM) ||
word_is_ambig)) {
if (tessedit_rejection_debug) tprintf("non-dict or ambig word detected\n");
word->done = FALSE;
}
if (tessedit_rejection_debug) {
tprintf("set_done(): done=%d\n", word->done);
word->best_choice->print("");
}
}

/*************************************************************************
* make_reject_map()
*
* Sets the done flag to indicate whether the resylt is acceptable.
*
* Sets a reject map for the word.
*************************************************************************/
void Tesseract::make_reject_map(WERD_RES * word, ROW * row, int16_t pass) {
int i;
int offset;

flip_0O(word);
check_debug_pt(word, -1); // For trap only
set_done(word, pass); // Set acceptance
word->reject_map.initialise(word->best_choice->unichar_lengths().length());
reject_blanks(word);
/*************************************************************************
* make_reject_map()
*
* Sets the done flag to indicate whether the resylt is acceptable.
*
* Sets a reject map for the word.
*************************************************************************/
void Tesseract::make_reject_map(WERD_RES *word, ROW *row, int16_t pass) {
int i;
int offset;

flip_0O(word);
check_debug_pt(word, -1); // For trap only
set_done(word, pass); // Set acceptance
word->reject_map.initialise(word->best_choice->unichar_lengths().length());
reject_blanks(word);
/*
0: Rays original heuristic - the baseline
*/
if (tessedit_reject_mode == 0) {
if (!word->done) reject_poor_matches(word);
} else if (tessedit_reject_mode == 5) {
/*
0: Rays original heuristic - the baseline
5: Reject I/1/l from words where there is no strong contextual
confirmation; the whole of any unacceptable words (incl PERM rej of
dubious 1/I/ls); and the whole of any words which are very small
*/
if (tessedit_reject_mode == 0) {
if (!word->done) reject_poor_matches(word);
} else if (tessedit_reject_mode == 5) {
if (kBlnXHeight / word->denorm.y_scale() <= min_sane_x_ht_pixels) {
word->reject_map.rej_word_small_xht();
} else {
one_ell_conflict(word, true);
/*
5: Reject I/1/l from words where there is no strong contextual
confirmation; the whole of any unacceptable words (incl PERM rej of
dubious 1/I/ls); and the whole of any words which are very small
Originally the code here just used the done flag. Now I have
duplicated and unpacked the conditions for setting the done flag so
that each mechanism can be turned on or off independently. This works
WITHOUT affecting the done flag setting.
*/
if (kBlnXHeight / word->denorm.y_scale() <= min_sane_x_ht_pixels) {
word->reject_map.rej_word_small_xht();
} else {
one_ell_conflict(word, true);
/*
Originally the code here just used the done flag. Now I have
duplicated and unpacked the conditions for setting the done flag so
that each mechanism can be turned on or off independently. This works
WITHOUT affecting the done flag setting.
*/
if (rej_use_tess_accepted && !word->tess_accepted)
word->reject_map.rej_word_not_tess_accepted();

if (rej_use_tess_blanks &&
(strchr(word->best_choice->unichar_string().string(), ' ') !=
nullptr))
word->reject_map.rej_word_contains_blanks();

WERD_CHOICE *best_choice = word->best_choice;
if (rej_use_good_perm) {
if ((best_choice->permuter() == SYSTEM_DAWG_PERM ||
best_choice->permuter() == FREQ_DAWG_PERM ||
best_choice->permuter() == USER_DAWG_PERM) &&
(!rej_use_sensible_wd ||
acceptable_word_string(
*word->uch_set, best_choice->unichar_string().string(),
best_choice->unichar_lengths().string()) !=
AC_UNACCEPTABLE)) {
// PASSED TEST
} else if (best_choice->permuter() == NUMBER_PERM) {
if (rej_alphas_in_number_perm) {
for (i = 0, offset = 0;
best_choice->unichar_string()[offset] != '\0';
offset += best_choice->unichar_lengths()[i++]) {
if (word->reject_map[i].accepted() &&
word->uch_set->get_isalpha(
best_choice->unichar_string().string() + offset,
best_choice->unichar_lengths()[i]))
word->reject_map[i].setrej_bad_permuter();
// rej alpha
}
if (rej_use_tess_accepted && !word->tess_accepted)
word->reject_map.rej_word_not_tess_accepted();

if (rej_use_tess_blanks &&
(strchr(word->best_choice->unichar_string().string(), ' ') !=
nullptr))
word->reject_map.rej_word_contains_blanks();

WERD_CHOICE *best_choice = word->best_choice;
if (rej_use_good_perm) {
if ((best_choice->permuter() == SYSTEM_DAWG_PERM ||
best_choice->permuter() == FREQ_DAWG_PERM ||
best_choice->permuter() == USER_DAWG_PERM) &&
(!rej_use_sensible_wd ||
acceptable_word_string(
*word->uch_set, best_choice->unichar_string().string(),
best_choice->unichar_lengths().string()) != AC_UNACCEPTABLE)) {
// PASSED TEST
} else if (best_choice->permuter() == NUMBER_PERM) {
if (rej_alphas_in_number_perm) {
for (i = 0, offset = 0;
best_choice->unichar_string()[offset] != '\0';
offset += best_choice->unichar_lengths()[i++]) {
if (word->reject_map[i].accepted() &&
word->uch_set->get_isalpha(
best_choice->unichar_string().string() + offset,
best_choice->unichar_lengths()[i]))
word->reject_map[i].setrej_bad_permuter();
// rej alpha
}
} else {
word->reject_map.rej_word_bad_permuter();
}
} else {
word->reject_map.rej_word_bad_permuter();
}
/* Ambig word rejection was here once !!*/
}
} else {
tprintf("BAD tessedit_reject_mode\n");
err_exit();
/* Ambig word rejection was here once !!*/
}
} else {
tprintf("BAD tessedit_reject_mode\n");
err_exit();
}

if (tessedit_image_border > -1) reject_edge_blobs(word);
if (tessedit_image_border > -1) reject_edge_blobs(word);

check_debug_pt(word, 10);
if (tessedit_rejection_debug) {
tprintf("Permuter Type = %d\n", word->best_choice->permuter());
tprintf("Certainty: %f Rating: %f\n", word->best_choice->certainty(),
word->best_choice->rating());
tprintf("Dict word: %d\n", dict_word(*(word->best_choice)));
}

flip_hyphens(word);
check_debug_pt(word, 20);
check_debug_pt(word, 10);
if (tessedit_rejection_debug) {
tprintf("Permuter Type = %d\n", word->best_choice->permuter());
tprintf("Certainty: %f Rating: %f\n", word->best_choice->certainty(),
word->best_choice->rating());
tprintf("Dict word: %d\n", dict_word(*(word->best_choice)));
}

flip_hyphens(word);
check_debug_pt(word, 20);
}
} // namespace tesseract

void reject_blanks(WERD_RES *word) {
Expand Down
8 changes: 4 additions & 4 deletions src/ccstruct/coutln.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class DLLSYM C_OUTLINE : public ELIST_LINK {
CRACKEDGE* startpt, // from edge detector
ICOORD bot_left, // bounding box //length of loop
ICOORD top_right, int16_t length);
C_OUTLINE(ICOORD startpt, // start of loop
DIR128* new_steps, // steps in loop
int16_t length); // length of loop
// outline to copy
C_OUTLINE(ICOORD startpt, // start of loop
DIR128* new_steps, // steps in loop
int16_t length); // length of loop
// outline to copy
C_OUTLINE(C_OUTLINE* srcline, FCOORD rotation); // and rotate

// Build a fake outline, given just a bounding box and append to the list.
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/crakedge.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* File: crakedge.h (Formerly:
* File: crakedge.h (Formerly:
*crkedge.h) Description: Sturctures for the Crack following edge detector.
* Author: Ray Smith
* Created: Fri Mar 22 16:06:38 GMT 1991
Expand Down
16 changes: 8 additions & 8 deletions src/ccstruct/ocrrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ class ROW : public ELIST_LINK {
ROW &operator=(const ROW &source);

private:
int32_t kerning; // inter char gap
int32_t spacing; // inter word gap
TBOX bound_box; // bounding box
float xheight; // height of line
float ascrise; // size of ascenders
float descdrop; //-size of descenders
float bodysize; // CJK character size. (equals to
// xheight+ascrise by default)
int32_t kerning; // inter char gap
int32_t spacing; // inter word gap
TBOX bound_box; // bounding box
float xheight; // height of line
float ascrise; // size of ascenders
float descdrop; //-size of descenders
float bodysize; // CJK character size. (equals to
// xheight+ascrise by default)
WERD_LIST words; // words
QSPLINE baseline; // baseline spline

Expand Down
3 changes: 2 additions & 1 deletion src/ccstruct/pageres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

ELISTIZE(BLOCK_RES)
CLISTIZE(BLOCK_RES)
ELISTIZE(ROW_RES) ELISTIZE(WERD_RES)
ELISTIZE(ROW_RES)
ELISTIZE(WERD_RES)

// Gain factor for computing thresholds that determine the ambiguity of a
// word.
Expand Down
4 changes: 2 additions & 2 deletions src/ccstruct/pdblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void PDBLK::plot( // draw outline
do {
prevpt = *(it.data()); // previous point
it.forward(); // move to next point
// draw round corner
// draw round corner
window->DrawTo(prevpt.x(), it.data()->y());
window->DrawTo(it.data()->x(), it.data()->y());
} while (!it.at_last()); // until end of list
Expand Down Expand Up @@ -270,7 +270,7 @@ BLOCK_RECT_IT::BLOCK_RECT_IT(
void BLOCK_RECT_IT::set_to_block( // start (new) block
PDBLK* blkptr) { // block to start
block = blkptr; // remember block
// set iterators
// set iterators
left_it.set_to_list(&blkptr->leftside);
right_it.set_to_list(&blkptr->rightside);
if (!blkptr->leftside.empty()) start_block(); // ready for iteration
Expand Down
4 changes: 2 additions & 2 deletions src/ccstruct/rejctmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class REJ {
void setrej_postNN_1Il(); // 1Il after NN
void setrej_rej_cblob(); // Insert duff blob
void setrej_mm_reject(); // Matrix matcher
// Odd repeated char
// Odd repeated char
void setrej_bad_repetition();
void setrej_poor_match(); // Failed Rays heuristic
// TEMP reject_word
Expand All @@ -189,7 +189,7 @@ class REJ {
void setrej_nn_accept(); // NN Flipped a char
void setrej_hyphen_accept(); // Good aspect ratio
void setrej_mm_accept(); // Matrix matcher
// Quality flip a char
// Quality flip a char
void setrej_quality_accept();
// Accept all except blank
void setrej_minimal_rej_accept();
Expand Down
2 changes: 1 addition & 1 deletion src/classify/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int32_t MergeClusters(int16_t N, PARAM_DESC ParamDesc[], int32_t n1, int32_t n2,
FLOAT32 m[], FLOAT32 m1[], FLOAT32 m2[]);

//--------------Global Data Definitions and
//Declarations---------------------------
// Declarations---------------------------
// define errors that can be trapped
#define ALREADYCLUSTERED 4000
#endif
2 changes: 1 addition & 1 deletion src/textord/drawtord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void plot_word_decisions( // draw words
int16_t blob_count; // blobs in word
BLOBNBOX *blob; // current blob
TBOX blob_box; // bounding box
// iterator
// iterator
BLOBNBOX_IT blob_it = row->blob_list();
BLOBNBOX_IT start_it = blob_it; // word start

Expand Down
2 changes: 1 addition & 1 deletion src/textord/fpchop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ROW *fixed_pitch_words( // find lines
WERD *word; // new word
int32_t xstarts[2]; // row ends
int32_t prev_x; // end of prev blob
// iterator
// iterator
BLOBNBOX_IT box_it = row->blob_list();
// boundaries
ICOORDELT_IT cell_it = &row->char_cells;
Expand Down
8 changes: 4 additions & 4 deletions src/textord/makerow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ void expand_rows( // find lines
float y_bottom, y_top; // allowed limits
TO_ROW *test_row; // next row
TO_ROW *row; // current row
// iterators
// iterators
BLOBNBOX_IT blob_it = &block->blobs;
TO_ROW_IT row_it = block->get_rows();

Expand Down Expand Up @@ -2023,7 +2023,7 @@ bool segment_baseline( // split baseline
TBOX box; // blob box
TBOX new_box; // new_it box
float middle; // xcentre of blob
// blobs
// blobs
BLOBNBOX_IT blob_it = row->blob_list();
BLOBNBOX_IT new_it = blob_it; // front end
SORTED_FLOATS yshifts; // shifts from baseline
Expand Down Expand Up @@ -2114,7 +2114,7 @@ double *linear_spline_baseline( // split baseline
int blobs_per_segment; // blobs in each
TBOX box; // blob box
TBOX new_box; // new_it box
// blobs
// blobs
BLOBNBOX_IT blob_it = row->blob_list();
BLOBNBOX_IT new_it = blob_it; // front end
float b, c; // fitted curve
Expand Down Expand Up @@ -2212,7 +2212,7 @@ void assign_blobs_to_rows( // find lines
BLOBNBOX *blob; // current blob
TO_ROW *row; // current row
TO_ROW *dest_row = nullptr; // row to put blob in
// iterators
// iterators
BLOBNBOX_IT blob_it = &block->blobs;
TO_ROW_IT row_it = block->get_rows();

Expand Down
Loading

0 comments on commit dc4d672

Please sign in to comment.