Tesseract
3.02
|
#include <dict.h>
Public Member Functions | |||||||||||||
Dict (Image *image_ptr) | |||||||||||||
~Dict () | |||||||||||||
const Image * | getImage () const | ||||||||||||
Image * | getImage () | ||||||||||||
const UNICHARSET & | getUnicharset () const | ||||||||||||
UNICHARSET & | getUnicharset () | ||||||||||||
const UnicharAmbigs & | getUnicharAmbigs () | ||||||||||||
bool | compound_marker (UNICHAR_ID unichar_id) | ||||||||||||
bool | hyphenated () const | ||||||||||||
Returns true if we've recorded the beginning of a hyphenated word. | |||||||||||||
int | hyphen_base_size () const | ||||||||||||
Size of the base word (the part on the line before) of a hyphenated word. | |||||||||||||
void | copy_hyphen_info (WERD_CHOICE *word) const | ||||||||||||
void | remove_hyphen_head (WERD_CHOICE *word) const | ||||||||||||
bool | has_hyphen_end (UNICHAR_ID unichar_id, bool first_pos) const | ||||||||||||
Check whether the word has a hyphen at the end. | |||||||||||||
bool | has_hyphen_end (const WERD_CHOICE &word) const | ||||||||||||
Same as above, but check the unichar at the end of the word. | |||||||||||||
void | reset_hyphen_vars (bool last_word_on_line) | ||||||||||||
void | set_hyphen_word (const WERD_CHOICE &word, const DawgInfoVector &active_dawgs, const DawgInfoVector &constraints) | ||||||||||||
void | update_best_choice (const WERD_CHOICE &word, WERD_CHOICE *best_choice) | ||||||||||||
void | init_active_dawgs (int sought_word_length, DawgInfoVector *active_dawgs, bool ambigs_mode) const | ||||||||||||
void | init_constraints (DawgInfoVector *constraints) const | ||||||||||||
bool | ambigs_mode (float rating_limit) | ||||||||||||
Returns true if we are operating in ambigs mode. | |||||||||||||
WERD_CHOICE * | dawg_permute_and_select (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit) | ||||||||||||
WERD_CHOICE * | get_top_choice_word (const BLOB_CHOICE_LIST_VECTOR &char_choices) | ||||||||||||
WERD_CHOICE * | permute_top_choice (const BLOB_CHOICE_LIST_VECTOR &char_choices, float *rating_limit, WERD_CHOICE *raw_choice, BOOL8 *any_alpha) | ||||||||||||
WERD_CHOICE * | permute_all (const BLOB_CHOICE_LIST_VECTOR &char_choices, const WERD_CHOICE *best_choice, WERD_CHOICE *raw_choice) | ||||||||||||
void | end_permute () | ||||||||||||
void | permute_subword (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit, int start, int end, WERD_CHOICE *current_word) | ||||||||||||
bool | permute_characters (const BLOB_CHOICE_LIST_VECTOR &char_choices, WERD_CHOICE *best_choice, WERD_CHOICE *raw_choice) | ||||||||||||
WERD_CHOICE * | permute_compound_words (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit) | ||||||||||||
WERD_CHOICE * | permute_fixed_length_words (const BLOB_CHOICE_LIST_VECTOR &char_choices, PermuterState *permuter_state) | ||||||||||||
void | incorporate_segcost (WERD_CHOICE *word) | ||||||||||||
Incoporate segmentation cost into word rating. | |||||||||||||
WERD_CHOICE * | permute_script_words (const BLOB_CHOICE_LIST_VECTOR &char_choices, PermuterState *permuter_state) | ||||||||||||
WERD_CHOICE * | permute_chartype_words (const BLOB_CHOICE_LIST_VECTOR &char_choices, PermuterState *permuter_state) | ||||||||||||
checks for consistency in character property (eg. alpah, digit, punct) | |||||||||||||
char | top_word_chartype (const BLOB_CHOICE_LIST_VECTOR &char_choices, char *pos_chartypes) | ||||||||||||
bool | NoDangerousAmbig (WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, BLOB_CHOICE_LIST_VECTOR *Choices, bool *modified_blobs) | ||||||||||||
double | StopperAmbigThreshold (double f1, double f2) | ||||||||||||
int | FreeBadChoice (void *item1, void *item2) | ||||||||||||
void | ReplaceAmbig (int wrong_ngram_begin_index, int wrong_ngram_size, UNICHAR_ID correct_ngram_id, WERD_CHOICE *werd_choice, BLOB_CHOICE_LIST_VECTOR *blob_choices, bool *modified_blobs) | ||||||||||||
void | DisableChoiceAccum () | ||||||||||||
void | EnableChoiceAccum () | ||||||||||||
bool | ChoiceAccumEnabled () | ||||||||||||
int | LengthOfShortestAlphaRun (const WERD_CHOICE &WordChoice) | ||||||||||||
Returns the length of the shortest alpha run in WordChoice. | |||||||||||||
VIABLE_CHOICE | NewViableChoice (const WERD_CHOICE &WordChoice, FLOAT32 AdjustFactor, const float Certainties[]) | ||||||||||||
void | PrintViableChoice (FILE *File, const char *Label, VIABLE_CHOICE Choice) | ||||||||||||
Dumps a text representation of the specified Choice to File. | |||||||||||||
bool | StringSameAs (const WERD_CHOICE &WordChoice, VIABLE_CHOICE ViableChoice) | ||||||||||||
bool | StringSameAs (const char *String, const char *String_lengths, VIABLE_CHOICE ViableChoice) | ||||||||||||
Compares String to ViableChoice and returns true if they are the same. | |||||||||||||
int | UniformCertainties (const BLOB_CHOICE_LIST_VECTOR &Choices, const WERD_CHOICE &BestChoice) | ||||||||||||
bool | AcceptableChoice (BLOB_CHOICE_LIST_VECTOR *Choices, WERD_CHOICE *BestChoice, DANGERR *fixpt, ACCEPTABLE_CHOICE_CALLER caller, bool *modified_blobs) | ||||||||||||
Returns true if the given best_choice is good enough to stop. | |||||||||||||
bool | AcceptableResult (const WERD_CHOICE &BestChoice) | ||||||||||||
int | ChoiceSameAs (const WERD_CHOICE &WordChoice, VIABLE_CHOICE ViableChoice) | ||||||||||||
void | LogNewChoice (FLOAT32 AdjustFactor, const float Certainties[], bool raw_choice, WERD_CHOICE *WordChoice, const BLOB_CHOICE_LIST_VECTOR &blob_choices) | ||||||||||||
void | EndDangerousAmbigs () | ||||||||||||
bool | CurrentBestChoiceIs (const WERD_CHOICE &WordChoice) | ||||||||||||
Returns true if WordChoice is the same as the current best choice. | |||||||||||||
FLOAT32 | CurrentBestChoiceAdjustFactor () | ||||||||||||
Returns the adjustment factor for the best choice for the current word. | |||||||||||||
bool | CurrentWordAmbig () | ||||||||||||
Returns true if there are multiple good choices for the current word. | |||||||||||||
void | DebugWordChoices () | ||||||||||||
Prints the current choices for this word to stdout. | |||||||||||||
void | PrintAmbigAlternatives (FILE *file, const char *label, int label_num_unichars) | ||||||||||||
Print all the choices in raw_choices_ list for non 1-1 ambiguities. | |||||||||||||
void | FillViableChoice (const WERD_CHOICE &WordChoice, FLOAT32 AdjustFactor, const float Certainties[], VIABLE_CHOICE ViableChoice) | ||||||||||||
bool | AlternativeChoicesWorseThan (FLOAT32 Threshold) | ||||||||||||
void | FilterWordChoices () | ||||||||||||
void | FindClassifierErrors (FLOAT32 MinRating, FLOAT32 MaxRating, FLOAT32 RatingMargin, FLOAT32 Thresholds[]) | ||||||||||||
void | InitChoiceAccum () | ||||||||||||
void | ClearBestChoiceAccum () | ||||||||||||
Clears best_choices_ list accumulated by the stopper. | |||||||||||||
void | LogNewSegmentation (PIECES_STATE BlobWidth) | ||||||||||||
void | LogNewSplit (int Blob) | ||||||||||||
void | AddNewChunk (VIABLE_CHOICE Choice, int Blob) | ||||||||||||
void | SettupStopperPass1 () | ||||||||||||
Sets up stopper variables in preparation for the first pass. | |||||||||||||
void | SettupStopperPass2 () | ||||||||||||
Sets up stopper variables in preparation for the second pass. | |||||||||||||
int | case_ok (const WERD_CHOICE &word, const UNICHARSET &unicharset) | ||||||||||||
Check a string to see if it matches a set of lexical rules. | |||||||||||||
bool | absolute_garbage (const WERD_CHOICE &word, const UNICHARSET &unicharset) | ||||||||||||
void | Load () | ||||||||||||
void | End () | ||||||||||||
void | ResetDocumentDictionary () | ||||||||||||
void | LoadEquivalenceList (const char *unichar_strings[]) | ||||||||||||
UNICHAR_ID | NormalizeUnicharIdForMatch (UNICHAR_ID unichar_id) const | ||||||||||||
int | def_letter_is_okay (void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const | ||||||||||||
int | LetterIsOkay (void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const | ||||||||||||
Calls letter_is_okay_ member function. | |||||||||||||
double | ProbabilityInContext (const char *context, int context_bytes, const char *character, int character_bytes) | ||||||||||||
Calls probability_in_context_ member function. | |||||||||||||
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. | |||||||||||||
double | ngram_probability_in_context (const char *lang, const char *context, int context_bytes, const char *character, int character_bytes) | ||||||||||||
const int | NumDawgs () const | ||||||||||||
Return the number of dawgs in the dawgs_ vector. | |||||||||||||
const Dawg * | GetDawg (int index) const | ||||||||||||
Return i-th dawg pointer recorded in the dawgs_ vector. | |||||||||||||
const Dawg * | GetPuncDawg () const | ||||||||||||
Return the points to the punctuation dawg. | |||||||||||||
const Dawg * | GetUnambigDawg () const | ||||||||||||
Return the points to the unambiguous words dawg. | |||||||||||||
const Dawg * | GetFixedLengthDawg (int word_length) const | ||||||||||||
Return the pointer to the Dawg that contains words of length word_length. | |||||||||||||
const int | GetMaxFixedLengthDawgIndex () const | ||||||||||||
bool | ConstraintsOk (const DawgInfoVector &constraints, int word_end, DawgType current_dawg_type) const | ||||||||||||
void | ProcessPatternEdges (const Dawg *dawg, const DawgInfo &info, UNICHAR_ID unichar_id, bool word_end, DawgArgs *dawg_args, PermuterType *current_permuter) const | ||||||||||||
int | valid_word (const WERD_CHOICE &word, bool numbers_ok) const | ||||||||||||
int | valid_word (const WERD_CHOICE &word) const | ||||||||||||
int | valid_word_or_number (const WERD_CHOICE &word) const | ||||||||||||
int | valid_word (const char *string) const | ||||||||||||
This function is used by api/tesseract_cube_combiner.cpp. | |||||||||||||
bool | valid_bigram (const WERD_CHOICE &word1, const WERD_CHOICE &word2) const | ||||||||||||
bool | valid_punctuation (const WERD_CHOICE &word) | ||||||||||||
int | good_choice (const WERD_CHOICE &choice) | ||||||||||||
Returns true if a good answer is found for the unknown blob rating. | |||||||||||||
void | add_document_word (const WERD_CHOICE &best_choice) | ||||||||||||
Adds a word found on this document to the document specific dictionary. | |||||||||||||
int | get_top_word_script (const BLOB_CHOICE_LIST_VECTOR &char_choices, const UNICHARSET &unicharset) | ||||||||||||
void | adjust_word (WERD_CHOICE *word, float *certainty_array, const BLOB_CHOICE_LIST_VECTOR *char_choices, bool nonword, float additional_adjust, bool debug) | ||||||||||||
Adjusts the rating of the given word. | |||||||||||||
void | adjust_word (WERD_CHOICE *word, float *certainty_array, const BLOB_CHOICE_LIST_VECTOR *char_choices, bool debug) | ||||||||||||
void | adjust_non_word (WERD_CHOICE *word, float *certainty_array, const BLOB_CHOICE_LIST_VECTOR *char_choices, bool debug) | ||||||||||||
void | SetWordsegRatingAdjustFactor (float f) | ||||||||||||
Set wordseg_rating_adjust_factor_ to the given value. | |||||||||||||
const LIST & | getBestChoices () | ||||||||||||
go_deeper_dawg_fxn | |||||||||||||
If the choice being composed so far could be a dictionary word keep exploring choices. There are two modes for deciding whether to go deeper: regular dawg permuter mode and the special ambigs mode. If *limit is <= 0.0 the function switches to the ambigs mode (this is the case when dawg_permute_and_select() function is called from NoDangerousAmbigs()) and only searches for the first choice that has a rating better than *limit (in this case ratings are fake, since the real ratings can not be < 0). Modification of the hyphen state is turned off in the ambigs mode. When in the regular dawg permuter mode, the function explores all the possible words and chooses the one with the best rating. The letters with ratings that are far worse than the ones seen so far are pruned out. | |||||||||||||
WERD_CHOICE * | dawg_permute_and_select (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit, int sought_word_length, int end_char_choice_index) | ||||||||||||
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) | ||||||||||||
choose_il1 | |||||||||||||
Choose between the candidate il1 chars.
| |||||||||||||
const char * | choose_il1 (const char *first_char, const char *second_char, const char *third_char, const char *prev_char, const char *next_char, const char *next_next_char) | ||||||||||||
fragment_state | |||||||||||||
Given the current char choice and information about previously seen fragments, determines whether adjacent character fragments are present and whether they can be concatenated. The given prev_char_frag_info contains:
The output char_frag_info is filled in as follows:
| |||||||||||||
WERD_CHOICE * | top_fragments_permute_and_select (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit) | ||||||||||||
void | go_deeper_top_fragments_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 *more_args) | ||||||||||||
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) | ||||||||||||
Semi-generic functions used by multiple permuters. | |||||||||||||
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) | ||||||||||||
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) |
Static Public Member Functions | |
static NODE_REF | GetStartingNode (const Dawg *dawg, EDGE_REF edge_ref) |
Returns the appropriate next node given the EDGE_REF. | |
static void | ReadFixedLengthDawgs (DawgType type, const STRING &lang, PermuterType perm, int debug_level, FILE *file, DawgVector *dawg_vec, int *max_wdlen) |
static void | WriteFixedLengthDawgs (const GenericVector< SquishedDawg * > &dawg_vec, int num_dawgs, int debug_level, FILE *output_file) |
static bool | valid_word_permuter (uinT8 perm, bool numbers_ok) |
Check all the DAWGs to see if this word is in any of them. |
tesseract::Dict::Dict | ( | Image * | image_ptr | ) |
Definition at line 33 of file dict.cpp.
tesseract::Dict::~Dict | ( | ) |
bool tesseract::Dict::absolute_garbage | ( | const WERD_CHOICE & | word, |
const UNICHARSET & | unicharset | ||
) |
Returns true if the word looks like an absolute garbage (e.g. image mistakenly recognized as text).
Definition at line 78 of file context.cpp.
bool tesseract::Dict::AcceptableChoice | ( | BLOB_CHOICE_LIST_VECTOR * | Choices, |
WERD_CHOICE * | BestChoice, | ||
DANGERR * | fixpt, | ||
ACCEPTABLE_CHOICE_CALLER | caller, | ||
bool * | modified_blobs | ||
) |
Returns true if the given best_choice is good enough to stop.
Definition at line 191 of file stopper.cpp.
bool tesseract::Dict::AcceptableResult | ( | const WERD_CHOICE & | BestChoice | ) |
Returns false if the best choice for the current word is questionable and should be tried again on the second pass or should be flagged to the user.
Definition at line 254 of file stopper.cpp.
void tesseract::Dict::add_document_word | ( | const WERD_CHOICE & | best_choice | ) |
Adds a word found on this document to the document specific dictionary.
Definition at line 690 of file dict.cpp.
void tesseract::Dict::AddNewChunk | ( | VIABLE_CHOICE | Choice, |
int | Blob | ||
) |
Increments the chunk count of the character in Choice which corresponds to Blob (index of the blob being split).
Definition at line 788 of file stopper.cpp.
|
inline |
void tesseract::Dict::adjust_word | ( | WERD_CHOICE * | word, |
float * | certainty_array, | ||
const BLOB_CHOICE_LIST_VECTOR * | char_choices, | ||
bool | nonword, | ||
float | additional_adjust, | ||
bool | debug | ||
) |
Adjusts the rating of the given word.
Definition at line 749 of file dict.cpp.
|
inline |
bool tesseract::Dict::AlternativeChoicesWorseThan | ( | FLOAT32 | Threshold | ) |
Returns true if there are no alternative choices for the current word or if all alternatives have an adjust factor worse than Threshold.
Definition at line 299 of file stopper.cpp.
|
inline |
void tesseract::Dict::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 | ||
) |
append_choices
Checks to see whether or not the next choice is worth appending to the word being generated. If so then keeps going deeper into the word.
This function assumes that Dict::go_deeper_fxn_ is set.
Definition at line 1479 of file permute.cpp.
int tesseract::Dict::case_ok | ( | const WERD_CHOICE & | word, |
const UNICHARSET & | unicharset | ||
) |
Check a string to see if it matches a set of lexical rules.
Definition at line 58 of file context.cpp.
|
inline |
int tesseract::Dict::ChoiceSameAs | ( | const WERD_CHOICE & | WordChoice, |
VIABLE_CHOICE | ViableChoice | ||
) |
Compares the corresponding strings of WordChoice and ViableChoice and returns true if they are the same.
Definition at line 878 of file stopper.cpp.
const char * tesseract::Dict::choose_il1 | ( | const char * | first_char, |
const char * | second_char, | ||
const char * | third_char, | ||
const char * | prev_char, | ||
const char * | next_char, | ||
const char * | next_next_char | ||
) |
Definition at line 1163 of file permute.cpp.
void tesseract::Dict::ClearBestChoiceAccum | ( | ) |
Clears best_choices_ list accumulated by the stopper.
Definition at line 458 of file stopper.cpp.
|
inline |
|
inline |
At word ending make sure all the recorded constraints are satisfied. Each constraint signifies that we found a beginning pattern in a pattern dawg. Check that this pattern can end here (e.g. if some leading punctuation is found this would ensure that we are not expecting any particular trailing punctuation after the word).
Definition at line 631 of file dict.h.
|
inline |
If this word is hyphenated copy the base word (the part on the line before) of a hyphenated word into the given word. This function assumes that word is not NULL.
FLOAT32 tesseract::Dict::CurrentBestChoiceAdjustFactor | ( | ) |
Returns the adjustment factor for the best choice for the current word.
Definition at line 316 of file stopper.cpp.
bool tesseract::Dict::CurrentBestChoiceIs | ( | const WERD_CHOICE & | WordChoice | ) |
Returns true if WordChoice is the same as the current best choice.
Definition at line 311 of file stopper.cpp.
bool tesseract::Dict::CurrentWordAmbig | ( | ) |
Returns true if there are multiple good choices for the current word.
Definition at line 325 of file stopper.cpp.
WERD_CHOICE * tesseract::Dict::dawg_permute_and_select | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
float | rating_limit, | ||
int | sought_word_length, | ||
int | start_char_choice_index | ||
) |
Recursively explore all the possible character combinations in the given char_choices. Use go_deeper_dawg_fxn() to explore all the dawgs in the dawgs_ vector in parallel and discard invalid words.
Allocate and return a WERD_CHOICE with the best valid word found.
dawg_permute_and_select
Recursively explore all the possible character combinations in the given char_choices. Use go_deeper_dawg_fxn() to search all the dawgs in the dawgs_ vector in parallel and discard invalid words.
If sought_word_length is not kAnyWordLength, the function only searches for a valid word formed by the given char_choices in one fixed length dawg (that contains words of length sought_word_length) starting at the start_char_choice_index.
Allocate and return a WERD_CHOICE with the best valid word found.
Definition at line 263 of file permdawg.cpp.
|
inline |
void tesseract::Dict::DebugWordChoices | ( | ) |
Prints the current choices for this word to stdout.
Definition at line 330 of file stopper.cpp.
int tesseract::Dict::def_letter_is_okay | ( | void * | void_dawg_args, |
UNICHAR_ID | unichar_id, | ||
bool | word_end | ||
) | const |
Returns the maximal permuter code (from ccstruct/ratngs.h) if in light of the current state the letter at word_index in the given word is allowed according to at least one of the dawgs in dawgs_, otherwise returns NO_PERM.
The state is described by void_dawg_args, which are interpreted as DawgArgs and contain two relevant input vectors: active_dawgs and constraints. Each entry in the active_dawgs vector contains an index into the dawgs_ vector and an EDGE_REF that indicates the last edge followed in the dawg. Each entry in the constraints vector contains an index into the dawgs_ vector and an EDGE_REF that indicates an edge in a pattern dawg followed to match a pattern. Currently constraints are used to save the state of punctuation dawgs after leading punctuation was found.
Input: At word_index 0 dawg_args->active_dawgs should contain an entry for each dawg whose type has a bit set in kBeginningDawgsType, dawg_args->constraints should be empty. EDGE_REFs in active_dawgs and constraints vectors should be initialized to NO_EDGE. If hyphen state needs to be applied, initial dawg_args->active_dawgs and dawg_args->constrains can be copied from the saved hyphen state (maintained by Dict). For word_index > 0 the corresponding state (active_dawgs and constraints) can be obtained from dawg_args->updated_* passed to def_letter_is_okay for word_index-1. Note: the function assumes that active_dags, constraints and updated_* member variables of dawg_args are not NULL.
Output: The function fills in dawg_args->updated_active_dawgs vector with the entries for dawgs that contain the word up to the letter at word_index. The new constraints (if any) are added to dawg_args->updated_constraints, the constraints from dawg_args->constraints are also copied into it.
Detailed description: In order to determine whether the word is still valid after considering all the letters up to the one at word_index the following is done for each entry in dawg_args->active_dawgs:
Definition at line 380 of file dict.cpp.
|
inline |
|
inline |
|
inline |
void tesseract::Dict::End | ( | ) |
Definition at line 335 of file dict.cpp.
void tesseract::Dict::end_permute | ( | ) |
void tesseract::Dict::EndDangerousAmbigs | ( | ) |
Definition at line 778 of file stopper.cpp.
void tesseract::Dict::FillViableChoice | ( | const WERD_CHOICE & | WordChoice, |
FLOAT32 | AdjustFactor, | ||
const float | Certainties[], | ||
VIABLE_CHOICE | ViableChoice | ||
) |
Fill ViableChoice with information from WordChoice, AChoice, AdjustFactor, and Certainties.
Definition at line 943 of file stopper.cpp.
void tesseract::Dict::FilterWordChoices | ( | ) |
Removes from best_choices_ all choices which are not within a reasonable range of the best choice.
Definition at line 375 of file stopper.cpp.
void tesseract::Dict::FindClassifierErrors | ( | FLOAT32 | MinRating, |
FLOAT32 | MaxRating, | ||
FLOAT32 | RatingMargin, | ||
FLOAT32 | Thresholds[] | ||
) |
Compares the best choice for the current word to the best raw choice to determine which characters were classified incorrectly by the classifier. Then places a separate threshold into Thresholds for each character in the word. If the classifier was correct, MaxRating is placed into Thresholds. If the classifier was incorrect, the avg. match rating (error percentage) of the classifier's incorrect choice minus some margin is placed into thresholds.This can then be used by the caller to try to create a new template for the desired class that will classify the character with a rating better than the threshold value. The match rating placed into Thresholds is never allowed to be below MinRating in order to prevent trying to make overly tight templates. MinRating limits how tight to make a template. MaxRating limits how loose to make a template. RatingMargin denotes the amount of margin to put in template.
Definition at line 394 of file stopper.cpp.
bool tesseract::Dict::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 | ||
) |
Semi-generic functions used by multiple permuters.
Definition at line 1283 of file permute.cpp.
int tesseract::Dict::FreeBadChoice | ( | void * | item1, |
void * | item2 | ||
) |
Definition at line 167 of file stopper.cpp.
WERD_CHOICE * tesseract::Dict::get_top_choice_word | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices | ) |
Return the top choice for each character as the choice for the word.
Definition at line 908 of file permute.cpp.
int tesseract::Dict::get_top_word_script | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
const UNICHARSET & | unicharset | ||
) |
Definition at line 908 of file dict.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void tesseract::Dict::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 | ||
) |
If the choice being composed so far could be a dictionary word and we have not reached the end of the word keep exploring the char_choices further. Also: – sets hyphen word if needed – if word_ending is true and the word is better than best_choice, copies word to best_choice and logs new word choice
Definition at line 67 of file permdawg.cpp.
void tesseract::Dict::go_deeper_top_fragments_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 * | more_args | ||
) |
While the choice being composed so far could be better than best_choice keeps exploring char_choices. If the end of the word is reached and the word is better than best_choice, copies word to best_choice and logs the new word choice.
go_deeper_top_fragments_fxn
While the choice being composed so far could be better than best_choice keeps exploring char_choices. If the end of the word is reached and the word is better than best_choice, copies word to best_choice and logs the new word choice.
Definition at line 1538 of file permute.cpp.
int tesseract::Dict::good_choice | ( | const WERD_CHOICE & | choice | ) |
Returns true if a good answer is found for the unknown blob rating.
|
inline |
|
inline |
|
inline |
Size of the base word (the part on the line before) of a hyphenated word.
|
inline |
Returns true if we've recorded the beginning of a hyphenated word.
void tesseract::Dict::incorporate_segcost | ( | WERD_CHOICE * | word | ) |
Incoporate segmentation cost into word rating.
Incorporate segmentation cost into the word rating. This is done through a multiplier wordseg_rating_adjust_factor_ which is determined in bestfirst.cpp during state evaluation. This is not the cleanest way to do this. It would be better to reorganize the SEARCH_STATE to keep track of associated states, or do the rating adjustment outside the permuter in evalaute_state.
Definition at line 409 of file permute.cpp.
void tesseract::Dict::init_active_dawgs | ( | int | sought_word_length, |
DawgInfoVector * | active_dawgs, | ||
bool | ambigs_mode | ||
) | const |
Fill the given active_dawgs vector with dawgs that could contain the beginning of the word. If hyphenated() returns true, copy the entries from hyphen_active_dawgs_ instead.
Definition at line 643 of file dict.cpp.
void tesseract::Dict::init_constraints | ( | DawgInfoVector * | constraints | ) | const |
If hyphenated() returns true, copy the entries from hyphen_constraints_ into the given constraints vector.
Definition at line 677 of file dict.cpp.
void tesseract::Dict::InitChoiceAccum | ( | ) |
Initializes the data structures used to keep track the good word choices found for a word.
Definition at line 435 of file stopper.cpp.
int tesseract::Dict::LengthOfShortestAlphaRun | ( | const WERD_CHOICE & | WordChoice | ) |
Returns the length of the shortest alpha run in WordChoice.
Definition at line 883 of file stopper.cpp.
|
inline |
Calls letter_is_okay_ member function.
void tesseract::Dict::Load | ( | ) |
Initialize Dict class - load dawgs from [lang].traineddata and user-specified wordlist and parttern list.
Definition at line 219 of file dict.cpp.
void tesseract::Dict::LoadEquivalenceList | ( | const char * | unichar_strings[] | ) |
Definition at line 354 of file dict.cpp.
void tesseract::Dict::LogNewChoice | ( | FLOAT32 | AdjustFactor, |
const float | Certainties[], | ||
bool | raw_choice, | ||
WERD_CHOICE * | WordChoice, | ||
const BLOB_CHOICE_LIST_VECTOR & | blob_choices | ||
) |
Adds Choice to ChoicesList if the adjusted certainty for Choice is within a reasonable range of the best choice in ChoicesList. The ChoicesList list is kept in sorted order by rating. Duplicates are removed. WordChoice is the new choice for current word. AdjustFactor is an adjustment factor which was applied to choice. Certainties are certainties for each char in new choice. raw_choice indicates whether WordChoice is a raw or best choice.
Definition at line 484 of file stopper.cpp.
void tesseract::Dict::LogNewSegmentation | ( | PIECES_STATE | BlobWidth | ) |
Updates the blob widths in current_segmentation_ to be the same as provided in BlobWidth. BlobWidth[] contains the number of chunks in each blob in the current segmentation.
Definition at line 463 of file stopper.cpp.
void tesseract::Dict::LogNewSplit | ( | int | Blob | ) |
Given Blob (the index of the blob that was split), adds 1 chunk to the specified blob for each choice in best_choices_ and for best_raw_choice_.
Definition at line 471 of file stopper.cpp.
VIABLE_CHOICE tesseract::Dict::NewViableChoice | ( | const WERD_CHOICE & | WordChoice, |
FLOAT32 | AdjustFactor, | ||
const float | Certainties[] | ||
) |
Allocates a new viable choice data structure, copies WordChoice, Certainties, and current_segmentation_ into it, returns a pointer to the newly created VIABLE_CHOICE. WordChoice is a choice to be converted to a viable choice. AdjustFactor is a factor used to adjust ratings for WordChoice. Certainties contain certainty for each character in WordChoice.
Definition at line 902 of file stopper.cpp.
double tesseract::Dict::ngram_probability_in_context | ( | const char * | lang, |
const char * | context, | ||
int | context_bytes, | ||
const char * | character, | ||
int | character_bytes | ||
) |
bool tesseract::Dict::NoDangerousAmbig | ( | WERD_CHOICE * | BestChoice, |
DANGERR * | fixpt, | ||
bool | fix_replaceable, | ||
BLOB_CHOICE_LIST_VECTOR * | Choices, | ||
bool * | modified_blobs | ||
) |
Definition at line 581 of file stopper.cpp.
UNICHAR_ID tesseract::Dict::NormalizeUnicharIdForMatch | ( | UNICHAR_ID | unichar_id | ) | const |
|
inline |
WERD_CHOICE * tesseract::Dict::permute_all | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
const WERD_CHOICE * | best_choice, | ||
WERD_CHOICE * | raw_choice | ||
) |
Definition at line 331 of file permute.cpp.
bool tesseract::Dict::permute_characters | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
WERD_CHOICE * | best_choice, | ||
WERD_CHOICE * | raw_choice | ||
) |
permute_characters
Permute these characters together according to each of the different permuters that are enabled. Returns true if best_choice was updated.
Definition at line 765 of file permute.cpp.
WERD_CHOICE * tesseract::Dict::permute_chartype_words | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
PermuterState * | permuter_state | ||
) |
checks for consistency in character property (eg. alpah, digit, punct)
Definition at line 542 of file permute.cpp.
void tesseract::Dict::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 | ||
) |
permute_choices
Call append_choices() for each BLOB_CHOICE in BLOB_CHOICE_LIST with the given char_choice_index in char_choices.
Definition at line 1437 of file permute.cpp.
WERD_CHOICE * tesseract::Dict::permute_compound_words | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
float | rating_limit | ||
) |
permute_compound_words
Return the top choice for each character as the choice for the word.
Definition at line 799 of file permute.cpp.
WERD_CHOICE * tesseract::Dict::permute_fixed_length_words | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
PermuterState * | permuter_state | ||
) |
Find permutations matching a list of fixed-char-length dawgs The bestchoice based on this permuter alone is returned. Alternatively, non-conflicting changes can be combined through permuter_state.
Perform search on fixed-length dictionaries within a word. This is used for non-space delimited languages like CJK when a "word" corresponds to a "phrase" consisted of multiple short words. It iterates over every character position looking for longest matches against a set of fixed-length dawgs. Each dictionary hit is rewarded with a rating bonus. Note: this is very slow as it is performed on every segmentation state.
Definition at line 430 of file permute.cpp.
WERD_CHOICE * tesseract::Dict::permute_script_words | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
PermuterState * | permuter_state | ||
) |
Checks for script-consistent permutations. Similar to fixed-length permuter, the best choice is returned by the function, but the combined changes are also recorded into permuter_state.
Try flipping characters in a word to get better script consistency. Similar to how upper/lower case checking is done in top_choice_permuter, this permuter tries to suggest a more script-consistent choice AND modifies the rating. So it combines both the case_ok check and adjust_non_word functionality. However, instead of penalizing an inconsistent word with a > 1 multiplier, we reward the script-consistent choice with a < 1 multiplier.
Definition at line 669 of file permute.cpp.
void tesseract::Dict::permute_subword | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
float | rating_limit, | ||
int | start, | ||
int | end, | ||
WERD_CHOICE * | current_word | ||
) |
permute_subword
Permute a part of a compound word this subword is bounded by hyphens and the start and end of the word. Call the standard word permute function on a set of choices covering only part of the original word. When it is done reclaim the memory that was used in the exercise.
Definition at line 859 of file permute.cpp.
WERD_CHOICE * tesseract::Dict::permute_top_choice | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
float * | rating_limit, | ||
WERD_CHOICE * | raw_choice, | ||
BOOL8 * | any_alpha | ||
) |
permute_top_choice
Return the top choice for each character as the choice for the word. In addition a choice is created for the best lower and upper case non-words. In each character position the best lower (or upper) case character is substituted for the best overall character.
Definition at line 934 of file permute.cpp.
void tesseract::Dict::PrintAmbigAlternatives | ( | FILE * | file, |
const char * | label, | ||
int | label_num_unichars | ||
) |
Print all the choices in raw_choices_ list for non 1-1 ambiguities.
Definition at line 358 of file stopper.cpp.
void tesseract::Dict::PrintViableChoice | ( | FILE * | File, |
const char * | Label, | ||
VIABLE_CHOICE | Choice | ||
) |
Dumps a text representation of the specified Choice to File.
Definition at line 912 of file stopper.cpp.
|
inline |
void tesseract::Dict::ProcessPatternEdges | ( | const Dawg * | dawg, |
const DawgInfo & | info, | ||
UNICHAR_ID | unichar_id, | ||
bool | word_end, | ||
DawgArgs * | dawg_args, | ||
PermuterType * | current_permuter | ||
) | const |
For each of the character classes of the given unichar_id (and the unichar_id itself) finds the corresponding outgoing node or self-loop in the given dawg and (after checking that it is valid) records it in dawg_args->updated_ative_dawgs. Updates current_permuter if any valid edges were found.
Definition at line 554 of file dict.cpp.
|
static |
Read/Write/Access special purpose dawgs which contain words only of a certain length (used for phrase search for non-space-delimited languages). Reads a sequence of dawgs from the given file. Appends the constructed dawgs to the given dawg_vec. Fills the given table with indices of the dawgs in the dawg_vec corresponding to the dawgs with words of a particular length.
Definition at line 592 of file dict.cpp.
|
inline |
Erase the unichar ids corresponding to the portion of the word from the previous line. The word is not changed if it is not split between lines and hyphenated.
void tesseract::Dict::ReplaceAmbig | ( | int | wrong_ngram_begin_index, |
int | wrong_ngram_size, | ||
UNICHAR_ID | correct_ngram_id, | ||
WERD_CHOICE * | werd_choice, | ||
BLOB_CHOICE_LIST_VECTOR * | blob_choices, | ||
bool * | modified_blobs | ||
) |
Replaces the corresponding wrong ngram in werd_choice with the correct one. We indicate that this newly inserted ngram unichar is composed from several fragments and modify the corresponding entries in blob_choices to contain fragments of the correct ngram unichar instead of the original unichars. Ratings and certainties of entries in blob_choices and werd_choice are unichaged. E.g. for werd_choice mystring'' and ambiguity ''->": werd_choice becomes mystring", first ' in blob_choices becomes |"|0|2, second one is set to |"|1|2.
Definition at line 802 of file stopper.cpp.
void tesseract::Dict::reset_hyphen_vars | ( | bool | last_word_on_line | ) |
Unless the previous word was the last one on the line, and the current one is not (thus it is the first one on the line), erase hyphen_word_, clear hyphen_active_dawgs_, hyphen_constraints_ update last_word_on_line_.
Definition at line 32 of file hyphen.cpp.
|
inline |
void tesseract::Dict::set_hyphen_word | ( | const WERD_CHOICE & | word, |
const DawgInfoVector & | active_dawgs, | ||
const DawgInfoVector & | constraints | ||
) |
Update hyphen_word_, and copy the given DawgInfoVectors into hyphen_active_dawgs_ and hyphen_constraints_.
Definition at line 50 of file hyphen.cpp.
void tesseract::Dict::SettupStopperPass1 | ( | ) |
Sets up stopper variables in preparation for the first pass.
Definition at line 780 of file stopper.cpp.
void tesseract::Dict::SettupStopperPass2 | ( | ) |
Sets up stopper variables in preparation for the second pass.
Definition at line 784 of file stopper.cpp.
|
inline |
|
inline |
bool tesseract::Dict::StringSameAs | ( | const WERD_CHOICE & | WordChoice, |
VIABLE_CHOICE | ViableChoice | ||
) |
Compares unichar ids in word_choice to those in viable_choice, returns true if they are the same.
Definition at line 951 of file stopper.cpp.
bool tesseract::Dict::StringSameAs | ( | const char * | String, |
const char * | String_lengths, | ||
VIABLE_CHOICE | ViableChoice | ||
) |
Compares String to ViableChoice and returns true if they are the same.
Definition at line 967 of file stopper.cpp.
WERD_CHOICE * tesseract::Dict::top_fragments_permute_and_select | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
float | rating_limit | ||
) |
top_fragments_permute_and_select
Creates a copy of character choices list that contain only fragments and the best non-fragmented character choice. Permutes character in this shortened list, builds characters from fragments if possible and returns a better choice if found.
Definition at line 1367 of file permute.cpp.
char tesseract::Dict::top_word_chartype | ( | const BLOB_CHOICE_LIST_VECTOR & | char_choices, |
char * | pos_chartypes | ||
) |
Look up the main chartype for each character position and store it in the given array. Also returns the dominant type from unambiguous top choices.
Definition at line 512 of file permute.cpp.
int tesseract::Dict::UniformCertainties | ( | const BLOB_CHOICE_LIST_VECTOR & | Choices, |
const WERD_CHOICE & | BestChoice | ||
) |
Returns true if the certainty of the BestChoice word is within a reasonable range of the average certainties for the best choices for each character in the segmentation. This test is used to catch words in which one character is much worse than the other characters in the word (i.e. false will be returned in that case). The algorithm computes the mean and std deviation of the certainties in the word with the worst certainty thrown out.
Definition at line 986 of file stopper.cpp.
|
inline |
bool tesseract::Dict::valid_bigram | ( | const WERD_CHOICE & | word1, |
const WERD_CHOICE & | word2 | ||
) | const |
Definition at line 849 of file dict.cpp.
bool tesseract::Dict::valid_punctuation | ( | const WERD_CHOICE & | word | ) |
Returns true if the word contains a valid punctuation pattern. Note: Since the domains of punctuation symbols and symblos used in numbers are not disjoint, a valid number might contain an invalid punctuation pattern (e.g. .99).
Definition at line 879 of file dict.cpp.
int tesseract::Dict::valid_word | ( | const WERD_CHOICE & | word, |
bool | numbers_ok | ||
) | const |
Definition at line 807 of file dict.cpp.
|
inline |
|
inline |
This function is used by api/tesseract_cube_combiner.cpp.
|
inline |
|
inlinestatic |
|
static |
Writes the dawgs in the dawgs_vec to a file. Updates the given table with the indices of dawgs in the dawg_vec for the corresponding word lengths.
double tesseract::Dict::bestrate_pruning_factor = 2.0 |
double tesseract::Dict::certainty_scale = 20.0 |
int tesseract::Dict::dawg_debug_level = 0 |
double tesseract::Dict::doc_dict_certainty_threshold = -2.25 |
bool tesseract::Dict::doc_dict_enable = 1 |
double tesseract::Dict::doc_dict_pending_threshold = 0.0 |
int tesseract::Dict::fragments_debug = 0 |
void(Dict::* tesseract::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) |
int tesseract::Dict::hyphen_debug_level = 0 |
int(Dict::* tesseract::Dict::letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const |
bool tesseract::Dict::load_bigram_dawg = false |
bool tesseract::Dict::load_fixed_length_dawgs = true |
bool tesseract::Dict::load_freq_dawg = true |
bool tesseract::Dict::load_number_dawg = true |
bool tesseract::Dict::load_punc_dawg = true |
bool tesseract::Dict::load_system_dawg = true |
bool tesseract::Dict::load_unambig_dawg = true |
int tesseract::Dict::max_permuter_attempts = 10000 |
int tesseract::Dict::max_viterbi_list_size = 10 |
bool tesseract::Dict::ngram_permuter_activated = false |
char* tesseract::Dict::output_ambig_words_file = "" |
bool tesseract::Dict::permute_chartype_word = 0 |
bool tesseract::Dict::permute_debug = 0 |
bool tesseract::Dict::permute_fixed_length_dawg = 0 |
bool tesseract::Dict::permute_only_top = false |
bool tesseract::Dict::permute_script_word = 0 |
double(Dict::* tesseract::Dict::probability_in_context_)(const char *lang, const char *context, int context_bytes, const char *character, int character_bytes) |
bool tesseract::Dict::save_doc_words = 0 |
bool tesseract::Dict::save_raw_choices = false |
int tesseract::Dict::segment_debug = 0 |
bool tesseract::Dict::segment_nonalphabetic_script = false |
double tesseract::Dict::segment_penalty_dict_case_bad = 1.3125 |
double tesseract::Dict::segment_penalty_dict_case_ok = 1.1 |
double tesseract::Dict::segment_penalty_dict_frequent_word = 1.0 |
double tesseract::Dict::segment_penalty_dict_nonword = 1.25 |
double tesseract::Dict::segment_penalty_garbage = 1.50 |
double tesseract::Dict::segment_penalty_ngram_best_choice = 1.24 |
double tesseract::Dict::segment_reward_chartype = 0.97 |
double tesseract::Dict::segment_reward_ngram_best_choice = 0.99 |
double tesseract::Dict::segment_reward_script = 0.95 |
bool tesseract::Dict::segment_segcost_rating = 0 |
double tesseract::Dict::stopper_allowable_character_badness = 3.0 |
double tesseract::Dict::stopper_ambiguity_threshold_gain = 8.0 |
double tesseract::Dict::stopper_ambiguity_threshold_offset = 1.5 |
double tesseract::Dict::stopper_certainty_per_char = -0.50 |
int tesseract::Dict::stopper_debug_level = 0 |
bool tesseract::Dict::stopper_no_acceptable_choices = false |
double tesseract::Dict::stopper_nondict_certainty_base = -2.50 |
double tesseract::Dict::stopper_phase2_certainty_rejection_offset = 1.0 |
int tesseract::Dict::stopper_smallword_size = 2 |
int tesseract::Dict::tessedit_truncate_wordchoice_log = 10 |
bool tesseract::Dict::use_only_first_uft8_step = false |
char* tesseract::Dict::user_patterns_suffix = "" |
char* tesseract::Dict::user_words_suffix = "" |
char* tesseract::Dict::word_to_debug = "" |
char* tesseract::Dict::word_to_debug_lengths = "" |