19 #ifndef TESSERACT_DICT_DICT_H_ 20 #define TESSERACT_DICT_DICT_H_ 35 #define CHARS_PER_LINE 500 36 #define MAX_WERD_LENGTH (int64_t) 128 55 static const int kRatingPad = 4;
56 static const char kDictWildcard[] =
"\u2606";
57 static const int kDictMaxWildcards = 2;
60 static const char kHyphenSymbol[] =
"-";
61 static const char kSlashSymbol[] =
"/";
62 static const char kQuestionSymbol[] =
"?";
63 static const char kApostropheSymbol[] =
"'";
64 static const float kSimCertaintyScale = -10.0;
65 static const float kSimCertaintyOffset = -10.0;
66 static const float kSimilarityFloor = 100.0;
67 static const int kDocDictMaxRepChars = 4;
112 return normed_ids.
size() == 1 &&
113 (normed_ids[0] == hyphen_unichar_id_ ||
114 normed_ids[0] == slash_unichar_id_);
121 return normed_ids.
size() == 1 && normed_ids[0] == apostrophe_unichar_id_;
128 !last_word_on_line_ && hyphen_word_;
139 *word = *hyphen_word_;
145 if (!last_word_on_line_ || first_pos)
149 return normed_ids.
size() == 1 && normed_ids[0] == hyphen_unichar_id_;
153 int word_index = word.
length() - 1;
181 bool ambigs_mode)
const;
184 bool suppress_patterns)
const;
200 bool word_ending,
WERD_CHOICE *word,
float certainties[],
201 float *limit,
WERD_CHOICE *best_choice,
int *attempts_left,
202 void *void_more_args);
207 int char_choice_index,
210 float certainties[],
float *limit,
212 void *void_more_args);
219 int char_choice_index,
232 int char_choice_index,
242 float curr_rating,
float curr_certainty,
244 const char *debug,
int word_ending,
250 bool fix_replaceable,
259 void ReplaceAmbig(
int wrong_ngram_begin_index,
int wrong_ngram_size,
312 if (pending_words_ !=
nullptr)
313 pending_words_->
clear();
314 if (document_words_ !=
nullptr)
315 document_words_->
clear();
364 unicharset, unichar_id, word_end);
373 int character_bytes);
378 int character_bytes) {
381 context, context_bytes,
387 const char* lang,
const char* context,
int context_bytes,
388 const char*
character,
int character_bytes) {
393 (void)character_bytes;
400 int character_bytes);
417 inline const Dawg *
GetDawg(
int index)
const {
return dawgs_[index]; }
424 if (edge_ref == NO_EDGE)
return 0;
426 if (node == 0) node = NO_EDGE;
434 const Dawg *dawg)
const {
435 if (!dawg)
return ch;
436 switch (dawg->
type()) {
491 float additional_adjust,
496 wordseg_rating_adjust_factor_ = f;
514 float reject_offset_;
524 bool last_word_on_line_;
532 bool dawg_cache_is_ours_;
536 Trie *pending_words_;
550 Trie *document_words_;
553 float wordseg_rating_adjust_factor_;
555 FILE *output_ambig_words_file_;
563 "A suffix of user-provided words located in tessdata.");
565 "A filename of user-provided patterns.");
567 "A suffix of user-provided patterns located in tessdata.");
572 "Load dawg with punctuation patterns.");
575 "Load dawg with special word bigrams.");
577 "Score penalty (0.1 = 10%) added if there are subscripts " 578 "or superscripts in a word, but it is otherwise OK.");
580 "Score penalty (0.1 = 10%) added if an xheight is " 583 "Score multiplier for word matches which have good case and" 584 "are frequent in the given language (lower is better).");
587 "Score multiplier for word matches that have good case " 588 "(lower is better).");
591 "Default score multiplier for word matches, which may have " 592 "case issues (lower is better).");
595 "Score multiplier for glyph fragment segmentations which " 596 "do not match a dictionary word (lower is better).");
599 "Score multiplier for poorly cased strings that are not in" 600 " the dictionary and generally look like garbage (lower is" 603 "Output file for ambiguities found in the dictionary");
605 ", to 2 for more details, to 3 to see all the debug messages");
609 "Use only the first UTF8 step of the given string" 610 " when computing log probabilities.");
613 "Certainty threshold for non-dict words");
615 "Reject certainty offset");
617 "Size of dict word to be treated as non-dict word");
619 "Certainty to add for each dict char above small word size.");
621 "Max certaintly variation allowed in a word (in sigma)");
624 "Make AcceptableChoice() always return false. Useful" 625 " when there is a need to explore all segmentations");
628 " should be printed to stdout");
630 "Lengths of unichars in word_to_debug");
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");
638 "Worst certainty for using pending dictionary");
640 " for words that can be inserted into the document dictionary");
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.");
649 #endif // THIRD_PARTY_TESSERACT_DICT_DICT_H_ static DawgCache * GlobalDawgCache()
int case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset) const
Check a string to see if it matches a set of lexical rules.
#define INT_VAR_H(name, val, comment)
int UniformCertainties(const WERD_CHOICE &word)
UNICHAR_ID WildcardID() const
float ParamsModelClassify(const char *lang, void *path)
double segment_penalty_dict_case_ok
const Dawg * GetPuncDawg() const
Return the points to the punctuation dawg.
const CCUtil * getCCUtil() const
int valid_word(const WERD_CHOICE &word) const
void ResetDocumentDictionary()
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
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.
void reset_hyphen_vars(bool last_word_on_line)
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
const UnicharAmbigs & getUnicharAmbigs() const
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)
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.
#define BOOL_VAR_H(name, val, comment)
double segment_penalty_dict_frequent_word
const char * string() const
int tessedit_truncate_wordchoice_log
double ngram_probability_in_context(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
double doc_dict_pending_threshold
int max_viterbi_list_size
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
double segment_penalty_dict_case_bad
#define double_VAR_H(name, val, comment)
bool AcceptableChoice(const WERD_CHOICE &best_choice, XHeightConsistencyEnum xheight_consistency)
Returns true if the given best_choice is good enough to stop.
bool stopper_no_acceptable_choices
double segment_penalty_dict_nonword
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
void update_best_choice(const WERD_CHOICE &word, WERD_CHOICE *best_choice)
#define STRING_VAR_H(name, val, comment)
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const
void ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size, UNICHAR_ID correct_ngram_id, WERD_CHOICE *werd_choice, MATRIX *ratings)
int hyphen_base_size() const
Size of the base word (the part on the line before) of a hyphenated word.
void EndDangerousAmbigs()
char * output_ambig_words_file
int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
int valid_word_or_number(const WERD_CHOICE &word) const
static NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref)
Returns the appropriate next node given the EDGE_REF.
double segment_penalty_garbage
float(Dict::* params_model_classify_)(const char *lang, void *path)
const Dawg * GetUnambigDawg() const
Return the points to the unambiguous words dawg.
const CHAR_FRAGMENT * fragment
int valid_word(const char *string) const
This function is used by api/tesseract_cube_combiner.cpp.
int good_choice(const WERD_CHOICE &choice)
Returns true if a good answer is found for the unknown blob rating.
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
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)
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
void ProcessPatternEdges(const Dawg *dawg, const DawgPosition &info, UNICHAR_ID unichar_id, bool word_end, DawgArgs *dawg_args, PermuterType *current_permuter) const
bool get_isdigit(UNICHAR_ID unichar_id) const
double stopper_allowable_character_badness
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.
float CallParamsModelClassify(void *path)
double stopper_nondict_certainty_base
DawgPositionVector * updated_dawgs
void SetWildcardID(UNICHAR_ID id)
bool IsSpaceDelimitedLang() const
Returns true if the language is space-delimited (not CJ, or T).
void Load(const STRING &lang, TessdataManager *data_file)
UNICHAR_ID unichar_id(int index) const
bool absolute_garbage(const WERD_CHOICE &word, const UNICHARSET &unicharset)
void LoadLSTM(const STRING &lang, TessdataManager *data_file)
int def_letter_is_okay(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
DawgArgs(DawgPositionVector *d, DawgPositionVector *up, PermuterType p)
void SetupForLoad(DawgCache *dawg_cache)
double doc_dict_certainty_threshold
bool use_only_first_uft8_step
bool valid_punctuation(const WERD_CHOICE &word)
double xheight_penalty_subscripts
double stopper_certainty_per_char
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)
void DebugWordChoices()
Prints the current choices for this word to stdout.
void copy_hyphen_info(WERD_CHOICE *word) const
double ProbabilityInContext(const char *context, int context_bytes, const char *character, int character_bytes)
Calls probability_in_context_ member function.
bool hyphenated() const
Returns true if we've recorded the beginning of a hyphenated word.
int max_permuter_attempts
virtual NODE_REF next_node(EDGE_REF edge_ref) const =0
DawgPositionVector * active_dawgs
const UNICHARSET & getUnicharset() const
char * word_to_debug_lengths
static const UNICHAR_ID kPatternUnicharID
bool is_apostrophe(UNICHAR_ID unichar_id)
void add_document_word(const WERD_CHOICE &best_choice)
Adds a word found on this document to the document specific dictionary.
int stopper_smallword_size
char * user_patterns_file
char * user_patterns_suffix
bool AcceptableResult(WERD_RES *word) const
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
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.
bool compound_marker(UNICHAR_ID unichar_id)
bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const
Check whether the word has a hyphen at the end.
double stopper_phase2_certainty_rejection_offset
bool has_hyphen_end(const WERD_CHOICE &word) const
Same as above, but check the unichar at the end of the word.
UNICHARSET & getUnicharset()
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
WERD_CHOICE * dawg_permute_and_select(const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
double xheight_penalty_inconsistent
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.
bool segment_nonalphabetic_script
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)
int(Dict::* letter_is_okay_)(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
void SetWordsegRatingAdjustFactor(float f)
Set wordseg_rating_adjust_factor_ to the given value.
int LengthOfShortestAlphaRun(const WERD_CHOICE &WordChoice) const
Returns the length of the shortest alpha run in WordChoice.
int LetterIsOkay(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
Calls letter_is_okay_ member function.
bool NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
UnicharAmbigs unichar_ambigs
UNICHAR_ID char_for_dawg(const UNICHARSET &unicharset, UNICHAR_ID ch, const Dawg *dawg) const