19 #ifndef TESSERACT_DICT_DICT_H_ 20 #define TESSERACT_DICT_DICT_H_ 35 #define MAX_WERD_LENGTH (inT64) 128 54 static const int kRatingPad = 4;
55 static const char kDictWildcard[] =
"\u2606";
56 static const int kDictMaxWildcards = 2;
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;
64 static const float kSimCertaintyOffset = -10.0;
65 static const float kSimilarityFloor = 100.0;
66 static const int kDocDictMaxRepChars = 4;
111 return normed_ids.
size() == 1 &&
112 (normed_ids[0] == hyphen_unichar_id_ ||
113 normed_ids[0] == slash_unichar_id_);
120 return normed_ids.
size() == 1 && normed_ids[0] == apostrophe_unichar_id_;
127 !last_word_on_line_ && hyphen_word_;
138 *word = *hyphen_word_;
144 if (!last_word_on_line_ || first_pos)
148 return normed_ids.
size() == 1 && normed_ids[0] == hyphen_unichar_id_;
152 int word_index = word.
length() - 1;
180 bool ambigs_mode)
const;
183 bool suppress_patterns)
const;
199 bool word_ending,
WERD_CHOICE *word,
float certainties[],
200 float *limit,
WERD_CHOICE *best_choice,
int *attempts_left,
201 void *void_more_args);
206 int char_choice_index,
209 float certainties[],
float *limit,
211 void *void_more_args);
218 int char_choice_index,
231 int char_choice_index,
241 float curr_rating,
float curr_certainty,
243 const char *debug,
int word_ending,
249 bool fix_replaceable,
258 void ReplaceAmbig(
int wrong_ngram_begin_index,
int wrong_ngram_size,
309 if (pending_words_ != NULL)
310 pending_words_->
clear();
311 if (document_words_ != NULL)
312 document_words_->
clear();
368 int character_bytes);
373 int character_bytes) {
376 context, context_bytes,
382 const char*
lang,
const char* context,
int context_bytes,
383 const char*
character,
int character_bytes) {
388 (void)character_bytes;
395 int character_bytes);
412 inline const Dawg *
GetDawg(
int index)
const {
return dawgs_[index]; }
419 if (edge_ref == NO_EDGE)
return 0;
421 if (node == 0) node = NO_EDGE;
429 if (!dawg)
return ch;
430 switch (dawg->
type()) {
485 float additional_adjust,
490 wordseg_rating_adjust_factor_ = f;
518 bool last_word_on_line_;
526 bool dawg_cache_is_ours_;
530 Trie *pending_words_;
544 Trie *document_words_;
547 float wordseg_rating_adjust_factor_;
549 FILE *output_ambig_words_file_;
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.");
566 "Load dawg with punctuation 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 " 577 "Score multiplier for word matches which have good case and" 578 "are frequent in the given language (lower is better).");
581 "Score multiplier for word matches that have good case " 582 "(lower is better).");
585 "Default score multiplier for word matches, which may have " 586 "case issues (lower is better).");
590 "Multipler to for the best choice from the ngram model.");
593 "Score multiplier for glyph fragment segmentations which " 594 "do not match a dictionary word (lower is better).");
597 "Score multiplier for poorly cased strings that are not in" 598 " the dictionary and generally look like garbage (lower is" 601 "Output file for ambiguities found in the dictionary");
603 ", to 2 for more details, to 3 to see all the debug messages");
607 "Use only the first UTF8 step of the given string" 608 " when computing log probabilities.");
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)");
622 "Make AcceptableChoice() always return false. Useful" 623 " when there is a need to explore all segmentations");
625 "Deprecated- backward compatibility only");
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_ void ProcessPatternEdges(const Dawg *dawg, const DawgPosition &info, UNICHAR_ID unichar_id, bool word_end, DawgArgs *dawg_args, PermuterType *current_permuter) const
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)
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
bool absolute_garbage(const WERD_CHOICE &word, const UNICHARSET &unicharset)
static const UNICHAR_ID kPatternUnicharID
char * output_ambig_words_file
DawgArgs(DawgPositionVector *d, DawgPositionVector *up, PermuterType p)
void default_dawgs(DawgPositionVector *anylength_dawgs, bool suppress_patterns) const
void ResetDocumentDictionary()
int valid_word_or_number(const WERD_CHOICE &word) const
void SettupStopperPass1()
Sets up stopper variables in preparation for the first pass.
#define STRING_VAR_H(name, val, comment)
bool valid_punctuation(const WERD_CHOICE &word)
DawgPositionVector * updated_dawgs
bool is_apostrophe(UNICHAR_ID unichar_id)
double stopper_allowable_character_badness
bool has_hyphen_end(const WERD_CHOICE &word) const
Same as above, but check the unichar at the end of the word.
void SetWildcardID(UNICHAR_ID id)
UNICHAR_ID unichar_id(int index) const
WERD_CHOICE * dawg_permute_and_select(const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
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)
int def_letter_is_okay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
float(Dict::* params_model_classify_)(const char *lang, void *path)
#define INT_VAR_H(name, val, comment)
double segment_penalty_dict_frequent_word
void SetWordsegRatingAdjustFactor(float f)
Set wordseg_rating_adjust_factor_ to the given value.
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 Load(const char *data_file_name, const STRING &lang)
void SettupStopperPass2()
Sets up stopper variables in preparation for the second pass.
double segment_penalty_ngram_best_choice
const Dawg * GetDawg(int index) const
Return i-th dawg pointer recorded in the dawgs_ vector.
const UNICHARSET & getUnicharset() const
void SetupForLoad(DawgCache *dawg_cache)
void update_best_choice(const WERD_CHOICE &word, WERD_CHOICE *best_choice)
double segment_penalty_dict_nonword
UNICHARSET & getUnicharset()
UnicharAmbigs unichar_ambigs
int max_permuter_attempts
void EndDangerousAmbigs()
double stopper_phase2_certainty_rejection_offset
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.
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.
bool IsSpaceDelimitedLang() const
Returns true if the language is space-delimited (not CJ, or T).
void reset_hyphen_vars(bool last_word_on_line)
const CHAR_FRAGMENT * fragment
bool AcceptableResult(WERD_RES *word)
int NumDawgs() const
Return the number of dawgs in the dawgs_ vector.
double doc_dict_certainty_threshold
#define BOOL_VAR_H(name, val, comment)
const char * string() const
int valid_word(const WERD_CHOICE &word) const
int max_viterbi_list_size
double ProbabilityInContext(const char *context, int context_bytes, const char *character, int character_bytes)
Calls probability_in_context_ member function.
double xheight_penalty_inconsistent
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
double stopper_certainty_per_char
void copy_hyphen_info(WERD_CHOICE *word) 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.
float CallParamsModelClassify(void *path)
void add_document_word(const WERD_CHOICE &best_choice)
Adds a word found on this document to the document specific dictionary.
const UnicharAmbigs & getUnicharAmbigs() const
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
int tessedit_truncate_wordchoice_log
bool AcceptableChoice(const WERD_CHOICE &best_choice, XHeightConsistencyEnum xheight_consistency)
Returns true if the given best_choice is good enough to stop.
UNICHAR_ID WildcardID() const
int LetterIsOkay(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
Calls letter_is_okay_ member function.
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.
char * user_patterns_suffix
bool stopper_no_acceptable_choices
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.
bool segment_nonalphabetic_script
double segment_penalty_dict_case_bad
int UniformCertainties(const WERD_CHOICE &word)
const GenericVector< UNICHAR_ID > & normed_ids(UNICHAR_ID unichar_id) const
int case_ok(const WERD_CHOICE &word, const UNICHARSET &unicharset)
Check a string to see if it matches a set of lexical rules.
int valid_word(const WERD_CHOICE &word, bool numbers_ok) const
double segment_penalty_dict_case_ok
GenericVector< Dawg * > DawgVector
const CCUtil * getCCUtil() const
void DebugWordChoices()
Prints the current choices for this word to stdout.
DawgPositionVector * active_dawgs
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.
double stopper_nondict_certainty_base
bool TESS_API NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
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)
static DawgCache * GlobalDawgCache()
float ParamsModelClassify(const char *lang, void *path)
char * word_to_debug_lengths
char * user_patterns_file
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 xheight_penalty_subscripts
const Dawg * GetUnambigDawg() const
Return the points to the unambiguous words dawg.
bool hyphenated() const
Returns true if we've recorded the beginning of a hyphenated word.
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.
void ReplaceAmbig(int wrong_ngram_begin_index, int wrong_ngram_size, UNICHAR_ID correct_ngram_id, WERD_CHOICE *werd_choice, MATRIX *ratings)
bool has_hyphen_end(UNICHAR_ID unichar_id, bool first_pos) const
Check whether the word has a hyphen at the end.
int stopper_smallword_size
#define double_VAR_H(name, val, comment)
double segment_penalty_garbage
int hyphen_base_size() const
Size of the base word (the part on the line before) of a hyphenated word.
double doc_dict_pending_threshold
bool use_only_first_uft8_step
const Dawg * GetPuncDawg() const
Return the points to the punctuation dawg.
bool compound_marker(UNICHAR_ID unichar_id)
UNICHAR_ID char_for_dawg(UNICHAR_ID ch, const Dawg *dawg) const
bool valid_bigram(const WERD_CHOICE &word1, const WERD_CHOICE &word2) const