tesseract  4.1.0
dict.cpp
Go to the documentation of this file.
1 // File: dict.cpp
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 #include <cstdio>
20 
21 #include "dict.h"
22 #include "unicodes.h"
23 
24 #include "tprintf.h"
25 
26 namespace tesseract {
27 
28 class Image;
29 
31  : letter_is_okay_(&tesseract::Dict::def_letter_is_okay),
32  probability_in_context_(&tesseract::Dict::def_probability_in_context),
33  params_model_classify_(nullptr),
34  ccutil_(ccutil),
35  wildcard_unichar_id_(INVALID_UNICHAR_ID),
36  apostrophe_unichar_id_(INVALID_UNICHAR_ID),
37  question_unichar_id_(INVALID_UNICHAR_ID),
38  slash_unichar_id_(INVALID_UNICHAR_ID),
39  hyphen_unichar_id_(INVALID_UNICHAR_ID),
40  STRING_MEMBER(user_words_file, "", "A filename of user-provided words.",
41  getCCUtil()->params()),
42  STRING_INIT_MEMBER(user_words_suffix, "",
43  "A suffix of user-provided words located in tessdata.",
44  getCCUtil()->params()),
45  STRING_MEMBER(user_patterns_file, "",
46  "A filename of user-provided patterns.",
47  getCCUtil()->params()),
48  STRING_INIT_MEMBER(user_patterns_suffix, "",
49  "A suffix of user-provided patterns located in "
50  "tessdata.",
51  getCCUtil()->params()),
52  BOOL_INIT_MEMBER(load_system_dawg, true, "Load system word dawg.",
53  getCCUtil()->params()),
54  BOOL_INIT_MEMBER(load_freq_dawg, true, "Load frequent word dawg.",
55  getCCUtil()->params()),
56  BOOL_INIT_MEMBER(load_unambig_dawg, true, "Load unambiguous word dawg.",
57  getCCUtil()->params()),
58  BOOL_INIT_MEMBER(load_punc_dawg, true,
59  "Load dawg with punctuation"
60  " patterns.",
61  getCCUtil()->params()),
62  BOOL_INIT_MEMBER(load_number_dawg, true,
63  "Load dawg with number"
64  " patterns.",
65  getCCUtil()->params()),
66  BOOL_INIT_MEMBER(load_bigram_dawg, true,
67  "Load dawg with special word "
68  "bigrams.",
69  getCCUtil()->params()),
70  double_MEMBER(xheight_penalty_subscripts, 0.125,
71  "Score penalty (0.1 = 10%) added if there are subscripts "
72  "or superscripts in a word, but it is otherwise OK.",
73  getCCUtil()->params()),
74  double_MEMBER(xheight_penalty_inconsistent, 0.25,
75  "Score penalty (0.1 = 10%) added if an xheight is "
76  "inconsistent.",
77  getCCUtil()->params()),
78  double_MEMBER(segment_penalty_dict_frequent_word, 1.0,
79  "Score multiplier for word matches which have good case and"
80  " are frequent in the given language (lower is better).",
81  getCCUtil()->params()),
82  double_MEMBER(segment_penalty_dict_case_ok, 1.1,
83  "Score multiplier for word matches that have good case "
84  "(lower is better).",
85  getCCUtil()->params()),
86  double_MEMBER(segment_penalty_dict_case_bad, 1.3125,
87  "Default score multiplier for word matches, which may have "
88  "case issues (lower is better).",
89  getCCUtil()->params()),
90  double_MEMBER(segment_penalty_dict_nonword, 1.25,
91  "Score multiplier for glyph fragment segmentations which "
92  "do not match a dictionary word (lower is better).",
93  getCCUtil()->params()),
94  double_MEMBER(segment_penalty_garbage, 1.50,
95  "Score multiplier for poorly cased strings that are not in"
96  " the dictionary and generally look like garbage (lower is"
97  " better).",
98  getCCUtil()->params()),
99  STRING_MEMBER(output_ambig_words_file, "",
100  "Output file for ambiguities found in the dictionary",
101  getCCUtil()->params()),
102  INT_MEMBER(dawg_debug_level, 0,
103  "Set to 1 for general debug info"
104  ", to 2 for more details, to 3 to see all the debug messages",
105  getCCUtil()->params()),
106  INT_MEMBER(hyphen_debug_level, 0, "Debug level for hyphenated words.",
107  getCCUtil()->params()),
108  INT_MEMBER(max_viterbi_list_size, 10, "Maximum size of viterbi list.",
109  getCCUtil()->params()),
110  BOOL_MEMBER(use_only_first_uft8_step, false,
111  "Use only the first UTF8 step of the given string"
112  " when computing log probabilities.",
113  getCCUtil()->params()),
114  double_MEMBER(certainty_scale, 20.0, "Certainty scaling factor",
115  getCCUtil()->params()),
116  double_MEMBER(stopper_nondict_certainty_base, -2.50,
117  "Certainty threshold for non-dict words",
118  getCCUtil()->params()),
119  double_MEMBER(stopper_phase2_certainty_rejection_offset, 1.0,
120  "Reject certainty offset", getCCUtil()->params()),
121  INT_MEMBER(stopper_smallword_size, 2,
122  "Size of dict word to be treated as non-dict word",
123  getCCUtil()->params()),
124  double_MEMBER(stopper_certainty_per_char, -0.50,
125  "Certainty to add"
126  " for each dict char above small word size.",
127  getCCUtil()->params()),
128  double_MEMBER(stopper_allowable_character_badness, 3.0,
129  "Max certaintly variation allowed in a word (in sigma)",
130  getCCUtil()->params()),
131  INT_MEMBER(stopper_debug_level, 0, "Stopper debug level",
132  getCCUtil()->params()),
133  BOOL_MEMBER(stopper_no_acceptable_choices, false,
134  "Make AcceptableChoice() always return false. Useful"
135  " when there is a need to explore all segmentations",
136  getCCUtil()->params()),
137  INT_MEMBER(tessedit_truncate_wordchoice_log, 10,
138  "Max words to keep in list", getCCUtil()->params()),
139  STRING_MEMBER(word_to_debug, "",
140  "Word for which stopper debug"
141  " information should be printed to stdout",
142  getCCUtil()->params()),
143  STRING_MEMBER(word_to_debug_lengths, "",
144  "Lengths of unichars in word_to_debug",
145  getCCUtil()->params()),
146  INT_MEMBER(fragments_debug, 0, "Debug character fragments",
147  getCCUtil()->params()),
148  BOOL_MEMBER(segment_nonalphabetic_script, false,
149  "Don't use any alphabetic-specific tricks."
150  " Set to true in the traineddata config file for"
151  " scripts that are cursive or inherently fixed-pitch",
152  getCCUtil()->params()),
153  BOOL_MEMBER(save_doc_words, 0, "Save Document Words",
154  getCCUtil()->params()),
155  double_MEMBER(doc_dict_pending_threshold, 0.0,
156  "Worst certainty for using pending dictionary",
157  getCCUtil()->params()),
158  double_MEMBER(doc_dict_certainty_threshold, -2.25,
159  "Worst certainty for words that can be inserted into the"
160  " document dictionary",
161  getCCUtil()->params()),
162  INT_MEMBER(max_permuter_attempts, 10000,
163  "Maximum number of different"
164  " character choices to consider during permutation."
165  " This limit is especially useful when user patterns"
166  " are specified, since overly generic patterns can result in"
167  " dawg search exploring an overly large number of options.",
168  getCCUtil()->params()) {
169  dang_ambigs_table_ = nullptr;
170  replace_ambigs_table_ = nullptr;
171  reject_offset_ = 0.0;
172  go_deeper_fxn_ = nullptr;
173  hyphen_word_ = nullptr;
174  last_word_on_line_ = false;
175  document_words_ = nullptr;
176  dawg_cache_ = nullptr;
177  dawg_cache_is_ours_ = false;
178  pending_words_ = nullptr;
179  bigram_dawg_ = nullptr;
180  freq_dawg_ = nullptr;
181  punc_dawg_ = nullptr;
182  unambig_dawg_ = nullptr;
183  wordseg_rating_adjust_factor_ = -1.0f;
184  output_ambig_words_file_ = nullptr;
185 }
186 
188  End();
189  delete hyphen_word_;
190  if (output_ambig_words_file_ != nullptr) fclose(output_ambig_words_file_);
191 }
192 
194  // This global cache (a singleton) will outlive every Tesseract instance
195  // (even those that someone else might declare as global statics).
196  static DawgCache cache;
197  return &cache;
198 }
199 
200 // Sets up ready for a Load or LoadLSTM.
201 void Dict::SetupForLoad(DawgCache* dawg_cache) {
202  if (dawgs_.length() != 0) this->End();
203 
204  apostrophe_unichar_id_ = getUnicharset().unichar_to_id(kApostropheSymbol);
205  question_unichar_id_ = getUnicharset().unichar_to_id(kQuestionSymbol);
206  slash_unichar_id_ = getUnicharset().unichar_to_id(kSlashSymbol);
207  hyphen_unichar_id_ = getUnicharset().unichar_to_id(kHyphenSymbol);
208 
209  if (dawg_cache != nullptr) {
210  dawg_cache_ = dawg_cache;
211  dawg_cache_is_ours_ = false;
212  } else {
213  dawg_cache_ = new DawgCache();
214  dawg_cache_is_ours_ = true;
215  }
216 }
217 
218 // Loads the dawgs needed by Tesseract. Call FinishLoad() after.
219 void Dict::Load(const STRING& lang, TessdataManager* data_file) {
220  // Load dawgs_.
221  if (load_punc_dawg) {
222  punc_dawg_ = dawg_cache_->GetSquishedDawg(lang, TESSDATA_PUNC_DAWG,
223  dawg_debug_level, data_file);
224  if (punc_dawg_) dawgs_ += punc_dawg_;
225  }
226  if (load_system_dawg) {
227  Dawg* system_dawg = dawg_cache_->GetSquishedDawg(
228  lang, TESSDATA_SYSTEM_DAWG, dawg_debug_level, data_file);
229  if (system_dawg) dawgs_ += system_dawg;
230  }
231  if (load_number_dawg) {
232  Dawg* number_dawg = dawg_cache_->GetSquishedDawg(
233  lang, TESSDATA_NUMBER_DAWG, dawg_debug_level, data_file);
234  if (number_dawg) dawgs_ += number_dawg;
235  }
236  if (load_bigram_dawg) {
237  bigram_dawg_ = dawg_cache_->GetSquishedDawg(lang, TESSDATA_BIGRAM_DAWG,
238  dawg_debug_level, data_file);
239  // The bigram_dawg_ is NOT used like the other dawgs! DO NOT add to the
240  // dawgs_!!
241  }
242  if (load_freq_dawg) {
243  freq_dawg_ = dawg_cache_->GetSquishedDawg(lang, TESSDATA_FREQ_DAWG,
244  dawg_debug_level, data_file);
245  if (freq_dawg_) dawgs_ += freq_dawg_;
246  }
247  if (load_unambig_dawg) {
248  unambig_dawg_ = dawg_cache_->GetSquishedDawg(lang, TESSDATA_UNAMBIG_DAWG,
249  dawg_debug_level, data_file);
250  if (unambig_dawg_) dawgs_ += unambig_dawg_;
251  }
252 
253  STRING name;
254  if (!user_words_suffix.empty() || !user_words_file.empty()) {
255  Trie* trie_ptr = new Trie(DAWG_TYPE_WORD, lang, USER_DAWG_PERM,
256  getUnicharset().size(), dawg_debug_level);
257  if (!user_words_file.empty()) {
258  name = user_words_file;
259  } else {
261  name += user_words_suffix;
262  }
263  if (!trie_ptr->read_and_add_word_list(name.string(), getUnicharset(),
265  tprintf("Error: failed to load %s\n", name.string());
266  delete trie_ptr;
267  } else {
268  dawgs_ += trie_ptr;
269  }
270  }
271 
272  if (!user_patterns_suffix.empty() || !user_patterns_file.empty()) {
273  Trie* trie_ptr = new Trie(DAWG_TYPE_PATTERN, lang, USER_PATTERN_PERM,
274  getUnicharset().size(), dawg_debug_level);
275  trie_ptr->initialize_patterns(&(getUnicharset()));
276  if (!user_patterns_file.empty()) {
277  name = user_patterns_file;
278  } else {
280  name += user_patterns_suffix;
281  }
282  if (!trie_ptr->read_pattern_list(name.string(), getUnicharset())) {
283  tprintf("Error: failed to load %s\n", name.string());
284  delete trie_ptr;
285  } else {
286  dawgs_ += trie_ptr;
287  }
288  }
289 
290  document_words_ = new Trie(DAWG_TYPE_WORD, lang, DOC_DAWG_PERM,
291  getUnicharset().size(), dawg_debug_level);
292  dawgs_ += document_words_;
293 
294  // This dawg is temporary and should not be searched by letter_is_ok.
295  pending_words_ = new Trie(DAWG_TYPE_WORD, lang, NO_PERM,
296  getUnicharset().size(), dawg_debug_level);
297 }
298 
299 // Loads the dawgs needed by the LSTM model. Call FinishLoad() after.
300 void Dict::LoadLSTM(const STRING& lang, TessdataManager* data_file) {
301  // Load dawgs_.
302  if (load_punc_dawg) {
303  punc_dawg_ = dawg_cache_->GetSquishedDawg(lang, TESSDATA_LSTM_PUNC_DAWG,
304  dawg_debug_level, data_file);
305  if (punc_dawg_) dawgs_ += punc_dawg_;
306  }
307  if (load_system_dawg) {
308  Dawg* system_dawg = dawg_cache_->GetSquishedDawg(
309  lang, TESSDATA_LSTM_SYSTEM_DAWG, dawg_debug_level, data_file);
310  if (system_dawg) dawgs_ += system_dawg;
311  }
312  if (load_number_dawg) {
313  Dawg* number_dawg = dawg_cache_->GetSquishedDawg(
314  lang, TESSDATA_LSTM_NUMBER_DAWG, dawg_debug_level, data_file);
315  if (number_dawg) dawgs_ += number_dawg;
316  }
317 
318  // stolen from Dict::Load (but needs params_ from Tesseract
319  // langdata/config/api):
320  STRING name;
321  if (!user_words_suffix.empty() || !user_words_file.empty()) {
322  Trie* trie_ptr = new Trie(DAWG_TYPE_WORD, lang, USER_DAWG_PERM,
323  getUnicharset().size(), dawg_debug_level);
324  if (!user_words_file.empty()) {
325  name = user_words_file;
326  } else {
328  name += user_words_suffix;
329  }
330  if (!trie_ptr->read_and_add_word_list(name.string(), getUnicharset(),
332  tprintf("Error: failed to load %s\n", name.string());
333  delete trie_ptr;
334  } else {
335  dawgs_ += trie_ptr;
336  }
337  }
338 
339  if (!user_patterns_suffix.empty() || !user_patterns_file.empty()) {
340  Trie* trie_ptr = new Trie(DAWG_TYPE_PATTERN, lang, USER_PATTERN_PERM,
341  getUnicharset().size(), dawg_debug_level);
342  trie_ptr->initialize_patterns(&(getUnicharset()));
343  if (!user_patterns_file.empty()) {
344  name = user_patterns_file;
345  } else {
347  name += user_patterns_suffix;
348  }
349  if (!trie_ptr->read_pattern_list(name.string(), getUnicharset())) {
350  tprintf("Error: failed to load %s\n", name.string());
351  delete trie_ptr;
352  } else {
353  dawgs_ += trie_ptr;
354  }
355  }
356 }
357 
358 // Completes the loading process after Load() and/or LoadLSTM().
359 // Returns false if no dictionaries were loaded.
361  if (dawgs_.empty()) return false;
362  // Construct a list of corresponding successors for each dawg. Each entry, i,
363  // in the successors_ vector is a vector of integers that represent the
364  // indices into the dawgs_ vector of the successors for dawg i.
365  successors_.reserve(dawgs_.length());
366  for (int i = 0; i < dawgs_.length(); ++i) {
367  const Dawg* dawg = dawgs_[i];
368  auto* lst = new SuccessorList();
369  for (int j = 0; j < dawgs_.length(); ++j) {
370  const Dawg* other = dawgs_[j];
371  if (dawg != nullptr && other != nullptr &&
372  (dawg->lang() == other->lang()) &&
373  kDawgSuccessors[dawg->type()][other->type()])
374  *lst += j;
375  }
376  successors_ += lst;
377  }
378  return true;
379 }
380 
381 void Dict::End() {
382  if (dawgs_.length() == 0) return; // Not safe to call twice.
383  for (int i = 0; i < dawgs_.size(); i++) {
384  if (!dawg_cache_->FreeDawg(dawgs_[i])) {
385  delete dawgs_[i];
386  }
387  }
388  dawg_cache_->FreeDawg(bigram_dawg_);
389  if (dawg_cache_is_ours_) {
390  delete dawg_cache_;
391  dawg_cache_ = nullptr;
392  }
393  successors_.delete_data_pointers();
394  dawgs_.clear();
395  successors_.clear();
396  document_words_ = nullptr;
397  delete pending_words_;
398  pending_words_ = nullptr;
399 }
400 
401 // Returns true if in light of the current state unichar_id is allowed
402 // according to at least one of the dawgs in the dawgs_ vector.
403 // See more extensive comments in dict.h where this function is declared.
404 int Dict::def_letter_is_okay(void* void_dawg_args, const UNICHARSET& unicharset,
405  UNICHAR_ID unichar_id, bool word_end) const {
406  auto* dawg_args = static_cast<DawgArgs*>(void_dawg_args);
407 
408  ASSERT_HOST(unicharset.contains_unichar_id(unichar_id));
409 
410  if (dawg_debug_level >= 3) {
411  tprintf(
412  "def_letter_is_okay: current unichar=%s word_end=%d"
413  " num active dawgs=%d\n",
414  getUnicharset().debug_str(unichar_id).string(), word_end,
415  dawg_args->active_dawgs->length());
416  }
417 
418  // Do not accept words that contain kPatternUnicharID.
419  // (otherwise pattern dawgs would not function correctly).
420  // Do not accept words containing INVALID_UNICHAR_IDs.
421  if (unichar_id == Dawg::kPatternUnicharID ||
422  unichar_id == INVALID_UNICHAR_ID) {
423  dawg_args->permuter = NO_PERM;
424  return NO_PERM;
425  }
426 
427  // Initialization.
428  PermuterType curr_perm = NO_PERM;
429  dawg_args->updated_dawgs->clear();
430  dawg_args->valid_end = false;
431 
432  // Go over the active_dawgs vector and insert DawgPosition records
433  // with the updated ref (an edge with the corresponding unichar id) into
434  // dawg_args->updated_pos.
435  for (int a = 0; a < dawg_args->active_dawgs->length(); ++a) {
436  const DawgPosition& pos = (*dawg_args->active_dawgs)[a];
437  const Dawg* punc_dawg =
438  pos.punc_index >= 0 ? dawgs_[pos.punc_index] : nullptr;
439  const Dawg* dawg = pos.dawg_index >= 0 ? dawgs_[pos.dawg_index] : nullptr;
440 
441  if (!dawg && !punc_dawg) {
442  // shouldn't happen.
443  tprintf("Received DawgPosition with no dawg or punc_dawg. wth?\n");
444  continue;
445  }
446  if (!dawg) {
447  // We're in the punctuation dawg. A core dawg has not been chosen.
448  NODE_REF punc_node = GetStartingNode(punc_dawg, pos.punc_ref);
449  EDGE_REF punc_transition_edge =
450  punc_dawg->edge_char_of(punc_node, Dawg::kPatternUnicharID, word_end);
451  if (punc_transition_edge != NO_EDGE) {
452  // Find all successors, and see which can transition.
453  const SuccessorList& slist = *(successors_[pos.punc_index]);
454  for (int s = 0; s < slist.length(); ++s) {
455  int sdawg_index = slist[s];
456  const Dawg* sdawg = dawgs_[sdawg_index];
457  UNICHAR_ID ch = char_for_dawg(unicharset, unichar_id, sdawg);
458  EDGE_REF dawg_edge = sdawg->edge_char_of(0, ch, word_end);
459  if (dawg_edge != NO_EDGE) {
460  if (dawg_debug_level >= 3) {
461  tprintf("Letter found in dawg %d\n", sdawg_index);
462  }
463  dawg_args->updated_dawgs->add_unique(
464  DawgPosition(sdawg_index, dawg_edge, pos.punc_index,
465  punc_transition_edge, false),
466  dawg_debug_level > 0,
467  "Append transition from punc dawg to current dawgs: ");
468  if (sdawg->permuter() > curr_perm) curr_perm = sdawg->permuter();
469  if (sdawg->end_of_word(dawg_edge) &&
470  punc_dawg->end_of_word(punc_transition_edge))
471  dawg_args->valid_end = true;
472  }
473  }
474  }
475  EDGE_REF punc_edge =
476  punc_dawg->edge_char_of(punc_node, unichar_id, word_end);
477  if (punc_edge != NO_EDGE) {
478  if (dawg_debug_level >= 3) {
479  tprintf("Letter found in punctuation dawg\n");
480  }
481  dawg_args->updated_dawgs->add_unique(
482  DawgPosition(-1, NO_EDGE, pos.punc_index, punc_edge, false),
483  dawg_debug_level > 0, "Extend punctuation dawg: ");
484  if (PUNC_PERM > curr_perm) curr_perm = PUNC_PERM;
485  if (punc_dawg->end_of_word(punc_edge)) dawg_args->valid_end = true;
486  }
487  continue;
488  }
489 
490  if (punc_dawg && dawg->end_of_word(pos.dawg_ref)) {
491  // We can end the main word here.
492  // If we can continue on the punc ref, add that possibility.
493  NODE_REF punc_node = GetStartingNode(punc_dawg, pos.punc_ref);
494  EDGE_REF punc_edge =
495  punc_node == NO_EDGE
496  ? NO_EDGE
497  : punc_dawg->edge_char_of(punc_node, unichar_id, word_end);
498  if (punc_edge != NO_EDGE) {
499  dawg_args->updated_dawgs->add_unique(
501  punc_edge, true),
502  dawg_debug_level > 0, "Return to punctuation dawg: ");
503  if (dawg->permuter() > curr_perm) curr_perm = dawg->permuter();
504  if (punc_dawg->end_of_word(punc_edge)) dawg_args->valid_end = true;
505  }
506  }
507 
508  if (pos.back_to_punc) continue;
509 
510  // If we are dealing with the pattern dawg, look up all the
511  // possible edges, not only for the exact unichar_id, but also
512  // for all its character classes (alpha, digit, etc).
513  if (dawg->type() == DAWG_TYPE_PATTERN) {
514  ProcessPatternEdges(dawg, pos, unichar_id, word_end, dawg_args,
515  &curr_perm);
516  // There can't be any successors to dawg that is of type
517  // DAWG_TYPE_PATTERN, so we are done examining this DawgPosition.
518  continue;
519  }
520 
521  // Find the edge out of the node for the unichar_id.
522  NODE_REF node = GetStartingNode(dawg, pos.dawg_ref);
523  EDGE_REF edge =
524  (node == NO_EDGE)
525  ? NO_EDGE
526  : dawg->edge_char_of(
527  node, char_for_dawg(unicharset, unichar_id, dawg), word_end);
528 
529  if (dawg_debug_level >= 3) {
530  tprintf("Active dawg: [%d, " REFFORMAT "] edge=" REFFORMAT "\n",
531  pos.dawg_index, node, edge);
532  }
533 
534  if (edge != NO_EDGE) { // the unichar was found in the current dawg
535  if (dawg_debug_level >= 3) {
536  tprintf("Letter found in dawg %d\n", pos.dawg_index);
537  }
538  if (word_end && punc_dawg && !punc_dawg->end_of_word(pos.punc_ref)) {
539  if (dawg_debug_level >= 3) {
540  tprintf("Punctuation constraint not satisfied at end of word.\n");
541  }
542  continue;
543  }
544  if (dawg->permuter() > curr_perm) curr_perm = dawg->permuter();
545  if (dawg->end_of_word(edge) &&
546  (punc_dawg == nullptr || punc_dawg->end_of_word(pos.punc_ref)))
547  dawg_args->valid_end = true;
548  dawg_args->updated_dawgs->add_unique(
549  DawgPosition(pos.dawg_index, edge, pos.punc_index, pos.punc_ref,
550  false),
551  dawg_debug_level > 0,
552  "Append current dawg to updated active dawgs: ");
553  }
554  } // end for
555  // Update dawg_args->permuter if it used to be NO_PERM or became NO_PERM
556  // or if we found the current letter in a non-punctuation dawg. This
557  // allows preserving information on which dawg the "core" word came from.
558  // Keep the old value of dawg_args->permuter if it is COMPOUND_PERM.
559  if (dawg_args->permuter == NO_PERM || curr_perm == NO_PERM ||
560  (curr_perm != PUNC_PERM && dawg_args->permuter != COMPOUND_PERM)) {
561  dawg_args->permuter = curr_perm;
562  }
563  if (dawg_debug_level >= 2) {
564  tprintf("Returning %d for permuter code for this character.\n",
565  dawg_args->permuter);
566  }
567  return dawg_args->permuter;
568 }
569 
570 void Dict::ProcessPatternEdges(const Dawg* dawg, const DawgPosition& pos,
571  UNICHAR_ID unichar_id, bool word_end,
572  DawgArgs* dawg_args,
573  PermuterType* curr_perm) const {
574  NODE_REF node = GetStartingNode(dawg, pos.dawg_ref);
575  // Try to find the edge corresponding to the exact unichar_id and to all the
576  // edges corresponding to the character class of unichar_id.
577  GenericVector<UNICHAR_ID> unichar_id_patterns;
578  unichar_id_patterns.push_back(unichar_id);
579  dawg->unichar_id_to_patterns(unichar_id, getUnicharset(),
580  &unichar_id_patterns);
581  for (int i = 0; i < unichar_id_patterns.size(); ++i) {
582  // On the first iteration check all the outgoing edges.
583  // On the second iteration check all self-loops.
584  for (int k = 0; k < 2; ++k) {
585  EDGE_REF edge =
586  (k == 0) ? dawg->edge_char_of(node, unichar_id_patterns[i], word_end)
587  : dawg->pattern_loop_edge(pos.dawg_ref,
588  unichar_id_patterns[i], word_end);
589  if (edge == NO_EDGE) continue;
590  if (dawg_debug_level >= 3) {
591  tprintf("Pattern dawg: [%d, " REFFORMAT "] edge=" REFFORMAT "\n",
592  pos.dawg_index, node, edge);
593  tprintf("Letter found in pattern dawg %d\n", pos.dawg_index);
594  }
595  if (dawg->permuter() > *curr_perm) *curr_perm = dawg->permuter();
596  if (dawg->end_of_word(edge)) dawg_args->valid_end = true;
597  dawg_args->updated_dawgs->add_unique(
598  DawgPosition(pos.dawg_index, edge, pos.punc_index, pos.punc_ref,
599  pos.back_to_punc),
600  dawg_debug_level > 0,
601  "Append current dawg to updated active dawgs: ");
602  }
603  }
604 }
605 
606 // Fill the given active_dawgs vector with dawgs that could contain the
607 // beginning of the word. If hyphenated() returns true, copy the entries
608 // from hyphen_active_dawgs_ instead.
610  bool ambigs_mode) const {
611  int i;
612  if (hyphenated()) {
613  *active_dawgs = hyphen_active_dawgs_;
614  if (dawg_debug_level >= 3) {
615  for (i = 0; i < hyphen_active_dawgs_.size(); ++i) {
616  tprintf("Adding hyphen beginning dawg [%d, " REFFORMAT "]\n",
617  hyphen_active_dawgs_[i].dawg_index,
618  hyphen_active_dawgs_[i].dawg_ref);
619  }
620  }
621  } else {
622  default_dawgs(active_dawgs, ambigs_mode);
623  }
624 }
625 
627  bool suppress_patterns) const {
628  bool punc_dawg_available =
629  (punc_dawg_ != nullptr) &&
630  punc_dawg_->edge_char_of(0, Dawg::kPatternUnicharID, true) != NO_EDGE;
631 
632  for (int i = 0; i < dawgs_.length(); i++) {
633  if (dawgs_[i] != nullptr &&
634  !(suppress_patterns && (dawgs_[i])->type() == DAWG_TYPE_PATTERN)) {
635  int dawg_ty = dawgs_[i]->type();
636  bool subsumed_by_punc = kDawgSuccessors[DAWG_TYPE_PUNCTUATION][dawg_ty];
637  if (dawg_ty == DAWG_TYPE_PUNCTUATION) {
638  *dawg_pos_vec += DawgPosition(-1, NO_EDGE, i, NO_EDGE, false);
639  if (dawg_debug_level >= 3) {
640  tprintf("Adding beginning punc dawg [%d, " REFFORMAT "]\n", i,
641  NO_EDGE);
642  }
643  } else if (!punc_dawg_available || !subsumed_by_punc) {
644  *dawg_pos_vec += DawgPosition(i, NO_EDGE, -1, NO_EDGE, false);
645  if (dawg_debug_level >= 3) {
646  tprintf("Adding beginning dawg [%d, " REFFORMAT "]\n", i, NO_EDGE);
647  }
648  }
649  }
650  }
651 }
652 
653 void Dict::add_document_word(const WERD_CHOICE& best_choice) {
654  // Do not add hyphenated word parts to the document dawg.
655  // hyphen_word_ will be non-nullptr after the set_hyphen_word() is
656  // called when the first part of the hyphenated word is
657  // discovered and while the second part of the word is recognized.
658  // hyphen_word_ is cleared in cc_recg() before the next word on
659  // the line is recognized.
660  if (hyphen_word_) return;
661 
662  int stringlen = best_choice.length();
663 
664  if (valid_word(best_choice) || stringlen < 2) return;
665 
666  // Discard words that contain >= kDocDictMaxRepChars repeating unichars.
667  if (best_choice.length() >= kDocDictMaxRepChars) {
668  int num_rep_chars = 1;
669  UNICHAR_ID uch_id = best_choice.unichar_id(0);
670  for (int i = 1; i < best_choice.length(); ++i) {
671  if (best_choice.unichar_id(i) != uch_id) {
672  num_rep_chars = 1;
673  uch_id = best_choice.unichar_id(i);
674  } else {
675  ++num_rep_chars;
676  if (num_rep_chars == kDocDictMaxRepChars) return;
677  }
678  }
679  }
680 
681  if (best_choice.certainty() < doc_dict_certainty_threshold ||
682  stringlen == 2) {
683  if (best_choice.certainty() < doc_dict_pending_threshold) return;
684 
685  if (!pending_words_->word_in_dawg(best_choice)) {
686  if (stringlen > 2 ||
687  (stringlen == 2 &&
688  getUnicharset().get_isupper(best_choice.unichar_id(0)) &&
689  getUnicharset().get_isupper(best_choice.unichar_id(1)))) {
690  pending_words_->add_word_to_dawg(best_choice);
691  }
692  return;
693  }
694  }
695 
696  if (save_doc_words) {
697  STRING filename(getCCUtil()->imagefile);
698  filename += ".doc";
699  FILE* doc_word_file = fopen(filename.string(), "a");
700  if (doc_word_file == nullptr) {
701  tprintf("Error: Could not open file %s\n", filename.string());
702  ASSERT_HOST(doc_word_file);
703  }
704  fprintf(doc_word_file, "%s\n", best_choice.debug_string().string());
705  fclose(doc_word_file);
706  }
707  document_words_->add_word_to_dawg(best_choice);
708 }
709 
710 void Dict::adjust_word(WERD_CHOICE* word, bool nonword,
711  XHeightConsistencyEnum xheight_consistency,
712  float additional_adjust, bool modify_rating,
713  bool debug) {
714  bool is_han = (getUnicharset().han_sid() != getUnicharset().null_sid() &&
715  word->GetTopScriptID() == getUnicharset().han_sid());
716  bool case_is_ok = (is_han || case_ok(*word));
717  bool punc_is_ok = (is_han || !nonword || valid_punctuation(*word));
718 
719  float adjust_factor = additional_adjust;
720  float new_rating = word->rating();
721  new_rating += kRatingPad;
722  const char* xheight_triggered = "";
723  if (word->length() > 1) {
724  // Calculate x-height and y-offset consistency penalties.
725  switch (xheight_consistency) {
726  case XH_INCONSISTENT:
727  adjust_factor += xheight_penalty_inconsistent;
728  xheight_triggered = ", xhtBAD";
729  break;
730  case XH_SUBNORMAL:
731  adjust_factor += xheight_penalty_subscripts;
732  xheight_triggered = ", xhtSUB";
733  break;
734  case XH_GOOD:
735  // leave the factor alone - all good!
736  break;
737  }
738  // TODO(eger): if nonword is true, but there is a "core" that is a dict
739  // word, negate nonword status.
740  } else {
741  if (debug) {
742  tprintf("Consistency could not be calculated.\n");
743  }
744  }
745  if (debug) {
746  tprintf("%sWord: %s %4.2f%s", nonword ? "Non-" : "",
747  word->unichar_string().string(), word->rating(), xheight_triggered);
748  }
749 
750  if (nonword) { // non-dictionary word
751  if (case_is_ok && punc_is_ok) {
752  adjust_factor += segment_penalty_dict_nonword;
753  new_rating *= adjust_factor;
754  if (debug) tprintf(", W");
755  } else {
756  adjust_factor += segment_penalty_garbage;
757  new_rating *= adjust_factor;
758  if (debug) {
759  if (!case_is_ok) tprintf(", C");
760  if (!punc_is_ok) tprintf(", P");
761  }
762  }
763  } else { // dictionary word
764  if (case_is_ok) {
765  if (!is_han && freq_dawg_ != nullptr && freq_dawg_->word_in_dawg(*word)) {
767  adjust_factor += segment_penalty_dict_frequent_word;
768  new_rating *= adjust_factor;
769  if (debug) tprintf(", F");
770  } else {
771  adjust_factor += segment_penalty_dict_case_ok;
772  new_rating *= adjust_factor;
773  if (debug) tprintf(", ");
774  }
775  } else {
776  adjust_factor += segment_penalty_dict_case_bad;
777  new_rating *= adjust_factor;
778  if (debug) tprintf(", C");
779  }
780  }
781  new_rating -= kRatingPad;
782  if (modify_rating) word->set_rating(new_rating);
783  if (debug) tprintf(" %4.2f --> %4.2f\n", adjust_factor, new_rating);
784  word->set_adjust_factor(adjust_factor);
785 }
786 
787 int Dict::valid_word(const WERD_CHOICE& word, bool numbers_ok) const {
788  const WERD_CHOICE* word_ptr = &word;
789  WERD_CHOICE temp_word(word.unicharset());
790  if (hyphenated() && hyphen_word_->unicharset() == word.unicharset()) {
791  copy_hyphen_info(&temp_word);
792  temp_word += word;
793  word_ptr = &temp_word;
794  }
795  if (word_ptr->length() == 0) return NO_PERM;
796  // Allocate vectors for holding current and updated
797  // active_dawgs and initialize them.
798  auto* active_dawgs = new DawgPositionVector[2];
799  init_active_dawgs(&(active_dawgs[0]), false);
800  DawgArgs dawg_args(&(active_dawgs[0]), &(active_dawgs[1]), NO_PERM);
801  int last_index = word_ptr->length() - 1;
802  // Call letter_is_okay for each letter in the word.
803  for (int i = hyphen_base_size(); i <= last_index; ++i) {
804  if (!((this->*letter_is_okay_)(&dawg_args, *word_ptr->unicharset(),
805  word_ptr->unichar_id(i), i == last_index)))
806  break;
807  // Swap active_dawgs, constraints with the corresponding updated vector.
808  if (dawg_args.updated_dawgs == &(active_dawgs[1])) {
809  dawg_args.updated_dawgs = &(active_dawgs[0]);
810  ++(dawg_args.active_dawgs);
811  } else {
812  ++(dawg_args.updated_dawgs);
813  dawg_args.active_dawgs = &(active_dawgs[0]);
814  }
815  }
816  delete[] active_dawgs;
817  return valid_word_permuter(dawg_args.permuter, numbers_ok)
818  ? dawg_args.permuter
819  : NO_PERM;
820 }
821 
822 bool Dict::valid_bigram(const WERD_CHOICE& word1,
823  const WERD_CHOICE& word2) const {
824  if (bigram_dawg_ == nullptr) return false;
825 
826  // Extract the core word from the middle of each word with any digits
827  // replaced with question marks.
828  int w1start, w1end, w2start, w2end;
829  word1.punct_stripped(&w1start, &w1end);
830  word2.punct_stripped(&w2start, &w2end);
831 
832  // We don't want to penalize a single guillemet, hyphen, etc.
833  // But our bigram list doesn't have any information about punctuation.
834  if (w1start >= w1end) return word1.length() < 3;
835  if (w2start >= w2end) return word2.length() < 3;
836 
837  const UNICHARSET& uchset = getUnicharset();
838  GenericVector<UNICHAR_ID> bigram_string;
839  bigram_string.reserve(w1end + w2end + 1);
840  for (int i = w1start; i < w1end; i++) {
841  const GenericVector<UNICHAR_ID>& normed_ids =
842  getUnicharset().normed_ids(word1.unichar_id(i));
843  if (normed_ids.size() == 1 && uchset.get_isdigit(normed_ids[0]))
844  bigram_string.push_back(question_unichar_id_);
845  else
846  bigram_string += normed_ids;
847  }
848  bigram_string.push_back(UNICHAR_SPACE);
849  for (int i = w2start; i < w2end; i++) {
850  const GenericVector<UNICHAR_ID>& normed_ids =
851  getUnicharset().normed_ids(word2.unichar_id(i));
852  if (normed_ids.size() == 1 && uchset.get_isdigit(normed_ids[0]))
853  bigram_string.push_back(question_unichar_id_);
854  else
855  bigram_string += normed_ids;
856  }
857  WERD_CHOICE normalized_word(&uchset, bigram_string.size());
858  for (int i = 0; i < bigram_string.size(); ++i) {
859  normalized_word.append_unichar_id_space_allocated(bigram_string[i], 1, 0.0f,
860  0.0f);
861  }
862  return bigram_dawg_->word_in_dawg(normalized_word);
863 }
864 
866  if (word.length() == 0) return NO_PERM;
867  int i;
868  WERD_CHOICE new_word(word.unicharset());
869  int last_index = word.length() - 1;
870  int new_len = 0;
871  for (i = 0; i <= last_index; ++i) {
872  UNICHAR_ID unichar_id = (word.unichar_id(i));
873  if (getUnicharset().get_ispunctuation(unichar_id)) {
874  new_word.append_unichar_id(unichar_id, 1, 0.0, 0.0);
875  } else if (!getUnicharset().get_isalpha(unichar_id) &&
876  !getUnicharset().get_isdigit(unichar_id)) {
877  return false; // neither punc, nor alpha, nor digit
878  } else if ((new_len = new_word.length()) == 0 ||
879  new_word.unichar_id(new_len - 1) != Dawg::kPatternUnicharID) {
880  new_word.append_unichar_id(Dawg::kPatternUnicharID, 1, 0.0, 0.0);
881  }
882  }
883  for (i = 0; i < dawgs_.size(); ++i) {
884  if (dawgs_[i] != nullptr && dawgs_[i]->type() == DAWG_TYPE_PUNCTUATION &&
885  dawgs_[i]->word_in_dawg(new_word))
886  return true;
887  }
888  return false;
889 }
890 
893  const UNICHARSET& u_set = getUnicharset();
894  if (u_set.han_sid() > 0) return false;
895  if (u_set.katakana_sid() > 0) return false;
896  if (u_set.thai_sid() > 0) return false;
897  return true;
898 }
899 
900 } // namespace tesseract
bool load_number_dawg
Definition: dict.h:579
void add_document_word(const WERD_CHOICE &best_choice)
Adds a word found on this document to the document specific dictionary.
Definition: dict.cpp:653
bool add_unique(const DawgPosition &new_pos, bool debug, const char *debug_msg)
Definition: dawg.h:385
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
Definition: ratngs.h:452
const STRING & lang() const
Definition: dawg.h:125
PermuterType
Definition: ratngs.h:242
void delete_data_pointers()
bool get_ispunctuation(UNICHAR_ID unichar_id) const
Definition: unicharset.h:519
double xheight_penalty_subscripts
Definition: dict.h:584
bool add_word_to_dawg(const WERD_CHOICE &word, const GenericVector< bool > *repetitions)
Definition: trie.cpp:169
#define STRING_INIT_MEMBER(name, val, comment, vec)
Definition: params.h:333
static const UNICHAR_ID kPatternUnicharID
Definition: dawg.h:122
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
Definition: dict.cpp:787
bool valid_end
Definition: dict.h:84
#define REFFORMAT
Definition: dawg.h:89
int length() const
Definition: genericvector.h:84
int64_t EDGE_REF
Definition: dawg.h:51
char * user_patterns_suffix
Definition: dict.h:573
bool load_unambig_dawg
Definition: dict.h:576
Definition: strngs.h:45
DawgPositionVector * updated_dawgs
Definition: dict.h:81
#define double_MEMBER(name, val, comment, vec)
Definition: params.h:324
int thai_sid() const
Definition: unicharset.h:892
bool load_punc_dawg
Definition: dict.h:578
double doc_dict_certainty_threshold
Definition: dict.h:646
PermuterType permuter
Definition: dict.h:82
virtual bool end_of_word(EDGE_REF edge_ref) const =0
#define BOOL_MEMBER(name, val, comment, vec)
Definition: params.h:318
void set_rating(float new_val)
Definition: ratngs.h:369
const STRING & unichar_string() const
Definition: ratngs.h:541
bool FinishLoad()
Definition: dict.cpp:360
int def_letter_is_okay(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.cpp:404
DawgPositionVector * active_dawgs
Definition: dict.h:80
int length() const
Definition: ratngs.h:303
bool valid_punctuation(const WERD_CHOICE &word)
Definition: dict.cpp:865
#define INT_MEMBER(name, val, comment, vec)
Definition: params.h:315
bool save_doc_words
Definition: dict.h:642
const CCUtil * getCCUtil() const
Definition: dict.h:91
void LoadLSTM(const STRING &lang, TessdataManager *data_file)
Definition: dict.cpp:300
virtual EDGE_REF pattern_loop_edge(EDGE_REF edge_ref, UNICHAR_ID unichar_id, bool word_end) const
Definition: dawg.h:192
void SetupForLoad(DawgCache *dawg_cache)
Definition: dict.cpp:201
int null_sid() const
Definition: unicharset.h:884
void punct_stripped(int *start_core, int *end_core) const
Definition: ratngs.cpp:383
PermuterType permuter() const
Definition: dawg.h:126
int GetTopScriptID() const
Definition: ratngs.cpp:667
Dawg * GetSquishedDawg(const STRING &lang, TessdataType tessdata_dawg_type, int debug_level, TessdataManager *data_file)
Definition: dawg_cache.cpp:45
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
Definition: dict.cpp:609
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:710
bool read_and_add_word_list(const char *filename, const UNICHARSET &unicharset, Trie::RTLReversePolicy reverse)
Definition: trie.cpp:281
void set_permuter(uint8_t perm)
Definition: ratngs.h:375
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:512
double segment_penalty_garbage
Definition: dict.h:607
XHeightConsistencyEnum
Definition: dict.h:74
void copy_hyphen_info(WERD_CHOICE *word) const
Definition: dict.h:140
static NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref)
Returns the appropriate next node given the EDGE_REF.
Definition: dict.h:429
void Load(const STRING &lang, TessdataManager *data_file)
Definition: dict.cpp:219
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:211
bool FreeDawg(Dawg *dawg)
Definition: dawg_cache.h:38
void reserve(int size)
virtual void unichar_id_to_patterns(UNICHAR_ID unichar_id, const UNICHARSET &unicharset, GenericVector< UNICHAR_ID > *vec) const
Definition: dawg.h:181
float rating() const
Definition: ratngs.h:327
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:210
char * user_patterns_file
Definition: dict.h:571
const char * string() const
Definition: strngs.cpp:194
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:36
bool empty() const
Definition: genericvector.h:89
double xheight_penalty_inconsistent
Definition: dict.h:587
char * user_words_suffix
Definition: dict.h:569
int push_back(T object)
bool load_freq_dawg
Definition: dict.h:575
EDGE_REF punc_ref
Definition: dawg.h:372
int(Dict::* letter_is_okay_)(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
Definition: dict.h:363
char * user_words_file
Definition: dict.h:567
double segment_penalty_dict_case_bad
Definition: dict.h:598
void End()
Definition: dict.cpp:381
float certainty() const
Definition: ratngs.h:330
UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:315
bool IsSpaceDelimitedLang() const
Returns true if the language is space-delimited (not CJ, or T).
Definition: dict.cpp:892
bool read_pattern_list(const char *filename, const UNICHARSET &unicharset)
Definition: trie.cpp:394
GenericVector< int > SuccessorList
Definition: dawg.h:65
#define ASSERT_HOST(x)
Definition: errcode.h:88
virtual EDGE_REF edge_char_of(NODE_REF node, UNICHAR_ID unichar_id, bool word_end) const =0
Returns the edge that corresponds to the letter out of this node.
const UNICHARSET & getUnicharset() const
Definition: dict.h:97
#define STRING_MEMBER(name, val, comment, vec)
Definition: params.h:321
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
Definition: unicharset.h:835
double segment_penalty_dict_frequent_word
Definition: dict.h:590
int case_ok(const WERD_CHOICE &word) const
Check a string to see if it matches a set of lexical rules.
Definition: context.cpp:46
void initialize_patterns(UNICHARSET *unicharset)
Definition: trie.cpp:337
bool load_system_dawg
Definition: dict.h:574
static TESS_API DawgCache * GlobalDawgCache()
Definition: dict.cpp:193
double doc_dict_pending_threshold
Definition: dict.h:644
int UNICHAR_ID
Definition: unichar.h:34
double segment_penalty_dict_case_ok
Definition: dict.h:594
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const
Definition: dict.cpp:822
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
Definition: dict.cpp:626
bool get_isupper(UNICHAR_ID unichar_id) const
Definition: unicharset.h:505
int64_t NODE_REF
Definition: dawg.h:52
const STRING debug_string() const
Definition: ratngs.h:505
int size() const
Definition: genericvector.h:70
Dict(CCUtil *image_ptr)
Definition: dict.cpp:30
bool contains_unichar_id(UNICHAR_ID unichar_id) const
Definition: unicharset.h:284
DawgType type() const
Definition: dawg.h:124
void set_adjust_factor(float factor)
Definition: ratngs.h:309
bool hyphenated() const
Returns true if we&#39;ve recorded the beginning of a hyphenated word.
Definition: dict.h:130
EDGE_REF dawg_ref
Definition: dawg.h:370
UNICHAR_ID char_for_dawg(const UNICHARSET &unicharset, UNICHAR_ID ch, const Dawg *dawg) const
Definition: dict.h:439
#define BOOL_INIT_MEMBER(name, val, comment, vec)
Definition: params.h:330
int han_sid() const
Definition: unicharset.h:889
double segment_penalty_dict_nonword
Definition: dict.h:602
int dawg_debug_level
Definition: dict.h:611
int hyphen_base_size() const
Size of the base word (the part on the line before) of a hyphenated word.
Definition: dict.h:134
const UNICHARSET * unicharset() const
Definition: ratngs.h:300
bool load_bigram_dawg
Definition: dict.h:581
static bool valid_word_permuter(uint8_t perm, bool numbers_ok)
Check all the DAWGs to see if this word is in any of them.
Definition: dict.h:465
bool word_in_dawg(const WERD_CHOICE &word) const
Returns true if the given word is in the Dawg.
Definition: dawg.cpp:65
int katakana_sid() const
Definition: unicharset.h:891
STRING language_data_path_prefix
Definition: ccutil.h:70
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:570