19 #ifndef TESSERACT_DICT_DICT_H_
20 #define TESSERACT_DICT_DICT_H_
36 #define MAX_WERD_LENGTH (inT64) 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;
110 return normed_ids.
size() == 1 &&
111 (normed_ids[0] == hyphen_unichar_id_ ||
112 normed_ids[0] == slash_unichar_id_);
119 return normed_ids.
size() == 1 && normed_ids[0] == apostrophe_unichar_id_;
126 !last_word_on_line_ && hyphen_word_;
137 *word = *hyphen_word_;
143 if (!last_word_on_line_ || first_pos)
147 return normed_ids.
size() == 1 && normed_ids[0] == hyphen_unichar_id_;
151 int word_index = word.
length() - 1;
179 bool ambigs_mode)
const;
182 bool suppress_patterns)
const;
198 bool word_ending,
WERD_CHOICE *word,
float certainties[],
199 float *limit,
WERD_CHOICE *best_choice,
int *attempts_left,
200 void *void_more_args);
205 int char_choice_index,
208 float certainties[],
float *limit,
210 void *void_more_args);
217 int char_choice_index,
230 int char_choice_index,
240 float curr_rating,
float curr_certainty,
242 const char *debug,
int word_ending,
248 bool fix_replaceable,
257 void ReplaceAmbig(
int wrong_ngram_begin_index,
int wrong_ngram_size,
302 if (pending_words_ !=
NULL)
303 pending_words_->
clear();
304 if (document_words_ !=
NULL)
305 document_words_->
clear();
361 int character_bytes);
365 const char* character,
366 int character_bytes) {
369 context, context_bytes,
375 const char* lang,
const char* context,
int context_bytes,
376 const char* character,
int character_bytes) {
378 (void) context_bytes;
380 (void) character_bytes;
386 const char* character,
387 int character_bytes);
401 return wildcard_unichar_id_;
406 inline const Dawg *
GetDawg(
int index)
const {
return dawgs_[index]; }
413 if (edge_ref == NO_EDGE)
return 0;
415 if (node == 0) node = NO_EDGE;
423 if (!dawg)
return ch;
424 switch (dawg->
type()) {
479 float additional_adjust,
484 wordseg_rating_adjust_factor_ = f;
510 bool last_word_on_line_;
518 bool dawg_cache_is_ours_;
522 Trie *pending_words_;
536 Trie *document_words_;
539 float wordseg_rating_adjust_factor_;
541 FILE *output_ambig_words_file_;
549 "A suffix of user-provided words located in tessdata.");
551 "A filename of user-provided patterns.");
553 "A suffix of user-provided patterns located in tessdata.");
558 "Load dawg with punctuation patterns.");
561 "Load dawg with special word bigrams.");
563 "Score penalty (0.1 = 10%) added if there are subscripts "
564 "or superscripts in a word, but it is otherwise OK.");
566 "Score penalty (0.1 = 10%) added if an xheight is "
569 "Score multiplier for word matches which have good case and"
570 "are frequent in the given language (lower is better).");
573 "Score multiplier for word matches that have good case "
574 "(lower is better).");
577 "Default score multiplier for word matches, which may have "
578 "case issues (lower is better).");
582 "Multipler to for the best choice from the ngram model.");
585 "Score multiplier for glyph fragment segmentations which "
586 "do not match a dictionary word (lower is better).");
589 "Score multiplier for poorly cased strings that are not in"
590 " the dictionary and generally look like garbage (lower is"
593 "Output file for ambiguities found in the dictionary");
595 ", to 2 for more details, to 3 to see all the debug messages");
599 "Use only the first UTF8 step of the given string"
600 " when computing log probabilities.");
603 "Certainty threshold for non-dict words");
605 "Reject certainty offset");
607 "Size of dict word to be treated as non-dict word");
609 "Certainty to add for each dict char above small word size.");
611 "Max certaintly variation allowed in a word (in sigma)");
614 "Make AcceptableChoice() always return false. Useful"
615 " when there is a need to explore all segmentations");
617 "Deprecated- backward compatability only");
620 " should be printed to stdout");
622 "Lengths of unichars in word_to_debug");
625 "Don't use any alphabetic-specific tricks."
626 "Set to true in the traineddata config file for"
627 " scripts that are cursive or inherently fixed-pitch");
630 "Worst certainty for using pending dictionary");
632 " for words that can be inserted into the document dictionary");
634 " character choices to consider during permutation."
635 " This limit is especially useful when user patterns"
636 " are specified, since overly generic patterns can result in"
637 " dawg search exploring an overly large number of options.");
641 #endif // THIRD_PARTY_TESSERACT_DICT_DICT_H_
void ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size, UNICHAR_ID correct_ngram_id, WERD_CHOICE *werd_choice, MATRIX *ratings)
double stopper_phase2_certainty_rejection_offset
DawgPositionVector * active_dawgs
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 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)
const CHAR_FRAGMENT * fragment
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.
int max_permuter_attempts
char * word_to_debug_lengths
bool has_hyphen_end(const WERD_CHOICE &word) const
Same as above, but check the unichar at the end of the word.
int valid_word(const char *string) const
This function is used by api/tesseract_cube_combiner.cpp.
const CCUtil * getCCUtil() const
void EndDangerousAmbigs()
void update_best_choice(const WERD_CHOICE &word, WERD_CHOICE *best_choice)
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
#define INT_VAR_H(name, val, comment)
void ProcessPatternEdges(const Dawg *dawg, const DawgPosition &info, UNICHAR_ID unichar_id, bool word_end, DawgPositionVector *updated_dawgs, PermuterType *current_permuter) const
bool absolute_garbage(const WERD_CHOICE &word, const UNICHARSET &unicharset)
int good_choice(const WERD_CHOICE &choice)
Returns true if a good answer is found for the unknown blob rating.
double stopper_allowable_character_badness
double segment_penalty_dict_case_ok
void reset_hyphen_vars(bool last_word_on_line)
const UNICHAR_ID WildcardID() const
bool segment_nonalphabetic_script
int def_letter_is_okay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
double xheight_penalty_inconsistent
GenericVector< Dawg * > DawgVector
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
double segment_penalty_ngram_best_choice
double segment_penalty_dict_case_bad
DawgArgs(DawgPositionVector *d, DawgPositionVector *up, PermuterType p)
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
UnicharAmbigs unichar_ambigs
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
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 stopper_smallword_size
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.
char * user_patterns_file
#define STRING_VAR_H(name, val, comment)
void SetWordsegRatingAdjustFactor(float f)
Set wordseg_rating_adjust_factor_ to the given value.
int valid_word(const WERD_CHOICE &word) const
static const UNICHAR_ID kPatternUnicharID
double stopper_certainty_per_char
float(Dict::* params_model_classify_)(const char *lang, void *path)
bool AcceptableChoice(const WERD_CHOICE &best_choice, XHeightConsistencyEnum xheight_consistency)
Returns true if the given best_choice is good enough to stop.
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
bool get_isdigit(UNICHAR_ID unichar_id) const
int LengthOfShortestAlphaRun(const WERD_CHOICE &WordChoice)
Returns the length of the shortest alpha run in WordChoice.
double doc_dict_pending_threshold
static DawgCache * GlobalDawgCache()
void copy_hyphen_info(WERD_CHOICE *word) const
static bool valid_word_permuter(uinT8 perm, bool numbers_ok)
Check all the DAWGs to see if this word is in any of them.
bool valid_punctuation(const WERD_CHOICE &word)
int case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset)
Check a string to see if it matches a set of lexical rules.
float ParamsModelClassify(const char *lang, void *path)
const UnicharAmbigs & getUnicharAmbigs() const
double xheight_penalty_subscripts
double ngram_probability_in_context(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes)
int max_viterbi_list_size
int hyphen_base_size() const
Size of the base word (the part on the line before) of a hyphenated word.
const UNICHAR_ID unichar_id(int index) const
bool compound_marker(UNICHAR_ID unichar_id)
int valid_word_or_number(const WERD_CHOICE &word) const
bool NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
bool use_only_first_uft8_step
double stopper_nondict_certainty_base
UNICHAR_ID char_for_dawg(UNICHAR_ID ch, const Dawg *dawg) const
double segment_penalty_dict_frequent_word
UNICHARSET & getUnicharset()
const Dawg * GetPuncDawg() const
Return the points to the punctuation dawg.
bool hyphenated() const
Returns true if we've recorded the beginning of a hyphenated word.
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)
char * user_patterns_suffix
WERD_CHOICE * dawg_permute_and_select(const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
#define double_VAR_H(name, val, comment)
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const
bool stopper_no_acceptable_choices
int LetterIsOkay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Calls letter_is_okay_ member function.
double doc_dict_certainty_threshold
const Dawg * GetUnambigDawg() const
Return the points to the unambiguous words dawg.
double ProbabilityInContext(const char *context, int context_bytes, const char *character, int character_bytes)
Calls probability_in_context_ member function.
const int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
void Load(DawgCache *dawg_cache)
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
void DebugWordChoices()
Prints the current choices for this word to stdout.
char * output_ambig_words_file
const UNICHARSET & getUnicharset() const
double segment_penalty_dict_nonword
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)
float CallParamsModelClassify(void *path)
bool AcceptableResult(WERD_RES *word)
double segment_penalty_garbage
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
DawgPositionVector * updated_dawgs
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
int tessedit_truncate_wordchoice_log
void add_document_word(const WERD_CHOICE &best_choice)
Adds a word found on this document to the document specific dictionary.
bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const
Check whether the word has a hyphen at the end.
const char * string() const
int UniformCertainties(const WERD_CHOICE &word)
bool is_apostrophe(UNICHAR_ID unichar_id)
virtual NODE_REF next_node(EDGE_REF edge_ref) const =0
#define BOOL_VAR_H(name, val, comment)
static NODE_REF GetStartingNode(const Dawg *dawg, EDGE_REF edge_ref)
Returns the appropriate next node given the EDGE_REF.
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.
void ResetDocumentDictionary()
void SetWildcardID(UNICHAR_ID id)