tesseract  3.05.02
dict.h
Go to the documentation of this file.
1 // File: dict.h
3 // Description: dict class.
4 // Author: Samuel Charron
5 //
6 // (C) Copyright 2006, Google Inc.
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 //
18 
19 #ifndef TESSERACT_DICT_DICT_H_
20 #define TESSERACT_DICT_DICT_H_
21 
22 #include "ambigs.h"
23 #include "dawg.h"
24 #include "dawg_cache.h"
25 #include "host.h"
26 #include "ratngs.h"
27 #include "stopper.h"
28 #include "trie.h"
29 #include "unicharset.h"
31 
32 class MATRIX;
33 class WERD_RES;
34 
35 #define MAX_WERD_LENGTH (inT64) 128
36 #define NO_RATING -1
37 
43  float rating;
44  float certainty;
45 };
46 
47 namespace tesseract {
48 
50 
51 //
52 // Constants
53 //
54 static const int kRatingPad = 4;
55 static const char kDictWildcard[] = "\u2606"; // WHITE STAR
56 static const int kDictMaxWildcards = 2; // max wildcards for a word
57 // TODO(daria): If hyphens are different in different languages and can be
58 // inferred from training data we should load their values dynamically.
59 static const char kHyphenSymbol[] = "-";
60 static const char kSlashSymbol[] = "/";
61 static const char kQuestionSymbol[] = "?";
62 static const char kApostropheSymbol[] = "'";
63 static const float kSimCertaintyScale = -10.0; // similarity matcher scaling
64 static const float kSimCertaintyOffset = -10.0; // similarity matcher offset
65 static const float kSimilarityFloor = 100.0; // worst E*L product to stop on
66 static const int kDocDictMaxRepChars = 4;
67 
68 // Enum for describing whether the x-height for the word is consistent:
69 // 0 - everything is good.
70 // 1 - there are one or two secondary (but consistent) baselines
71 // [think subscript and superscript], or there is an oversized
72 // first character.
73 // 2 - the word is inconsistent.
75 
76 struct DawgArgs {
78  : active_dawgs(d), updated_dawgs(up), permuter(p), valid_end(false) {}
79 
83  // True if the current position is a valid word end.
84  bool valid_end;
85 };
86 
87 class Dict {
88  public:
89  Dict(CCUtil* image_ptr);
90  ~Dict();
91  const CCUtil* getCCUtil() const {
92  return ccutil_;
93  }
95  return ccutil_;
96  }
97  const UNICHARSET& getUnicharset() const {
98  return getCCUtil()->unicharset;
99  }
101  return getCCUtil()->unicharset;
102  }
104  return getCCUtil()->unichar_ambigs;
105  }
106 
107  // Returns true if unichar_id is a word compounding character like - or /.
108  inline bool compound_marker(UNICHAR_ID unichar_id) {
109  const GenericVector<UNICHAR_ID>& normed_ids =
110  getUnicharset().normed_ids(unichar_id);
111  return normed_ids.size() == 1 &&
112  (normed_ids[0] == hyphen_unichar_id_ ||
113  normed_ids[0] == slash_unichar_id_);
114  }
115  // Returns true if unichar_id is an apostrophe-like character that may
116  // separate prefix/suffix words from a main body word.
117  inline bool is_apostrophe(UNICHAR_ID unichar_id) {
118  const GenericVector<UNICHAR_ID>& normed_ids =
119  getUnicharset().normed_ids(unichar_id);
120  return normed_ids.size() == 1 && normed_ids[0] == apostrophe_unichar_id_;
121  }
122 
123  /* hyphen.cpp ************************************************************/
124 
126  inline bool hyphenated() const { return
127  !last_word_on_line_ && hyphen_word_;
128  }
130  inline int hyphen_base_size() const {
131  return this->hyphenated() ? hyphen_word_->length() : 0;
132  }
136  inline void copy_hyphen_info(WERD_CHOICE *word) const {
137  if (this->hyphenated()) {
138  *word = *hyphen_word_;
139  if (hyphen_debug_level) word->print("copy_hyphen_info: ");
140  }
141  }
143  inline bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const {
144  if (!last_word_on_line_ || first_pos)
145  return false;
146  const GenericVector<UNICHAR_ID>& normed_ids =
147  getUnicharset().normed_ids(unichar_id);
148  return normed_ids.size() == 1 && normed_ids[0] == hyphen_unichar_id_;
149  }
151  inline bool has_hyphen_end(const WERD_CHOICE &word) const {
152  int word_index = word.length() - 1;
153  return has_hyphen_end(word.unichar_id(word_index), word_index == 0);
154  }
158  void reset_hyphen_vars(bool last_word_on_line);
161  void set_hyphen_word(const WERD_CHOICE &word,
162  const DawgPositionVector &active_dawgs);
163 
164  /* permdawg.cpp ************************************************************/
165  // Note: Functions in permdawg.cpp are only used by NoDangerousAmbig().
166  // When this function is refactored, permdawg.cpp can be removed.
167 
170  inline void update_best_choice(const WERD_CHOICE &word,
171  WERD_CHOICE *best_choice) {
172  if (word.rating() < best_choice->rating()) {
173  *best_choice = word;
174  }
175  }
179  void init_active_dawgs(DawgPositionVector *active_dawgs,
180  bool ambigs_mode) const;
181  // Fill the given vector with the default collection of any-length dawgs
182  void default_dawgs(DawgPositionVector *anylength_dawgs,
183  bool suppress_patterns) const;
184 
185 
192  const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit);
196  void go_deeper_dawg_fxn(
197  const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices,
198  int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info,
199  bool word_ending, WERD_CHOICE *word, float certainties[],
200  float *limit, WERD_CHOICE *best_choice, int *attempts_left,
201  void *void_more_args);
202 
204  void (Dict::*go_deeper_fxn_)(const char *debug,
205  const BLOB_CHOICE_LIST_VECTOR &char_choices,
206  int char_choice_index,
207  const CHAR_FRAGMENT_INFO *prev_char_frag_info,
208  bool word_ending, WERD_CHOICE *word,
209  float certainties[], float *limit,
210  WERD_CHOICE *best_choice, int *attempts_left,
211  void *void_more_args);
212  //
213  // Helper functions for dawg_permute_and_select().
214  //
215  void permute_choices(
216  const char *debug,
217  const BLOB_CHOICE_LIST_VECTOR &char_choices,
218  int char_choice_index,
219  const CHAR_FRAGMENT_INFO *prev_char_frag_info,
220  WERD_CHOICE *word,
221  float certainties[],
222  float *limit,
223  WERD_CHOICE *best_choice,
224  int *attempts_left,
225  void *more_args);
226 
227  void append_choices(
228  const char *debug,
229  const BLOB_CHOICE_LIST_VECTOR &char_choices,
230  const BLOB_CHOICE &blob_choice,
231  int char_choice_index,
232  const CHAR_FRAGMENT_INFO *prev_char_frag_info,
233  WERD_CHOICE *word,
234  float certainties[],
235  float *limit,
236  WERD_CHOICE *best_choice,
237  int *attempts_left,
238  void *more_args);
239 
240  bool fragment_state_okay(UNICHAR_ID curr_unichar_id,
241  float curr_rating, float curr_certainty,
242  const CHAR_FRAGMENT_INFO *prev_char_frag_info,
243  const char *debug, int word_ending,
244  CHAR_FRAGMENT_INFO *char_frag_info);
245 
246  /* stopper.cpp *************************************************************/
247  bool TESS_API NoDangerousAmbig(WERD_CHOICE *BestChoice,
248  DANGERR *fixpt,
249  bool fix_replaceable,
250  MATRIX* ratings);
251  // Replaces the corresponding wrong ngram in werd_choice with the correct
252  // one. The whole correct n-gram is inserted into the ratings matrix and
253  // the werd_choice: no more fragments!. Rating and certainty of new entries
254  // in matrix and werd_choice are the sum and mean of the wrong ngram
255  // respectively.
256  // E.g. for werd_choice mystring'' and ambiguity ''->": werd_choice becomes
257  // mystring", with a new entry in the ratings matrix for ".
258  void ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size,
259  UNICHAR_ID correct_ngram_id, WERD_CHOICE *werd_choice,
260  MATRIX *ratings);
261 
263  int LengthOfShortestAlphaRun(const WERD_CHOICE &WordChoice);
271  int UniformCertainties(const WERD_CHOICE& word);
273  bool AcceptableChoice(const WERD_CHOICE& best_choice,
274  XHeightConsistencyEnum xheight_consistency);
278  bool AcceptableResult(WERD_RES* word);
279  void EndDangerousAmbigs();
281  void DebugWordChoices();
283  void SettupStopperPass1();
285  void SettupStopperPass2();
286  /* context.cpp *************************************************************/
288  int case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset);
291  bool absolute_garbage(const WERD_CHOICE &word, const UNICHARSET &unicharset);
292 
293  /* dict.cpp ****************************************************************/
294 
297  static DawgCache *GlobalDawgCache();
298  // Sets up ready for a Load.
299  void SetupForLoad(DawgCache *dawg_cache);
300  // Loads the dawgs needed by Tesseract. Call FinishLoad() after.
301  void Load(const char *data_file_name, const STRING &lang);
302  // Completes the loading process after Load().
303  // Returns false if no dictionaries were loaded.
304  bool FinishLoad();
305  void End();
306 
307  // Resets the document dictionary analogous to ResetAdaptiveClassifier.
309  if (pending_words_ != NULL)
310  pending_words_->clear();
311  if (document_words_ != NULL)
312  document_words_->clear();
313  }
314 
350  //
351  int def_letter_is_okay(void* void_dawg_args,
352  UNICHAR_ID unichar_id, bool word_end) const;
353 
354  int (Dict::*letter_is_okay_)(void* void_dawg_args,
355  UNICHAR_ID unichar_id, bool word_end) const;
357  int LetterIsOkay(void* void_dawg_args,
358  UNICHAR_ID unichar_id, bool word_end) const {
359  return (this->*letter_is_okay_)(void_dawg_args, unichar_id, word_end);
360  }
361 
362 
364  double (Dict::*probability_in_context_)(const char* lang,
365  const char* context,
366  int context_bytes,
367  const char* character,
368  int character_bytes);
370  double ProbabilityInContext(const char* context,
371  int context_bytes,
372  const char* character,
373  int character_bytes) {
374  return (this->*probability_in_context_)(
375  getCCUtil()->lang.string(),
376  context, context_bytes,
377  character, character_bytes);
378  }
379 
382  const char* lang, const char* context, int context_bytes,
383  const char* character, int character_bytes) {
384  (void)lang;
385  (void)context;
386  (void)context_bytes;
387  (void)character;
388  (void)character_bytes;
389  return 0.0;
390  }
391  double ngram_probability_in_context(const char* lang,
392  const char* context,
393  int context_bytes,
394  const char* character,
395  int character_bytes);
396 
397  // Interface with params model.
398  float (Dict::*params_model_classify_)(const char *lang, void *path);
399  float ParamsModelClassify(const char *lang, void *path);
400  // Call params_model_classify_ member function.
401  float CallParamsModelClassify(void *path) {
402  ASSERT_HOST(params_model_classify_ != NULL); // ASSERT_HOST -> assert
403  return (this->*params_model_classify_)(
404  getCCUtil()->lang.string(), path);
405  }
406 
407  inline void SetWildcardID(UNICHAR_ID id) { wildcard_unichar_id_ = id; }
408  inline UNICHAR_ID WildcardID() const { return wildcard_unichar_id_; }
410  inline int NumDawgs() const { return dawgs_.size(); }
412  inline const Dawg *GetDawg(int index) const { return dawgs_[index]; }
414  inline const Dawg *GetPuncDawg() const { return punc_dawg_; }
416  inline const Dawg *GetUnambigDawg() const { return unambig_dawg_; }
418  static inline NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref) {
419  if (edge_ref == NO_EDGE) return 0; // beginning to explore the dawg
420  NODE_REF node = dawg->next_node(edge_ref);
421  if (node == 0) node = NO_EDGE; // end of word
422  return node;
423  }
424 
425  // Given a unichar from a string and a given dawg, return the unichar
426  // we should use to match in that dawg type. (for example, in the number
427  // dawg, all numbers are transformed to kPatternUnicharId).
428  inline UNICHAR_ID char_for_dawg(UNICHAR_ID ch, const Dawg *dawg) const {
429  if (!dawg) return ch;
430  switch (dawg->type()) {
431  case DAWG_TYPE_NUMBER:
433  default:
434  return ch;
435  }
436  }
437 
443  void ProcessPatternEdges(const Dawg *dawg, const DawgPosition &info,
444  UNICHAR_ID unichar_id, bool word_end,
445  DawgArgs *dawg_args,
446  PermuterType *current_permuter) const;
447 
451 
453  inline static bool valid_word_permuter(uinT8 perm, bool numbers_ok) {
454  return (perm == SYSTEM_DAWG_PERM || perm == FREQ_DAWG_PERM ||
455  perm == DOC_DAWG_PERM || perm == USER_DAWG_PERM ||
456  perm == USER_PATTERN_PERM || perm == COMPOUND_PERM ||
457  (numbers_ok && perm == NUMBER_PERM));
458  }
459  int valid_word(const WERD_CHOICE &word, bool numbers_ok) const;
460  int valid_word(const WERD_CHOICE &word) const {
461  return valid_word(word, false); // return NO_PERM for words with digits
462  }
463  int valid_word_or_number(const WERD_CHOICE &word) const {
464  return valid_word(word, true); // return NUMBER_PERM for valid numbers
465  }
467  int valid_word(const char *string) const {
468  WERD_CHOICE word(string, getUnicharset());
469  return valid_word(word);
470  }
471  // Do the two WERD_CHOICEs form a meaningful bigram?
472  bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const;
477  bool valid_punctuation(const WERD_CHOICE &word);
479  int good_choice(const WERD_CHOICE &choice);
481  void add_document_word(const WERD_CHOICE &best_choice);
483  void adjust_word(WERD_CHOICE *word,
484  bool nonword, XHeightConsistencyEnum xheight_consistency,
485  float additional_adjust,
486  bool modify_rating,
487  bool debug);
489  inline void SetWordsegRatingAdjustFactor(float f) {
490  wordseg_rating_adjust_factor_ = f;
491  }
493  bool IsSpaceDelimitedLang() const;
494 
495  private:
497  CCUtil* ccutil_;
504  UnicharAmbigs *dang_ambigs_table_;
506  UnicharAmbigs *replace_ambigs_table_;
508  FLOAT32 reject_offset_;
509  // Cached UNICHAR_IDs:
510  UNICHAR_ID wildcard_unichar_id_; // kDictWildcard.
511  UNICHAR_ID apostrophe_unichar_id_; // kApostropheSymbol.
512  UNICHAR_ID question_unichar_id_; // kQuestionSymbol.
513  UNICHAR_ID slash_unichar_id_; // kSlashSymbol.
514  UNICHAR_ID hyphen_unichar_id_; // kHyphenSymbol.
515  // Hyphen-related variables.
516  WERD_CHOICE *hyphen_word_;
517  DawgPositionVector hyphen_active_dawgs_;
518  bool last_word_on_line_;
519  // List of lists of "equivalent" UNICHAR_IDs for the purposes of dictionary
520  // matching. The first member of each list is taken as canonical. For
521  // example, the first list contains hyphens and dashes with the first symbol
522  // being the ASCII hyphen minus.
523  GenericVector<GenericVectorEqEq<UNICHAR_ID> > equivalent_symbols_;
524  // Dawg Cache reference - this is who we ask to allocate/deallocate dawgs.
525  DawgCache *dawg_cache_;
526  bool dawg_cache_is_ours_; // we should delete our own dawg_cache_
527  // Dawgs.
528  DawgVector dawgs_;
529  SuccessorListsVector successors_;
530  Trie *pending_words_;
531  // bigram_dawg_ points to a dawg of two-word bigrams which always supercede if
532  // any of them are present on the best choices list for a word pair.
533  // the bigrams are stored as space-separated words where:
534  // (1) leading and trailing punctuation has been removed from each word and
535  // (2) any digits have been replaced with '?' marks.
536  Dawg *bigram_dawg_;
539  // TODO(daria): need to support multiple languages in the future,
540  // so maybe will need to maintain a list of dawgs of each kind.
541  Dawg *freq_dawg_;
542  Dawg *unambig_dawg_;
543  Dawg *punc_dawg_;
544  Trie *document_words_;
547  float wordseg_rating_adjust_factor_;
548  // File for recording ambiguities discovered during dictionary search.
549  FILE *output_ambig_words_file_;
550 
551  public:
555  STRING_VAR_H(user_words_file, "", "A filename of user-provided words.");
557  "A suffix of user-provided words located in tessdata.");
559  "A filename of user-provided patterns.");
561  "A suffix of user-provided patterns located in tessdata.");
562  BOOL_VAR_H(load_system_dawg, true, "Load system word dawg.");
563  BOOL_VAR_H(load_freq_dawg, true, "Load frequent word dawg.");
564  BOOL_VAR_H(load_unambig_dawg, true, "Load unambiguous word dawg.");
566  "Load dawg with punctuation patterns.");
567  BOOL_VAR_H(load_number_dawg, true, "Load dawg with number patterns.");
569  "Load dawg with special word bigrams.");
571  "Score penalty (0.1 = 10%) added if there are subscripts "
572  "or superscripts in a word, but it is otherwise OK.");
574  "Score penalty (0.1 = 10%) added if an xheight is "
575  "inconsistent.");
577  "Score multiplier for word matches which have good case and"
578  "are frequent in the given language (lower is better).");
579 
581  "Score multiplier for word matches that have good case "
582  "(lower is better).");
583 
585  "Default score multiplier for word matches, which may have "
586  "case issues (lower is better).");
587 
588  // TODO(daria): remove this param when ngram permuter is deprecated.
590  "Multipler to for the best choice from the ngram model.");
591 
593  "Score multiplier for glyph fragment segmentations which "
594  "do not match a dictionary word (lower is better).");
595 
597  "Score multiplier for poorly cased strings that are not in"
598  " the dictionary and generally look like garbage (lower is"
599  " better).");
601  "Output file for ambiguities found in the dictionary");
602  INT_VAR_H(dawg_debug_level, 0, "Set to 1 for general debug info"
603  ", to 2 for more details, to 3 to see all the debug messages");
604  INT_VAR_H(hyphen_debug_level, 0, "Debug level for hyphenated words.");
605  INT_VAR_H(max_viterbi_list_size, 10, "Maximum size of viterbi list.");
607  "Use only the first UTF8 step of the given string"
608  " when computing log probabilities.");
609  double_VAR_H(certainty_scale, 20.0, "Certainty scaling factor");
611  "Certainty threshold for non-dict words");
613  "Reject certainty offset");
615  "Size of dict word to be treated as non-dict word");
617  "Certainty to add for each dict char above small word size.");
619  "Max certaintly variation allowed in a word (in sigma)");
620  INT_VAR_H(stopper_debug_level, 0, "Stopper debug level");
622  "Make AcceptableChoice() always return false. Useful"
623  " when there is a need to explore all segmentations");
625  "Deprecated- backward compatibility only");
626  INT_VAR_H(tessedit_truncate_wordchoice_log, 10, "Max words to keep in list");
627  STRING_VAR_H(word_to_debug, "", "Word for which stopper debug information"
628  " should be printed to stdout");
630  "Lengths of unichars in word_to_debug");
631  INT_VAR_H(fragments_debug, 0, "Debug character fragments");
633  "Don't use any alphabetic-specific tricks."
634  "Set to true in the traineddata config file for"
635  " scripts that are cursive or inherently fixed-pitch");
636  BOOL_VAR_H(save_doc_words, 0, "Save Document Words");
638  "Worst certainty for using pending dictionary");
639  double_VAR_H(doc_dict_certainty_threshold, -2.25, "Worst certainty"
640  " for words that can be inserted into the document dictionary");
641  INT_VAR_H(max_permuter_attempts, 10000, "Maximum number of different"
642  " character choices to consider during permutation."
643  " This limit is especially useful when user patterns"
644  " are specified, since overly generic patterns can result in"
645  " dawg search exploring an overly large number of options.");
646 };
647 } // namespace tesseract
648 
649 #endif // THIRD_PARTY_TESSERACT_DICT_DICT_H_
void ProcessPatternEdges(const Dawg *dawg, const DawgPosition &info, UNICHAR_ID unichar_id, bool word_end, DawgArgs *dawg_args, PermuterType *current_permuter) const
Definition: dict.cpp:510
void go_deeper_dawg_fxn(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, bool word_ending, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *void_more_args)
Definition: permdawg.cpp:51
int fragments_debug
Definition: dict.h:631
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.h:354
UNICHAR_ID unichar_id
Definition: dict.h:40
bool absolute_garbage(const WERD_CHOICE &word, const UNICHARSET &unicharset)
Definition: context.cpp:70
static const UNICHAR_ID kPatternUnicharID
Definition: dawg.h:125
char * output_ambig_words_file
Definition: dict.h:601
DawgArgs(DawgPositionVector *d, DawgPositionVector *up, PermuterType p)
Definition: dict.h:77
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
Definition: dict.cpp:565
void ResetDocumentDictionary()
Definition: dict.h:308
inT64 EDGE_REF
Definition: dawg.h:54
int valid_word_or_number(const WERD_CHOICE &word) const
Definition: dict.h:463
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
Definition: stopper.cpp:369
#define STRING_VAR_H(name, val, comment)
Definition: params.h:271
bool valid_punctuation(const WERD_CHOICE &word)
Definition: dict.cpp:806
DawgPositionVector * updated_dawgs
Definition: dict.h:81
double certainty_scale
Definition: dict.h:609
bool is_apostrophe(UNICHAR_ID unichar_id)
Definition: dict.h:117
double stopper_allowable_character_badness
Definition: dict.h:619
bool has_hyphen_end(const WERD_CHOICE &word) const
Same as above, but check the unichar at the end of the word.
Definition: dict.h:151
void SetWildcardID(UNICHAR_ID id)
Definition: dict.h:407
inT64 NODE_REF
Definition: dawg.h:55
STRING lang
Definition: ccutil.h:67
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:313
void End()
Definition: dict.cpp:327
WERD_CHOICE * dawg_permute_and_select(const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
Definition: permdawg.cpp:174
void print() const
Definition: ratngs.h:564
bool fragment_state_okay(UNICHAR_ID curr_unichar_id, float curr_rating, float curr_certainty, const CHAR_FRAGMENT_INFO *prev_char_frag_info, const char *debug, int word_ending, CHAR_FRAGMENT_INFO *char_frag_info)
Definition: permdawg.cpp:321
int def_letter_is_okay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.cpp:350
bool load_punc_dawg
Definition: dict.h:566
PermuterType
Definition: ratngs.h:240
float(Dict::* params_model_classify_)(const char *lang, void *path)
Definition: dict.h:398
#define TESS_API
Definition: platform.h:81
XHeightConsistencyEnum
Definition: dict.h:74
int stopper_debug_level
Definition: dict.h:620
#define INT_VAR_H(name, val, comment)
Definition: params.h:265
bool FinishLoad()
Definition: dict.cpp:307
double segment_penalty_dict_frequent_word
Definition: dict.h:578
void SetWordsegRatingAdjustFactor(float f)
Set wordseg_rating_adjust_factor_ to the given value.
Definition: dict.h:489
void append_choices(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, const BLOB_CHOICE &blob_choice, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *more_args)
Definition: permdawg.cpp:245
void Load(const char *data_file_name, const STRING &lang)
Definition: dict.cpp:224
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
Definition: stopper.cpp:373
double segment_penalty_ngram_best_choice
Definition: dict.h:590
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
Definition: dict.h:412
const UNICHARSET & getUnicharset() const
Definition: dict.h:97
int hyphen_debug_level
Definition: dict.h:604
Definition: matrix.h:572
unsigned char uinT8
Definition: host.h:32
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:206
void update_best_choice(const WERD_CHOICE &word, WERD_CHOICE *best_choice)
Definition: dict.h:170
double segment_penalty_dict_nonword
Definition: dict.h:594
UNICHARSET & getUnicharset()
Definition: dict.h:100
UnicharAmbigs unichar_ambigs
Definition: ccutil.h:71
int max_permuter_attempts
Definition: dict.h:645
void EndDangerousAmbigs()
Definition: stopper.cpp:367
double stopper_phase2_certainty_rejection_offset
Definition: dict.h:613
bool load_unambig_dawg
Definition: dict.h:564
double ngram_probability_in_context(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
static NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref)
Returns the appropriate next node given the EDGE_REF.
Definition: dict.h:418
int valid_word(const char *string) const
This function is used by api/tesseract_cube_combiner.cpp.
Definition: dict.h:467
DawgType type() const
Definition: dawg.h:127
int good_choice(const WERD_CHOICE &choice)
Returns true if a good answer is found for the unknown blob rating.
bool IsSpaceDelimitedLang() const
Returns true if the language is space-delimited (not CJ, or T).
Definition: dict.cpp:833
bool load_number_dawg
Definition: dict.h:567
bool save_doc_words
Definition: dict.h:636
void reset_hyphen_vars(bool last_word_on_line)
Definition: hyphen.cpp:32
const CHAR_FRAGMENT * fragment
Definition: dict.h:41
char * user_words_suffix
Definition: dict.h:557
bool AcceptableResult(WERD_RES *word)
Definition: stopper.cpp:110
int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
Definition: dict.h:410
double doc_dict_certainty_threshold
Definition: dict.h:640
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:268
const char * string() const
Definition: strngs.cpp:201
int valid_word(const WERD_CHOICE &word) const
Definition: dict.h:460
int max_viterbi_list_size
Definition: dict.h:605
void clear()
Definition: trie.cpp:65
double ProbabilityInContext(const char *context, int context_bytes, const char *character, int character_bytes)
Calls probability_in_context_ member function.
Definition: dict.h:370
double xheight_penalty_inconsistent
Definition: dict.h:575
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
Definition: dict.cpp:548
double stopper_certainty_per_char
Definition: dict.h:617
bool save_raw_choices
Definition: dict.h:625
void copy_hyphen_info(WERD_CHOICE *word) const
Definition: dict.h:136
double(Dict::* probability_in_context_)(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
Probability in context function used by the ngram permuter.
Definition: dict.h:364
CCUtil * getCCUtil()
Definition: dict.h:94
float CallParamsModelClassify(void *path)
Definition: dict.h:401
void add_document_word(const WERD_CHOICE &best_choice)
Adds a word found on this document to the document specific dictionary.
Definition: dict.cpp:592
int dawg_debug_level
Definition: dict.h:603
float FLOAT32
Definition: host.h:44
const UnicharAmbigs & getUnicharAmbigs() const
Definition: dict.h:103
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
Definition: hyphen.cpp:49
int tessedit_truncate_wordchoice_log
Definition: dict.h:626
bool AcceptableChoice(const WERD_CHOICE &best_choice, XHeightConsistencyEnum xheight_consistency)
Returns true if the given best_choice is good enough to stop.
Definition: stopper.cpp:50
UNICHAR_ID WildcardID() const
Definition: dict.h:408
int LetterIsOkay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Calls letter_is_okay_ member function.
Definition: dict.h:357
void adjust_word(WERD_CHOICE *word, bool nonword, XHeightConsistencyEnum xheight_consistency, float additional_adjust, bool modify_rating, bool debug)
Adjusts the rating of the given word.
Definition: dict.cpp:650
int length() const
Definition: ratngs.h:301
char * user_patterns_suffix
Definition: dict.h:561
float rating() const
Definition: ratngs.h:325
bool stopper_no_acceptable_choices
Definition: dict.h:623
virtual NODE_REF next_node(EDGE_REF edge_ref) const =0
static bool valid_word_permuter(uinT8 perm, bool numbers_ok)
Check all the DAWGs to see if this word is in any of them.
Definition: dict.h:453
bool segment_nonalphabetic_script
Definition: dict.h:635
double segment_penalty_dict_case_bad
Definition: dict.h:586
int UniformCertainties(const WERD_CHOICE &word)
Definition: stopper.cpp:470
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
Definition: unicharset.h:783
int case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset)
Check a string to see if it matches a set of lexical rules.
Definition: context.cpp:52
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:730
double segment_penalty_dict_case_ok
Definition: dict.h:582
Definition: strngs.h:44
int size() const
Definition: genericvector.h:72
GenericVector< Dawg * > DawgVector
Definition: dict.h:49
float certainty
Definition: dict.h:44
bool load_freq_dawg
Definition: dict.h:563
const CCUtil * getCCUtil() const
Definition: dict.h:91
void DebugWordChoices()
Prints the current choices for this word to stdout.
DawgPositionVector * active_dawgs
Definition: dict.h:80
int num_fragments
Definition: dict.h:42
void(Dict::* go_deeper_fxn_)(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, bool word_ending, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *void_more_args)
Pointer to go_deeper function.
Definition: dict.h:204
Dict(CCUtil *image_ptr)
Definition: dict.cpp:33
bool load_system_dawg
Definition: dict.h:562
double stopper_nondict_certainty_base
Definition: dict.h:611
bool TESS_API NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
Definition: stopper.cpp:151
void permute_choices(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *more_args)
Definition: permdawg.cpp:203
static DawgCache * GlobalDawgCache()
Definition: dict.cpp:198
float ParamsModelClassify(const char *lang, void *path)
PermuterType permuter
Definition: dict.h:82
char * word_to_debug_lengths
Definition: dict.h:630
char * user_patterns_file
Definition: dict.h:559
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
int LengthOfShortestAlphaRun(const WERD_CHOICE &WordChoice)
Returns the length of the shortest alpha run in WordChoice.
Definition: stopper.cpp:451
double xheight_penalty_subscripts
Definition: dict.h:572
const Dawg * GetUnambigDawg() const
Return the points to the unambiguous words dawg.
Definition: dict.h:416
UNICHARSET unicharset
Definition: ccutil.h:70
bool hyphenated() const
Returns true if we&#39;ve recorded the beginning of a hyphenated word.
Definition: dict.h:126
double def_probability_in_context(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
Default (no-op) implementation of probability in context function.
Definition: dict.h:381
char * word_to_debug
Definition: dict.h:628
char * user_words_file
Definition: dict.h:555
void ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size, UNICHAR_ID correct_ngram_id, WERD_CHOICE *werd_choice, MATRIX *ratings)
Definition: stopper.cpp:377
bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const
Check whether the word has a hyphen at the end.
Definition: dict.h:143
int stopper_smallword_size
Definition: dict.h:615
bool valid_end
Definition: dict.h:84
#define double_VAR_H(name, val, comment)
Definition: params.h:274
#define ASSERT_HOST(x)
Definition: errcode.h:84
double segment_penalty_garbage
Definition: dict.h:599
int hyphen_base_size() const
Size of the base word (the part on the line before) of a hyphenated word.
Definition: dict.h:130
bool load_bigram_dawg
Definition: dict.h:569
double doc_dict_pending_threshold
Definition: dict.h:638
bool use_only_first_uft8_step
Definition: dict.h:608
const Dawg * GetPuncDawg() const
Return the points to the punctuation dawg.
Definition: dict.h:414
float rating
Definition: dict.h:43
int UNICHAR_ID
Definition: unichar.h:33
bool compound_marker(UNICHAR_ID unichar_id)
Definition: dict.h:108
UNICHAR_ID char_for_dawg(UNICHAR_ID ch, const Dawg *dawg) const
Definition: dict.h:428
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const
Definition: dict.cpp:763