tesseract  5.0.0-alpha-619-ge9db
ratngs.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: ratngs.h (Formerly ratings.h)
3  * Description: Definition of the WERD_CHOICE and BLOB_CHOICE classes.
4  * Author: Ray Smith
5  *
6  * (C) Copyright 1992, Hewlett-Packard Ltd.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  *
17  **********************************************************************/
18 
19 #ifndef RATNGS_H
20 #define RATNGS_H
21 
22 #include <cassert>
23 #include <cfloat> // for FLT_MAX
24 
25 #include "clst.h"
26 #include "elst.h"
27 #ifndef DISABLED_LEGACY_ENGINE
28 #include "fontinfo.h"
29 #endif // ndef DISABLED_LEGACY_ENGINE
31 #include "matrix.h"
32 #include <tesseract/unichar.h>
33 #include "unicharset.h"
34 #include "werd.h"
35 
36 class MATRIX;
37 struct TBLOB;
38 struct TWERD;
39 
40 // Enum to describe the source of a BLOB_CHOICE to make it possible to determine
41 // whether a blob has been classified by inspecting the BLOB_CHOICEs.
43  BCC_STATIC_CLASSIFIER, // From the char_norm classifier.
44  BCC_ADAPTED_CLASSIFIER, // From the adaptive classifier.
45  BCC_SPECKLE_CLASSIFIER, // Backup for failed classification.
46  BCC_AMBIG, // Generated by ambiguity detection.
47  BCC_FAKE, // From some other process.
48 };
49 
50 class BLOB_CHOICE: public ELIST_LINK
51 {
52  public:
53  BLOB_CHOICE() {
54  unichar_id_ = UNICHAR_SPACE;
55  fontinfo_id_ = -1;
56  fontinfo_id2_ = -1;
57  rating_ = 10.0;
58  certainty_ = -1.0;
59  script_id_ = -1;
60  min_xheight_ = 0.0f;
61  max_xheight_ = 0.0f;
62  yshift_ = 0.0f;
63  classifier_ = BCC_FAKE;
64  }
65  BLOB_CHOICE(UNICHAR_ID src_unichar_id, // character id
66  float src_rating, // rating
67  float src_cert, // certainty
68  int script_id, // script
69  float min_xheight, // min xheight in image pixel units
70  float max_xheight, // max xheight allowed by this char
71  float yshift, // the larger of y shift (top or bottom)
72  BlobChoiceClassifier c); // adapted match or other
73  BLOB_CHOICE(const BLOB_CHOICE &other);
74  ~BLOB_CHOICE() = default;
75 
76  UNICHAR_ID unichar_id() const {
77  return unichar_id_;
78  }
79  float rating() const {
80  return rating_;
81  }
82  float certainty() const {
83  return certainty_;
84  }
85  int16_t fontinfo_id() const {
86  return fontinfo_id_;
87  }
88  int16_t fontinfo_id2() const {
89  return fontinfo_id2_;
90  }
91  #ifndef DISABLED_LEGACY_ENGINE
93  return fonts_;
94  }
96  fonts_ = fonts;
97  int score1 = 0, score2 = 0;
98  fontinfo_id_ = -1;
99  fontinfo_id2_ = -1;
100  for (int f = 0; f < fonts_.size(); ++f) {
101  if (fonts_[f].score > score1) {
102  score2 = score1;
103  fontinfo_id2_ = fontinfo_id_;
104  score1 = fonts_[f].score;
105  fontinfo_id_ = fonts_[f].fontinfo_id;
106  } else if (fonts_[f].score > score2) {
107  score2 = fonts_[f].score;
108  fontinfo_id2_ = fonts_[f].fontinfo_id;
109  }
110  }
111  }
112  #endif // ndef DISABLED_LEGACY_ENGINE
113  int script_id() const {
114  return script_id_;
115  }
116  const MATRIX_COORD& matrix_cell() {
117  return matrix_cell_;
118  }
119  float min_xheight() const {
120  return min_xheight_;
121  }
122  float max_xheight() const {
123  return max_xheight_;
124  }
125  float yshift() const {
126  return yshift_;
127  }
129  return classifier_;
130  }
131  bool IsAdapted() const {
132  return classifier_ == BCC_ADAPTED_CLASSIFIER;
133  }
134  bool IsClassified() const {
135  return classifier_ == BCC_STATIC_CLASSIFIER ||
136  classifier_ == BCC_ADAPTED_CLASSIFIER ||
137  classifier_ == BCC_SPECKLE_CLASSIFIER;
138  }
139 
140  void set_unichar_id(UNICHAR_ID newunichar_id) {
141  unichar_id_ = newunichar_id;
142  }
143  void set_rating(float newrat) {
144  rating_ = newrat;
145  }
146  void set_certainty(float newrat) {
147  certainty_ = newrat;
148  }
149  void set_script(int newscript_id) {
150  script_id_ = newscript_id;
151  }
152  void set_matrix_cell(int col, int row) {
153  matrix_cell_.col = col;
154  matrix_cell_.row = row;
155  }
157  classifier_ = classifier;
158  }
159  static BLOB_CHOICE* deep_copy(const BLOB_CHOICE* src) {
160  auto* choice = new BLOB_CHOICE;
161  *choice = *src;
162  return choice;
163  }
164  // Returns true if *this and other agree on the baseline and x-height
165  // to within some tolerance based on a given estimate of the x-height.
166  bool PosAndSizeAgree(const BLOB_CHOICE& other, float x_height,
167  bool debug) const;
168 
169  void print(const UNICHARSET *unicharset) const {
170  tprintf("r%.2f c%.2f x[%g,%g]: %d %s",
171  rating_, certainty_,
172  min_xheight_, max_xheight_, unichar_id_,
173  (unicharset == nullptr) ? "" :
174  unicharset->debug_str(unichar_id_).c_str());
175  }
176  void print_full() const {
177  print(nullptr);
178  tprintf(" script=%d, font1=%d, font2=%d, yshift=%g, classifier=%d\n",
179  script_id_, fontinfo_id_, fontinfo_id2_, yshift_, classifier_);
180  }
181  // Sort function for sorting BLOB_CHOICEs in increasing order of rating.
182  static int SortByRating(const void *p1, const void *p2) {
183  const BLOB_CHOICE *bc1 = *static_cast<const BLOB_CHOICE *const *>(p1);
184  const BLOB_CHOICE *bc2 = *static_cast<const BLOB_CHOICE *const *>(p2);
185  return (bc1->rating_ < bc2->rating_) ? -1 : 1;
186  }
187 
188  private:
189  // Copy assignment operator.
190  BLOB_CHOICE& operator=(const BLOB_CHOICE& other);
191 
192  UNICHAR_ID unichar_id_; // unichar id
193 #ifndef DISABLED_LEGACY_ENGINE
194  // Fonts and scores. Allowed to be empty.
196 #endif // ndef DISABLED_LEGACY_ENGINE
197  int16_t fontinfo_id_; // char font information
198  int16_t fontinfo_id2_; // 2nd choice font information
199  // Rating is the classifier distance weighted by the length of the outline
200  // in the blob. In terms of probability, classifier distance is -klog p such
201  // that the resulting distance is in the range [0, 1] and then
202  // rating = w (-k log p) where w is the weight for the length of the outline.
203  // Sums of ratings may be compared meaningfully for words of different
204  // segmentation.
205  float rating_; // size related
206  // Certainty is a number in [-20, 0] indicating the classifier certainty
207  // of the choice. In terms of probability, certainty = 20 (k log p) where
208  // k is defined as above to normalize -klog p to the range [0, 1].
209  float certainty_; // absolute
210  int script_id_;
211  // Holds the position of this choice in the ratings matrix.
212  // Used to location position in the matrix during path backtracking.
213  MATRIX_COORD matrix_cell_;
214  // X-height range (in image pixels) that this classification supports.
215  float min_xheight_;
216  float max_xheight_;
217  // yshift_ - The vertical distance (in image pixels) the character is
218  // shifted (up or down) from an acceptable y position.
219  float yshift_;
220  BlobChoiceClassifier classifier_; // What generated *this.
221 };
222 
223 // Make BLOB_CHOICE listable.
225 
226 // Return the BLOB_CHOICE in bc_list matching a given unichar_id,
227 // or nullptr if there is no match.
228 BLOB_CHOICE *FindMatchingChoice(UNICHAR_ID char_id, BLOB_CHOICE_LIST *bc_list);
229 
230 // Permuter codes used in WERD_CHOICEs.
232  NO_PERM, // 0
233  PUNC_PERM, // 1
244  COMPOUND_PERM, // 12
245 
247 };
248 
249 namespace tesseract {
250 // ScriptPos tells whether a character is subscript, superscript or normal.
251 enum ScriptPos {
255  SP_DROPCAP
256 };
257 
258 const char *ScriptPosToString(tesseract::ScriptPos script_pos);
259 
260 } // namespace tesseract.
261 
262 class WERD_CHOICE : public ELIST_LINK {
263  public:
264  static const float kBadRating;
265  static const char *permuter_name(uint8_t permuter);
266 
268  : unicharset_(unicharset) { this->init(8); }
269  WERD_CHOICE(const UNICHARSET *unicharset, int reserved)
270  : unicharset_(unicharset) { this->init(reserved); }
271  WERD_CHOICE(const char *src_string,
272  const char *src_lengths,
273  float src_rating,
274  float src_certainty,
275  uint8_t src_permuter,
276  const UNICHARSET &unicharset)
277  : unicharset_(&unicharset) {
278  this->init(src_string, src_lengths, src_rating,
279  src_certainty, src_permuter);
280  }
281  WERD_CHOICE(const char *src_string, const UNICHARSET &unicharset);
282  WERD_CHOICE(const WERD_CHOICE &word)
283  : ELIST_LINK(word), unicharset_(word.unicharset_) {
284  this->init(word.length());
285  this->operator=(word);
286  }
287  ~WERD_CHOICE();
288 
289  const UNICHARSET *unicharset() const {
290  return unicharset_;
291  }
292  inline int length() const {
293  return length_;
294  }
295  float adjust_factor() const {
296  return adjust_factor_;
297  }
298  void set_adjust_factor(float factor) {
299  adjust_factor_ = factor;
300  }
301  inline const UNICHAR_ID *unichar_ids() const {
302  return unichar_ids_;
303  }
304  inline UNICHAR_ID unichar_id(int index) const {
305  assert(index < length_);
306  return unichar_ids_[index];
307  }
308  inline int state(int index) const {
309  return state_[index];
310  }
311  tesseract::ScriptPos BlobPosition(int index) const {
312  if (index < 0 || index >= length_)
313  return tesseract::SP_NORMAL;
314  return script_pos_[index];
315  }
316  inline float rating() const {
317  return rating_;
318  }
319  inline float certainty() const {
320  return certainty_;
321  }
322  inline float certainty(int index) const {
323  return certainties_[index];
324  }
325  inline float min_x_height() const {
326  return min_x_height_;
327  }
328  inline float max_x_height() const {
329  return max_x_height_;
330  }
331  inline void set_x_heights(float min_height, float max_height) {
332  min_x_height_ = min_height;
333  max_x_height_ = max_height;
334  }
335  inline uint8_t permuter() const {
336  return permuter_;
337  }
338  const char *permuter_name() const;
339  // Returns the BLOB_CHOICE_LIST corresponding to the given index in the word,
340  // taken from the appropriate cell in the ratings MATRIX.
341  // Borrowed pointer, so do not delete.
342  BLOB_CHOICE_LIST* blob_choices(int index, MATRIX* ratings) const;
343 
344  // Returns the MATRIX_COORD corresponding to the location in the ratings
345  // MATRIX for the given index into the word.
346  MATRIX_COORD MatrixCoord(int index) const;
347 
348  inline void set_unichar_id(UNICHAR_ID unichar_id, int index) {
349  assert(index < length_);
350  unichar_ids_[index] = unichar_id;
351  }
352  bool dangerous_ambig_found() const {
353  return dangerous_ambig_found_;
354  }
355  void set_dangerous_ambig_found_(bool value) {
356  dangerous_ambig_found_ = value;
357  }
358  inline void set_rating(float new_val) {
359  rating_ = new_val;
360  }
361  inline void set_certainty(float new_val) {
362  certainty_ = new_val;
363  }
364  inline void set_permuter(uint8_t perm) {
365  permuter_ = perm;
366  }
367  // Note: this function should only be used if all the fields
368  // are populated manually with set_* functions (rather than
369  // (copy)constructors and append_* functions).
370  inline void set_length(int len) {
371  ASSERT_HOST(reserved_ >= len);
372  length_ = len;
373  }
374 
376  inline void double_the_size() {
377  if (reserved_ > 0) {
379  reserved_, unichar_ids_);
381  reserved_, script_pos_);
383  reserved_, state_);
385  reserved_, certainties_);
386  reserved_ *= 2;
387  } else {
388  unichar_ids_ = new UNICHAR_ID[1];
389  script_pos_ = new tesseract::ScriptPos[1];
390  state_ = new int[1];
391  certainties_ = new float[1];
392  reserved_ = 1;
393  }
394  }
395 
398  inline void init(int reserved) {
399  reserved_ = reserved;
400  if (reserved > 0) {
401  unichar_ids_ = new UNICHAR_ID[reserved];
402  script_pos_ = new tesseract::ScriptPos[reserved];
403  state_ = new int[reserved];
404  certainties_ = new float[reserved];
405  } else {
406  unichar_ids_ = nullptr;
407  script_pos_ = nullptr;
408  state_ = nullptr;
409  certainties_ = nullptr;
410  }
411  length_ = 0;
412  adjust_factor_ = 1.0f;
413  rating_ = 0.0;
414  certainty_ = FLT_MAX;
415  min_x_height_ = 0.0f;
416  max_x_height_ = FLT_MAX;
417  permuter_ = NO_PERM;
418  unichars_in_script_order_ = false; // Tesseract is strict left-to-right.
419  dangerous_ambig_found_ = false;
420  }
421 
427  void init(const char *src_string, const char *src_lengths,
428  float src_rating, float src_certainty,
429  uint8_t src_permuter);
430 
432  inline void make_bad() {
433  length_ = 0;
434  rating_ = kBadRating;
435  certainty_ = -FLT_MAX;
436  }
437 
442  UNICHAR_ID unichar_id, int blob_count,
443  float rating, float certainty) {
444  assert(reserved_ > length_);
445  length_++;
446  this->set_unichar_id(unichar_id, blob_count,
447  rating, certainty, length_-1);
448  }
449 
450  void append_unichar_id(UNICHAR_ID unichar_id, int blob_count,
451  float rating, float certainty);
452 
453  inline void set_unichar_id(UNICHAR_ID unichar_id, int blob_count,
454  float rating, float certainty, int index) {
455  assert(index < length_);
456  unichar_ids_[index] = unichar_id;
457  state_[index] = blob_count;
458  certainties_[index] = certainty;
459  script_pos_[index] = tesseract::SP_NORMAL;
460  rating_ += rating;
461  if (certainty < certainty_) {
462  certainty_ = certainty;
463  }
464  }
465  // Sets the entries for the given index from the BLOB_CHOICE, assuming
466  // unit fragment lengths, but setting the state for this index to blob_count.
467  void set_blob_choice(int index, int blob_count,
468  const BLOB_CHOICE* blob_choice);
469 
471  void remove_unichar_ids(int index, int num);
472  inline void remove_last_unichar_id() { --length_; }
473  inline void remove_unichar_id(int index) {
474  this->remove_unichar_ids(index, 1);
475  }
476  bool has_rtl_unichar_id() const;
478 
479  // Returns the half-open interval of unichar_id indices [start, end) which
480  // enclose the core portion of this word -- the part after stripping
481  // punctuation from the left and right.
482  void punct_stripped(int *start_core, int *end_core) const;
483 
484  // Returns the indices [start, end) containing the core of the word, stripped
485  // of any superscript digits on either side. (i.e., the non-footnote part
486  // of the word). There is no guarantee that the output range is non-empty.
487  void GetNonSuperscriptSpan(int *start, int *end) const;
488 
489  // Return a copy of this WERD_CHOICE with the choices [start, end).
490  // The result is useful only for checking against a dictionary.
491  WERD_CHOICE shallow_copy(int start, int end) const;
492 
493  void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const;
494  const STRING debug_string() const {
495  STRING word_str;
496  for (int i = 0; i < length_; ++i) {
497  word_str += unicharset_->debug_str(unichar_ids_[i]);
498  word_str += " ";
499  }
500  return word_str;
501  }
502  // Returns true if any unichar_id in the word is a non-space-delimited char.
503  bool ContainsAnyNonSpaceDelimited() const {
504  for (int i = 0; i < length_; ++i) {
505  if (!unicharset_->IsSpaceDelimited(unichar_ids_[i])) return true;
506  }
507  return false;
508  }
509  // Returns true if the word is all spaces.
510  bool IsAllSpaces() const {
511  for (int i = 0; i < length_; ++i) {
512  if (unichar_ids_[i] != UNICHAR_SPACE) return false;
513  }
514  return true;
515  }
516 
517  // Call this to override the default (strict left to right graphemes)
518  // with the fact that some engine produces a "reading order" set of
519  // Graphemes for each word.
520  bool set_unichars_in_script_order(bool in_script_order) {
521  return unichars_in_script_order_ = in_script_order;
522  }
523 
524  bool unichars_in_script_order() const {
525  return unichars_in_script_order_;
526  }
527 
528  // Returns a UTF-8 string equivalent to the current choice
529  // of UNICHAR IDs.
530  const STRING &unichar_string() const {
531  this->string_and_lengths(&unichar_string_, &unichar_lengths_);
532  return unichar_string_;
533  }
534 
535  // Returns the lengths, one byte each, representing the number of bytes
536  // required in the unichar_string for each UNICHAR_ID.
537  const STRING &unichar_lengths() const {
538  this->string_and_lengths(&unichar_string_, &unichar_lengths_);
539  return unichar_lengths_;
540  }
541 
542  // Sets up the script_pos_ member using the blobs_list to get the bln
543  // bounding boxes, *this to get the unichars, and this->unicharset
544  // to get the target positions. If small_caps is true, sub/super are not
545  // considered, but dropcaps are.
546  // NOTE: blobs_list should be the chopped_word blobs. (Fully segemented.)
547  void SetScriptPositions(bool small_caps, TWERD* word, int debug = 0);
548  // Sets the script_pos_ member from some source positions with a given length.
549  void SetScriptPositions(const tesseract::ScriptPos* positions, int length);
550  // Sets all the script_pos_ positions to the given position.
552 
553  static tesseract::ScriptPos ScriptPositionOf(bool print_debug,
554  const UNICHARSET& unicharset,
555  const TBOX& blob_box,
557 
558  // Returns the "dominant" script ID for the word. By "dominant", the script
559  // must account for at least half the characters. Otherwise, it returns 0.
560  // Note that for Japanese, Hiragana and Katakana are simply treated as Han.
561  int GetTopScriptID() const;
562 
563  // Fixes the state_ for a chop at the given blob_posiiton.
564  void UpdateStateForSplit(int blob_position);
565 
566  // Returns the sum of all the state elements, being the total number of blobs.
567  int TotalOfStates() const;
568 
569  void print() const { this->print(""); }
570  void print(const char *msg) const;
571  // Prints the segmentation state with an introductory message.
572  void print_state(const char *msg) const;
573 
574  // Displays the segmentation state of *this (if not the same as the last
575  // one displayed) and waits for a click in the window.
576  void DisplaySegmentation(TWERD* word);
577 
578  WERD_CHOICE& operator+= ( // concatanate
579  const WERD_CHOICE & second);// second on first
580 
581  WERD_CHOICE& operator= (const WERD_CHOICE& source);
582 
583  private:
584  const UNICHARSET *unicharset_;
585  // TODO(rays) Perhaps replace the multiple arrays with an array of structs?
586  // unichar_ids_ is an array of classifier "results" that make up a word.
587  // For each unichar_ids_[i], script_pos_[i] has the sub/super/normal position
588  // of each unichar_id.
589  // state_[i] indicates the number of blobs in WERD_RES::chopped_word that
590  // were put together to make the classification results in the ith position
591  // in unichar_ids_, and certainties_[i] is the certainty of the choice that
592  // was used in this word.
593  // == Change from before ==
594  // Previously there was fragment_lengths_ that allowed a word to be
595  // artificially composed of multiple fragment results. Since the new
596  // segmentation search doesn't do fragments, treatment of fragments has
597  // been moved to a lower level, augmenting the ratings matrix with the
598  // combined fragments, and allowing the language-model/segmentation-search
599  // to deal with only the combined unichar_ids.
600  UNICHAR_ID *unichar_ids_; // unichar ids that represent the text of the word
601  tesseract::ScriptPos* script_pos_; // Normal/Sub/Superscript of each unichar.
602  int* state_; // Number of blobs in each unichar.
603  float* certainties_; // Certainty of each unichar.
604  int reserved_; // size of the above arrays
605  int length_; // word length
606  // Factor that was used to adjust the rating.
607  float adjust_factor_;
608  // Rating is the sum of the ratings of the individual blobs in the word.
609  float rating_; // size related
610  // certainty is the min (worst) certainty of the individual blobs in the word.
611  float certainty_; // absolute
612  // xheight computed from the result, or 0 if inconsistent.
613  float min_x_height_;
614  float max_x_height_;
615  uint8_t permuter_; // permuter code
616 
617  // Normally, the ratings_ matrix represents the recognition results in order
618  // from left-to-right. However, some engines (say Cube) may return
619  // recognition results in the order of the script's major reading direction
620  // (for Arabic, that is right-to-left).
621  bool unichars_in_script_order_;
622  // True if NoDangerousAmbig found an ambiguity.
623  bool dangerous_ambig_found_;
624 
625  // The following variables are populated and passed by reference any
626  // time unichar_string() or unichar_lengths() are called.
627  mutable STRING unichar_string_;
628  mutable STRING unichar_lengths_;
629 };
630 
631 // Make WERD_CHOICE listable.
634 
635 // Utilities for comparing WERD_CHOICEs
636 
638  const WERD_CHOICE &word2);
639 
640 // Utilities for debug printing.
641 void print_ratings_list(
642  const char *msg, // intro message
643  BLOB_CHOICE_LIST *ratings, // list of results
644  const UNICHARSET &current_unicharset // unicharset that can be used
645  // for id-to-unichar conversion
646  );
647 
648 #endif
WERD_CHOICE::unichar_string
const STRING & unichar_string() const
Definition: ratngs.h:529
WERD_CHOICE::set_length
void set_length(int len)
Definition: ratngs.h:369
elst.h
WERD_CHOICE::set_unichars_in_script_order
bool set_unichars_in_script_order(bool in_script_order)
Definition: ratngs.h:519
WERD_CHOICE::shallow_copy
WERD_CHOICE shallow_copy(int start, int end) const
Definition: ratngs.cpp:416
BlobChoiceClassifier
BlobChoiceClassifier
Definition: ratngs.h:41
WERD_CHOICE::set_adjust_factor
void set_adjust_factor(float factor)
Definition: ratngs.h:297
NUM_PERMUTER_TYPES
Definition: ratngs.h:245
BCC_FAKE
Definition: ratngs.h:46
WERD_CHOICE::unichar_id
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:303
WERD_CHOICE
Definition: ratngs.h:261
WERD_CHOICE::dangerous_ambig_found
bool dangerous_ambig_found() const
Definition: ratngs.h:351
TWERD
Definition: blobs.h:416
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
BLOB_CHOICE::min_xheight
float min_xheight() const
Definition: ratngs.h:118
SYSTEM_DAWG_PERM
Definition: ratngs.h:239
WERD_CHOICE::GetTopScriptID
int GetTopScriptID() const
Definition: ratngs.cpp:669
WERD_CHOICE::set_certainty
void set_certainty(float new_val)
Definition: ratngs.h:360
BLOB_CHOICE::certainty
float certainty() const
Definition: ratngs.h:81
WERD_CHOICE::TotalOfStates
int TotalOfStates() const
Definition: ratngs.cpp:713
PermuterType
PermuterType
Definition: ratngs.h:230
WERD_CHOICE::contains_unichar_id
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: ratngs.cpp:328
WERD_CHOICE::make_bad
void make_bad()
Set the fields in this choice to be default (bad) values.
Definition: ratngs.h:431
GenericVector::double_the_size_memcpy
static T * double_the_size_memcpy(int current_size, T *data)
Definition: genericvector.h:207
BLOB_CHOICE::print
void print(const UNICHARSET *unicharset) const
Definition: ratngs.h:168
MATRIX
Definition: matrix.h:574
WERD_CHOICE::certainty
float certainty() const
Definition: ratngs.h:318
NO_PERM
Definition: ratngs.h:231
STRING
Definition: strngs.h:45
BCC_ADAPTED_CLASSIFIER
Definition: ratngs.h:43
WERD_CHOICE::permuter
uint8_t permuter() const
Definition: ratngs.h:334
WERD_CHOICE::operator+=
WERD_CHOICE & operator+=(const WERD_CHOICE &second)
Definition: ratngs.cpp:487
BLOB_CHOICE::BLOB_CHOICE
BLOB_CHOICE()
Definition: ratngs.h:52
COMPOUND_PERM
Definition: ratngs.h:243
UNICHARSET::IsSpaceDelimited
bool IsSpaceDelimited(UNICHAR_ID unichar_id) const
Definition: unicharset.h:642
WERD_CHOICE::append_unichar_id_space_allocated
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
Definition: ratngs.h:440
WERD_CHOICE::WERD_CHOICE
WERD_CHOICE(const WERD_CHOICE &word)
Definition: ratngs.h:281
print_ratings_list
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET &current_unicharset)
Definition: ratngs.cpp:835
WERD_CHOICE::unicharset
const UNICHARSET * unicharset() const
Definition: ratngs.h:288
WERD_CHOICE::kBadRating
static const float kBadRating
Definition: ratngs.h:263
BLOB_CHOICE::script_id
int script_id() const
Definition: ratngs.h:112
WERD_CHOICE::state
int state(int index) const
Definition: ratngs.h:307
WERD_CHOICE::BlobPosition
tesseract::ScriptPos BlobPosition(int index) const
Definition: ratngs.h:310
BLOB_CHOICE::unichar_id
UNICHAR_ID unichar_id() const
Definition: ratngs.h:75
ELISTIZEH
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:907
BLOB_CHOICE::set_script
void set_script(int newscript_id)
Definition: ratngs.h:148
BCC_AMBIG
Definition: ratngs.h:45
BLOB_CHOICE::set_classifier
void set_classifier(BlobChoiceClassifier classifier)
Definition: ratngs.h:155
BLOB_CHOICE::matrix_cell
const MATRIX_COORD & matrix_cell()
Definition: ratngs.h:115
werd.h
WERD_CHOICE::reverse_and_mirror_unichar_ids
void reverse_and_mirror_unichar_ids()
Definition: ratngs.cpp:367
tesseract::SP_SUBSCRIPT
Definition: ratngs.h:252
WERD_CHOICE::init
void init(int reserved)
Definition: ratngs.h:397
BLOB_CHOICE::set_rating
void set_rating(float newrat)
Definition: ratngs.h:142
WERD_CHOICE::string_and_lengths
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
Definition: ratngs.cpp:451
genericvector.h
WERD_CHOICE::SetScriptPositions
void SetScriptPositions(bool small_caps, TWERD *word, int debug=0)
Definition: ratngs.cpp:552
UPPER_CASE_PERM
Definition: ratngs.h:235
WERD_CHOICE::punct_stripped
void punct_stripped(int *start_core, int *end_core) const
Definition: ratngs.cpp:385
tesseract::ScriptPos
ScriptPos
Definition: ratngs.h:250
BLOB_CHOICE::set_matrix_cell
void set_matrix_cell(int col, int row)
Definition: ratngs.h:151
BLOB_CHOICE::SortByRating
static int SortByRating(const void *p1, const void *p2)
Definition: ratngs.h:181
WERD_CHOICE::IsAllSpaces
bool IsAllSpaces() const
Definition: ratngs.h:509
WERD_CHOICE::set_unichar_id
void set_unichar_id(UNICHAR_ID unichar_id, int index)
Definition: ratngs.h:347
WERD_CHOICE::min_x_height
float min_x_height() const
Definition: ratngs.h:324
UNICHARSET::debug_str
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:342
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
unicharset.h
BLOB_CHOICE::set_certainty
void set_certainty(float newrat)
Definition: ratngs.h:145
WERD_CHOICE::MatrixCoord
MATRIX_COORD MatrixCoord(int index) const
Definition: ratngs.cpp:304
WERD_CHOICE::double_the_size
void double_the_size()
Make more space in unichar_id_ and fragment_lengths_ arrays.
Definition: ratngs.h:375
BLOB_CHOICE::classifier
BlobChoiceClassifier classifier() const
Definition: ratngs.h:127
UNICHAR_SPACE
Definition: unicharset.h:34
matrix.h
WERD_CHOICE::~WERD_CHOICE
~WERD_CHOICE()
Definition: ratngs.cpp:278
EqualIgnoringCaseAndTerminalPunct
bool EqualIgnoringCaseAndTerminalPunct(const WERD_CHOICE &word1, const WERD_CHOICE &word2)
Definition: ratngs.cpp:807
BLOB_CHOICE::max_xheight
float max_xheight() const
Definition: ratngs.h:121
WERD_CHOICE::adjust_factor
float adjust_factor() const
Definition: ratngs.h:294
WERD_CHOICE::UpdateStateForSplit
void UpdateStateForSplit(int blob_position)
Definition: ratngs.cpp:701
UNICHARSET
Definition: unicharset.h:145
WERD_CHOICE::unichars_in_script_order
bool unichars_in_script_order() const
Definition: ratngs.h:523
WERD_CHOICE::GetNonSuperscriptSpan
void GetNonSuperscriptSpan(int *start, int *end) const
Definition: ratngs.cpp:399
NGRAM_PERM
Definition: ratngs.h:236
BLOB_CHOICE::fonts
const GenericVector< tesseract::ScoredFont > & fonts() const
Definition: ratngs.h:91
tesseract::SP_NORMAL
Definition: ratngs.h:251
WERD_CHOICE::set_rating
void set_rating(float new_val)
Definition: ratngs.h:357
tesseract
Definition: baseapi.h:65
WERD_CHOICE::debug_string
const STRING debug_string() const
Definition: ratngs.h:493
fontinfo.h
WERD_CHOICE::ContainsAnyNonSpaceDelimited
bool ContainsAnyNonSpaceDelimited() const
Definition: ratngs.h:502
WERD_CHOICE::DisplaySegmentation
void DisplaySegmentation(TWERD *word)
Definition: ratngs.cpp:763
TOP_CHOICE_PERM
Definition: ratngs.h:233
tesseract::SP_DROPCAP
Definition: ratngs.h:254
BLOB_CHOICE::rating
float rating() const
Definition: ratngs.h:78
UNICHAR_ID
int UNICHAR_ID
Definition: unichar.h:36
USER_PATTERN_PERM
Definition: ratngs.h:238
GenericVector< tesseract::ScoredFont >
WERD_CHOICE::has_rtl_unichar_id
bool has_rtl_unichar_id() const
Definition: ratngs.cpp:433
BLOB_CHOICE::fontinfo_id
int16_t fontinfo_id() const
Definition: ratngs.h:84
BLOB_CHOICE::~BLOB_CHOICE
~BLOB_CHOICE()=default
WERD_CHOICE::remove_last_unichar_id
void remove_last_unichar_id()
Definition: ratngs.h:471
WERD_CHOICE::print_state
void print_state(const char *msg) const
Definition: ratngs.cpp:754
WERD_CHOICE::set_x_heights
void set_x_heights(float min_height, float max_height)
Definition: ratngs.h:330
BLOB_CHOICE::PosAndSizeAgree
bool PosAndSizeAgree(const BLOB_CHOICE &other, float x_height, bool debug) const
Definition: ratngs.cpp:154
BLOB_CHOICE::deep_copy
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:158
FindMatchingChoice
BLOB_CHOICE * FindMatchingChoice(UNICHAR_ID char_id, BLOB_CHOICE_LIST *bc_list)
Definition: ratngs.cpp:182
WERD_CHOICE::operator=
WERD_CHOICE & operator=(const WERD_CHOICE &source)
Definition: ratngs.cpp:523
WERD_CHOICE::print
void print() const
Definition: ratngs.h:568
BLOB_CHOICE::fontinfo_id2
int16_t fontinfo_id2() const
Definition: ratngs.h:87
WERD_CHOICE::length
int length() const
Definition: ratngs.h:291
BLOB_CHOICE
Definition: ratngs.h:49
MATRIX_COORD
Definition: matrix.h:604
TBLOB
Definition: blobs.h:282
BLOB_CHOICE::yshift
float yshift() const
Definition: ratngs.h:124
WERD_CHOICE::set_dangerous_ambig_found_
void set_dangerous_ambig_found_(bool value)
Definition: ratngs.h:354
WERD_CHOICE::SetAllScriptPositions
void SetAllScriptPositions(tesseract::ScriptPos position)
Definition: ratngs.cpp:625
unichar.h
tesseract::SP_SUPERSCRIPT
Definition: ratngs.h:253
MATRIX_COORD::col
int col
Definition: matrix.h:632
BLOB_CHOICE::print_full
void print_full() const
Definition: ratngs.h:175
BLOB_CHOICE::set_fonts
void set_fonts(const GenericVector< tesseract::ScoredFont > &fonts)
Definition: ratngs.h:94
WERD_CHOICE::permuter_name
const char * permuter_name() const
Definition: ratngs.cpp:285
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
WERD_CHOICE::WERD_CHOICE
WERD_CHOICE(const UNICHARSET *unicharset)
Definition: ratngs.h:266
WERD_CHOICE::ScriptPositionOf
static tesseract::ScriptPos ScriptPositionOf(bool print_debug, const UNICHARSET &unicharset, const TBOX &blob_box, UNICHAR_ID unichar_id)
Definition: ratngs.cpp:631
ELIST_LINK
Definition: elst.h:74
LOWER_CASE_PERM
Definition: ratngs.h:234
MATRIX_COORD::row
int row
Definition: matrix.h:633
BLOB_CHOICE::IsAdapted
bool IsAdapted() const
Definition: ratngs.h:130
WERD_CHOICE::remove_unichar_ids
void remove_unichar_ids(int index, int num)
Definition: ratngs.cpp:344
WERD_CHOICE::rating
float rating() const
Definition: ratngs.h:315
WERD_CHOICE::unichar_ids
const UNICHAR_ID * unichar_ids() const
Definition: ratngs.h:300
WERD_CHOICE::remove_unichar_id
void remove_unichar_id(int index)
Definition: ratngs.h:472
DOC_DAWG_PERM
Definition: ratngs.h:240
PUNC_PERM
Definition: ratngs.h:232
GenericVector::size
int size() const
Definition: genericvector.h:71
WERD_CHOICE::set_permuter
void set_permuter(uint8_t perm)
Definition: ratngs.h:363
BLOB_CHOICE::set_unichar_id
void set_unichar_id(UNICHAR_ID newunichar_id)
Definition: ratngs.h:139
WERD_CHOICE::unichar_lengths
const STRING & unichar_lengths() const
Definition: ratngs.h:536
WERD_CHOICE::set_blob_choice
void set_blob_choice(int index, int blob_count, const BLOB_CHOICE *blob_choice)
Definition: ratngs.cpp:314
FREQ_DAWG_PERM
Definition: ratngs.h:242
WERD_CHOICE::append_unichar_id
void append_unichar_id(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
Definition: ratngs.cpp:470
WERD_CHOICE::blob_choices
BLOB_CHOICE_LIST * blob_choices(int index, MATRIX *ratings) const
Definition: ratngs.cpp:292
NUMBER_PERM
Definition: ratngs.h:237
clst.h
BCC_SPECKLE_CLASSIFIER
Definition: ratngs.h:44
USER_DAWG_PERM
Definition: ratngs.h:241
BLOB_CHOICE::IsClassified
bool IsClassified() const
Definition: ratngs.h:133
tesseract::ScriptPosToString
const char * ScriptPosToString(enum ScriptPos script_pos)
Definition: ratngs.cpp:202
BCC_STATIC_CLASSIFIER
Definition: ratngs.h:42
TBOX
Definition: rect.h:33
WERD_CHOICE::max_x_height
float max_x_height() const
Definition: ratngs.h:327