tesseract  4.0.0-1-g2a2b
rejctmap.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: rejctmap.cpp (Formerly rejmap.c)
3  * Description: REJ and REJMAP class functions.
4  * Author: Phil Cheatle
5  * Created: Thu Jun 9 13:46:38 BST 1994
6  *
7  * (C) Copyright 1994, Hewlett-Packard Ltd.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 #include "host.h"
21 #include "rejctmap.h"
22 #include "params.h"
23 
24 bool REJ::perm_rejected() { //Is char perm reject?
25  return (flag (R_TESS_FAILURE) ||
26  flag (R_SMALL_XHT) ||
27  flag (R_EDGE_CHAR) ||
28  flag (R_1IL_CONFLICT) ||
29  flag (R_POSTNN_1IL) ||
30  flag (R_REJ_CBLOB) ||
32 }
33 
34 
35 bool REJ::rej_before_nn_accept() {
36  return flag (R_POOR_MATCH) ||
39 }
40 
41 
42 bool REJ::rej_between_nn_and_mm() {
43  return flag (R_HYPHEN) ||
44  flag (R_DUBIOUS) ||
46 }
47 
48 
49 bool REJ::rej_between_mm_and_quality_accept() {
50  return flag (R_BAD_QUALITY);
51 }
52 
53 
54 bool REJ::rej_between_quality_and_minimal_rej_accept() {
55  return flag (R_DOC_REJ) ||
57 }
58 
59 
60 bool REJ::rej_before_mm_accept() {
61  return rej_between_nn_and_mm () ||
62  (rej_before_nn_accept () &&
64 }
65 
66 
67 bool REJ::rej_before_quality_accept() {
68  return rej_between_mm_and_quality_accept () ||
69  (!flag (R_MM_ACCEPT) && rej_before_mm_accept ());
70 }
71 
72 
73 bool REJ::rejected() { //Is char rejected?
75  return false;
76  else
77  return (perm_rejected () ||
78  rej_between_quality_and_minimal_rej_accept () ||
79  (!flag (R_QUALITY_ACCEPT) && rej_before_quality_accept ()));
80 }
81 
82 
83 bool REJ::accept_if_good_quality() { //potential rej?
84  return (rejected () &&
85  !perm_rejected () &&
86  flag (R_BAD_PERMUTER) &&
87  !flag (R_POOR_MATCH) &&
90  (!rej_between_nn_and_mm () &&
91  !rej_between_mm_and_quality_accept () &&
92  !rej_between_quality_and_minimal_rej_accept ()));
93 }
94 
95 
96 void REJ::setrej_tess_failure() { //Tess generated blank
97  set_flag(R_TESS_FAILURE);
98 }
99 
100 
101 void REJ::setrej_small_xht() { //Small xht char/wd
102  set_flag(R_SMALL_XHT);
103 }
104 
105 
106 void REJ::setrej_edge_char() { //Close to image edge
107  set_flag(R_EDGE_CHAR);
108 }
109 
110 
111 void REJ::setrej_1Il_conflict() { //Initial reject map
112  set_flag(R_1IL_CONFLICT);
113 }
114 
115 
116 void REJ::setrej_postNN_1Il() { //1Il after NN
117  set_flag(R_POSTNN_1IL);
118 }
119 
120 
121 void REJ::setrej_rej_cblob() { //Insert duff blob
122  set_flag(R_REJ_CBLOB);
123 }
124 
125 
126 void REJ::setrej_mm_reject() { //Matrix matcher
127  set_flag(R_MM_REJECT);
128 }
129 
130 
131 void REJ::setrej_bad_repetition() { //Odd repeated char
132  set_flag(R_BAD_REPETITION);
133 }
134 
135 
136 void REJ::setrej_poor_match() { //Failed Rays heuristic
137  set_flag(R_POOR_MATCH);
138 }
139 
140 
142  //TEMP reject_word
143  set_flag(R_NOT_TESS_ACCEPTED);
144 }
145 
146 
148  //TEMP reject_word
149  set_flag(R_CONTAINS_BLANKS);
150 }
151 
152 
153 void REJ::setrej_bad_permuter() { //POTENTIAL reject_word
154  set_flag(R_BAD_PERMUTER);
155 }
156 
157 
158 void REJ::setrej_hyphen() { //PostNN dubious hyphen or .
159  set_flag(R_HYPHEN);
160 }
161 
162 
163 void REJ::setrej_dubious() { //PostNN dubious limit
164  set_flag(R_DUBIOUS);
165 }
166 
167 
168 void REJ::setrej_no_alphanums() { //TEMP reject_word
169  set_flag(R_NO_ALPHANUMS);
170 }
171 
172 
173 void REJ::setrej_mostly_rej() { //TEMP reject_word
174  set_flag(R_MOSTLY_REJ);
175 }
176 
177 
178 void REJ::setrej_xht_fixup() { //xht fixup
179  set_flag(R_XHT_FIXUP);
180 }
181 
182 
183 void REJ::setrej_bad_quality() { //TEMP reject_word
184  set_flag(R_BAD_QUALITY);
185 }
186 
187 
188 void REJ::setrej_doc_rej() { //TEMP reject_word
189  set_flag(R_DOC_REJ);
190 }
191 
192 
193 void REJ::setrej_block_rej() { //TEMP reject_word
194  set_flag(R_BLOCK_REJ);
195 }
196 
197 
198 void REJ::setrej_row_rej() { //TEMP reject_word
199  set_flag(R_ROW_REJ);
200 }
201 
202 
203 void REJ::setrej_unlv_rej() { //TEMP reject_word
204  set_flag(R_UNLV_REJ);
205 }
206 
207 
208 void REJ::setrej_hyphen_accept() { //NN Flipped a char
209  set_flag(R_HYPHEN_ACCEPT);
210 }
211 
212 
213 void REJ::setrej_nn_accept() { //NN Flipped a char
214  set_flag(R_NN_ACCEPT);
215 }
216 
217 
218 void REJ::setrej_mm_accept() { //Matrix matcher
219  set_flag(R_MM_ACCEPT);
220 }
221 
222 
223 void REJ::setrej_quality_accept() { //Quality flip a char
224  set_flag(R_QUALITY_ACCEPT);
225 }
226 
227 
229  //Accept all except blank
230  set_flag(R_MINIMAL_REJ_ACCEPT);
231 }
232 
233 
234 void REJ::full_print(FILE *fp) {
235  fprintf (fp, "R_TESS_FAILURE: %s\n", flag (R_TESS_FAILURE) ? "T" : "F");
236  fprintf (fp, "R_SMALL_XHT: %s\n", flag (R_SMALL_XHT) ? "T" : "F");
237  fprintf (fp, "R_EDGE_CHAR: %s\n", flag (R_EDGE_CHAR) ? "T" : "F");
238  fprintf (fp, "R_1IL_CONFLICT: %s\n", flag (R_1IL_CONFLICT) ? "T" : "F");
239  fprintf (fp, "R_POSTNN_1IL: %s\n", flag (R_POSTNN_1IL) ? "T" : "F");
240  fprintf (fp, "R_REJ_CBLOB: %s\n", flag (R_REJ_CBLOB) ? "T" : "F");
241  fprintf (fp, "R_MM_REJECT: %s\n", flag (R_MM_REJECT) ? "T" : "F");
242  fprintf (fp, "R_BAD_REPETITION: %s\n", flag (R_BAD_REPETITION) ? "T" : "F");
243  fprintf (fp, "R_POOR_MATCH: %s\n", flag (R_POOR_MATCH) ? "T" : "F");
244  fprintf (fp, "R_NOT_TESS_ACCEPTED: %s\n",
245  flag (R_NOT_TESS_ACCEPTED) ? "T" : "F");
246  fprintf (fp, "R_CONTAINS_BLANKS: %s\n",
247  flag (R_CONTAINS_BLANKS) ? "T" : "F");
248  fprintf (fp, "R_BAD_PERMUTER: %s\n", flag (R_BAD_PERMUTER) ? "T" : "F");
249  fprintf (fp, "R_HYPHEN: %s\n", flag (R_HYPHEN) ? "T" : "F");
250  fprintf (fp, "R_DUBIOUS: %s\n", flag (R_DUBIOUS) ? "T" : "F");
251  fprintf (fp, "R_NO_ALPHANUMS: %s\n", flag (R_NO_ALPHANUMS) ? "T" : "F");
252  fprintf (fp, "R_MOSTLY_REJ: %s\n", flag (R_MOSTLY_REJ) ? "T" : "F");
253  fprintf (fp, "R_XHT_FIXUP: %s\n", flag (R_XHT_FIXUP) ? "T" : "F");
254  fprintf (fp, "R_BAD_QUALITY: %s\n", flag (R_BAD_QUALITY) ? "T" : "F");
255  fprintf (fp, "R_DOC_REJ: %s\n", flag (R_DOC_REJ) ? "T" : "F");
256  fprintf (fp, "R_BLOCK_REJ: %s\n", flag (R_BLOCK_REJ) ? "T" : "F");
257  fprintf (fp, "R_ROW_REJ: %s\n", flag (R_ROW_REJ) ? "T" : "F");
258  fprintf (fp, "R_UNLV_REJ: %s\n", flag (R_UNLV_REJ) ? "T" : "F");
259  fprintf (fp, "R_HYPHEN_ACCEPT: %s\n", flag (R_HYPHEN_ACCEPT) ? "T" : "F");
260  fprintf (fp, "R_NN_ACCEPT: %s\n", flag (R_NN_ACCEPT) ? "T" : "F");
261  fprintf (fp, "R_MM_ACCEPT: %s\n", flag (R_MM_ACCEPT) ? "T" : "F");
262  fprintf (fp, "R_QUALITY_ACCEPT: %s\n", flag (R_QUALITY_ACCEPT) ? "T" : "F");
263  fprintf (fp, "R_MINIMAL_REJ_ACCEPT: %s\n",
264  flag (R_MINIMAL_REJ_ACCEPT) ? "T" : "F");
265 }
266 
267 REJMAP &REJMAP::operator=(const REJMAP &source) {
268  initialise(source.len);
269  for (int i = 0; i < len; i++) {
270  ptr[i] = source.ptr[i];
271  }
272  return *this;
273 }
274 
275 void REJMAP::initialise(int16_t length) {
276  ptr.reset(new REJ[length]);
277  len = length;
278 }
279 
280 
281 int16_t REJMAP::accept_count() { //How many accepted?
282  int i;
283  int16_t count = 0;
284 
285  for (i = 0; i < len; i++) {
286  if (ptr[i].accepted ())
287  count++;
288  }
289  return count;
290 }
291 
292 
293 bool REJMAP::recoverable_rejects() { //Any non perm rejs?
294  for (int i = 0; i < len; i++) {
295  if (ptr[i].recoverable ())
296  return true;
297  }
298  return false;
299 }
300 
301 
302 bool REJMAP::quality_recoverable_rejects() { //Any potential rejs?
303  for (int i = 0; i < len; i++) {
304  if (ptr[i].accept_if_good_quality ())
305  return true;
306  }
307  return false;
308 }
309 
310 
311 void REJMAP::remove_pos( //Cut out an element
312  int16_t pos //element to remove
313  ) {
314  ASSERT_HOST (pos >= 0);
315  ASSERT_HOST (pos < len);
316  ASSERT_HOST (len > 0);
317 
318  len--;
319  for (; pos < len; pos++) ptr[pos] = ptr[pos + 1];
320 }
321 
322 
323 void REJMAP::print(FILE *fp) {
324  int i;
325  char buff[512];
326 
327  for (i = 0; i < len; i++) {
328  buff[i] = ptr[i].display_char ();
329  }
330  buff[i] = '\0';
331  fprintf (fp, "\"%s\"", buff);
332 }
333 
334 
335 void REJMAP::full_print(FILE *fp) {
336  int i;
337 
338  for (i = 0; i < len; i++) {
339  ptr[i].full_print (fp);
340  fprintf (fp, "\n");
341  }
342 }
343 
344 
345 void REJMAP::rej_word_small_xht() { //Reject whole word
346  int i;
347 
348  for (i = 0; i < len; i++) {
349  ptr[i].setrej_small_xht ();
350  }
351 }
352 
353 
354 void REJMAP::rej_word_tess_failure() { //Reject whole word
355  int i;
356 
357  for (i = 0; i < len; i++) {
358  ptr[i].setrej_tess_failure ();
359  }
360 }
361 
362 
363 void REJMAP::rej_word_not_tess_accepted() { //Reject whole word
364  int i;
365 
366  for (i = 0; i < len; i++) {
367  if (ptr[i].accepted()) ptr[i].setrej_not_tess_accepted();
368  }
369 }
370 
371 
372 void REJMAP::rej_word_contains_blanks() { //Reject whole word
373  int i;
374 
375  for (i = 0; i < len; i++) {
376  if (ptr[i].accepted()) ptr[i].setrej_contains_blanks();
377  }
378 }
379 
380 
381 void REJMAP::rej_word_bad_permuter() { //Reject whole word
382  int i;
383 
384  for (i = 0; i < len; i++) {
385  if (ptr[i].accepted()) ptr[i].setrej_bad_permuter ();
386  }
387 }
388 
389 
390 void REJMAP::rej_word_xht_fixup() { //Reject whole word
391  int i;
392 
393  for (i = 0; i < len; i++) {
394  if (ptr[i].accepted()) ptr[i].setrej_xht_fixup();
395  }
396 }
397 
398 
399 void REJMAP::rej_word_no_alphanums() { //Reject whole word
400  int i;
401 
402  for (i = 0; i < len; i++) {
403  if (ptr[i].accepted()) ptr[i].setrej_no_alphanums();
404  }
405 }
406 
407 
408 void REJMAP::rej_word_mostly_rej() { //Reject whole word
409  int i;
410 
411  for (i = 0; i < len; i++) {
412  if (ptr[i].accepted()) ptr[i].setrej_mostly_rej();
413  }
414 }
415 
416 
417 void REJMAP::rej_word_bad_quality() { //Reject whole word
418  int i;
419 
420  for (i = 0; i < len; i++) {
421  if (ptr[i].accepted()) ptr[i].setrej_bad_quality();
422  }
423 }
424 
425 
426 void REJMAP::rej_word_doc_rej() { //Reject whole word
427  int i;
428 
429  for (i = 0; i < len; i++) {
430  if (ptr[i].accepted()) ptr[i].setrej_doc_rej();
431  }
432 }
433 
434 
435 void REJMAP::rej_word_block_rej() { //Reject whole word
436  int i;
437 
438  for (i = 0; i < len; i++) {
439  if (ptr[i].accepted()) ptr[i].setrej_block_rej();
440  }
441 }
442 
443 
444 void REJMAP::rej_word_row_rej() { //Reject whole word
445  int i;
446 
447  for (i = 0; i < len; i++) {
448  if (ptr[i].accepted()) ptr[i].setrej_row_rej();
449  }
450 }
void setrej_minimal_rej_accept()
Definition: rejctmap.cpp:228
void setrej_doc_rej()
Definition: rejctmap.cpp:188
void setrej_hyphen_accept()
Definition: rejctmap.cpp:208
void rej_word_block_rej()
Definition: rejctmap.cpp:435
REJMAP & operator=(const REJMAP &source)
Definition: rejctmap.cpp:267
void setrej_mm_accept()
Definition: rejctmap.cpp:218
void setrej_bad_quality()
Definition: rejctmap.cpp:183
void setrej_contains_blanks()
Definition: rejctmap.cpp:147
void setrej_nn_accept()
Definition: rejctmap.cpp:213
void setrej_bad_permuter()
Definition: rejctmap.cpp:153
void rej_word_row_rej()
Definition: rejctmap.cpp:444
int count(LIST var_list)
Definition: oldlist.cpp:98
void full_print(FILE *fp)
Definition: rejctmap.cpp:335
void setrej_row_rej()
Definition: rejctmap.cpp:198
bool quality_recoverable_rejects()
Definition: rejctmap.cpp:302
int32_t length() const
Definition: rejctmap.h:223
void setrej_edge_char()
Definition: rejctmap.cpp:106
void rej_word_doc_rej()
Definition: rejctmap.cpp:426
void setrej_dubious()
Definition: rejctmap.cpp:163
void setrej_unlv_rej()
Definition: rejctmap.cpp:203
void setrej_mm_reject()
Definition: rejctmap.cpp:126
void setrej_poor_match()
Definition: rejctmap.cpp:136
void setrej_postNN_1Il()
Definition: rejctmap.cpp:116
void setrej_not_tess_accepted()
Definition: rejctmap.cpp:141
void setrej_small_xht()
Definition: rejctmap.cpp:101
void full_print(FILE *fp)
Definition: rejctmap.cpp:234
void setrej_1Il_conflict()
Definition: rejctmap.cpp:111
int16_t accept_count()
Definition: rejctmap.cpp:281
bool recoverable_rejects()
Definition: rejctmap.cpp:293
void rej_word_bad_permuter()
Definition: rejctmap.cpp:381
void setrej_xht_fixup()
Definition: rejctmap.cpp:178
void setrej_hyphen()
Definition: rejctmap.cpp:158
void setrej_no_alphanums()
Definition: rejctmap.cpp:168
bool perm_rejected()
Definition: rejctmap.cpp:24
Definition: rejctmap.h:97
void setrej_tess_failure()
Definition: rejctmap.cpp:96
bool rejected()
Definition: rejctmap.cpp:73
void rej_word_small_xht()
Definition: rejctmap.cpp:345
bool accept_if_good_quality()
Definition: rejctmap.cpp:83
void setrej_bad_repetition()
Definition: rejctmap.cpp:131
void rej_word_no_alphanums()
Definition: rejctmap.cpp:399
void rej_word_tess_failure()
Definition: rejctmap.cpp:354
void setrej_block_rej()
Definition: rejctmap.cpp:193
void rej_word_not_tess_accepted()
Definition: rejctmap.cpp:363
void setrej_rej_cblob()
Definition: rejctmap.cpp:121
void rej_word_contains_blanks()
Definition: rejctmap.cpp:372
void setrej_quality_accept()
Definition: rejctmap.cpp:223
void rej_word_mostly_rej()
Definition: rejctmap.cpp:408
void print(FILE *fp)
Definition: rejctmap.cpp:323
void rej_word_bad_quality()
Definition: rejctmap.cpp:417
void setrej_mostly_rej()
Definition: rejctmap.cpp:173
void initialise(int16_t length)
Definition: rejctmap.cpp:275
void remove_pos(int16_t pos)
Definition: rejctmap.cpp:311
bool flag(REJ_FLAGS rej_flag)
Definition: rejctmap.h:132
#define ASSERT_HOST(x)
Definition: errcode.h:84
void rej_word_xht_fixup()
Definition: rejctmap.cpp:390