tesseract::Dict Class Reference

#include <dict.h>

List of all members.

Public Member Functions

 Dict (Image *image_ptr)
 ~Dict ()
const ImagegetImage () const
ImagegetImage ()
const UNICHARSETgetUnicharset () const
UNICHARSETgetUnicharset ()
const UnicharAmbigsgetUnicharAmbigs ()
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_CHOICEdawg_permute_and_select (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
WERD_CHOICEget_top_choice_word (const BLOB_CHOICE_LIST_VECTOR &char_choices)
WERD_CHOICEpermute_top_choice (const BLOB_CHOICE_LIST_VECTOR &char_choices, float *rating_limit, WERD_CHOICE *raw_choice, BOOL8 *any_alpha)
WERD_CHOICEpermute_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_CHOICEpermute_compound_words (const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
WERD_CHOICEpermute_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_CHOICEpermute_script_words (const BLOB_CHOICE_LIST_VECTOR &char_choices, PermuterState *permuter_state)
WERD_CHOICEpermute_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)
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 DawgGetDawg (int index) const
 Return i-th dawg pointer recorded in the dawgs_ vector.
const DawgGetPuncDawg () const
 Return the points to the punctuation dawg.
const DawgGetUnambigDawg () const
 Return the points to the unambiguous words dawg.
const DawgGetFixedLengthDawg (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, bool debug)
void adjust_non_word (WERD_CHOICE *word, float *certainty_array, bool debug)
void SetWordsegRatingAdjustFactor (float f)
 Set wordseg_rating_adjust_factor_ to the given value.
const LISTgetBestChoices ()
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_CHOICEdawg_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.

Parameters:
first_char first choice
second_char second choice
third_char third choice
prev_char prev in word
next_char next in word
next_next_char after next next in word
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:

  • fragment: if not NULL contains information about immediately preceeding fragmented character choice
  • num_fragments: number of fragments that have been used so far to construct a character
  • certainty: certainty of the current choice or minimum certainty of all fragments concatenated so far
  • rating: rating of the current choice or sum of fragment ratings concatenated so far

The output char_frag_info is filled in as follows:

  • character: is set to be NULL if the choice is a non-matching or non-ending fragment piece; is set to unichar of the given choice if it represents a regular character or a matching ending fragment
  • fragment,num_fragments,certainty,rating are set as described above
Returns:
false if a non-matching fragment is discovered, true otherwise.
WERD_CHOICEtop_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.

Public Attributes

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 that will be modified by various permuters.
int(Dict::* letter_is_okay_ )(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) 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.
char * user_words_suffix = ""
char * user_patterns_suffix = ""
bool load_system_dawg = true
bool load_freq_dawg = true
bool load_unambig_dawg = true
bool load_punc_dawg = true
bool load_number_dawg = true
bool load_fixed_length_dawgs = true
bool load_bigram_dawg = false
double segment_penalty_dict_frequent_word = 1.0
double segment_penalty_dict_case_ok = 1.1
double segment_penalty_dict_case_bad = 1.3125
double segment_penalty_ngram_best_choice = 1.24
double segment_penalty_dict_nonword = 1.25
double segment_penalty_garbage = 1.50
char * output_ambig_words_file = ""
int dawg_debug_level = 0
int hyphen_debug_level = 0
int max_viterbi_list_size = 10
bool use_only_first_uft8_step = false
double certainty_scale = 20.0
double stopper_nondict_certainty_base = -2.50
double stopper_phase2_certainty_rejection_offset = 1.0
int stopper_smallword_size = 2
double stopper_certainty_per_char = -0.50
double stopper_allowable_character_badness = 3.0
int stopper_debug_level = 0
bool stopper_no_acceptable_choices = false
double stopper_ambiguity_threshold_gain = 8.0
double stopper_ambiguity_threshold_offset = 1.5
bool save_raw_choices = false
int tessedit_truncate_wordchoice_log = 10
char * word_to_debug = ""
char * word_to_debug_lengths = ""
int fragments_debug = 0
int segment_debug = 0
bool permute_debug = 0
double bestrate_pruning_factor = 2.0
bool permute_script_word = 0
bool segment_segcost_rating = 0
bool segment_nonalphabetic_script = false
double segment_reward_script = 0.95
bool permute_fixed_length_dawg = 0
bool permute_chartype_word = 0
double segment_reward_chartype = 0.97
double segment_reward_ngram_best_choice = 0.99
bool save_doc_words = 0
bool doc_dict_enable = 1
double doc_dict_pending_threshold = 0.0
double doc_dict_certainty_threshold = -2.25
bool ngram_permuter_activated = false
int max_permuter_attempts = 10000
bool permute_only_top = false

Constructor & Destructor Documentation

tesseract::Dict::Dict ( Image image_ptr  ) 
tesseract::Dict::~Dict (  ) 

Member Function Documentation

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).

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.

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.

void tesseract::Dict::add_document_word ( const WERD_CHOICE best_choice  ) 

Adds a word found on this document to the document specific dictionary.

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).

void tesseract::Dict::adjust_non_word ( WERD_CHOICE word,
float *  certainty_array,
bool  debug 
) [inline]
void tesseract::Dict::adjust_word ( WERD_CHOICE word,
float *  certainty_array,
bool  debug 
) [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.

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.

bool tesseract::Dict::ambigs_mode ( float  rating_limit  )  [inline]

Returns true if we are operating in ambigs mode.

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.

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.

bool tesseract::Dict::ChoiceAccumEnabled (  )  [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.

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 
)
void tesseract::Dict::ClearBestChoiceAccum (  ) 

Clears best_choices_ list accumulated by the stopper.

bool tesseract::Dict::compound_marker ( UNICHAR_ID  unichar_id  )  [inline]
bool tesseract::Dict::ConstraintsOk ( const DawgInfoVector constraints,
int  word_end,
DawgType  current_dawg_type 
) const [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).

void tesseract::Dict::copy_hyphen_info ( WERD_CHOICE word  )  const [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.

bool tesseract::Dict::CurrentBestChoiceIs ( const WERD_CHOICE WordChoice  ) 

Returns true if WordChoice is the same as the current best choice.

bool tesseract::Dict::CurrentWordAmbig (  ) 

Returns true if there are multiple good choices for the current word.

WERD_CHOICE* tesseract::Dict::dawg_permute_and_select ( const BLOB_CHOICE_LIST_VECTOR char_choices,
float  rating_limit 
) [inline]
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.

void tesseract::Dict::DebugWordChoices (  ) 

Prints the current choices for this word to stdout.

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:

  • next starting node is obtained from entry.ref and edge_char_of() is called to obtain the next edge
  • if a valid edge is found, the function returns the updated permuter code true and an entry [entry.dawg_index, edge] is inserted in dawg_args->updated_active_dawgs otherwise:
    • if we are dealing with dawg of type DAWG_TYPE_PUNCTUATION, edge_char_of() is called again, but now with kPatternUnicharID as unichar_id; if a valid edge is found it is recorded in dawg_args->updated_constraints
    • the function checks whether the word can end with the previous letter
    • each successor of the dawg (e.g. dawgs with type DAWG_TYPE_WORD could be successors to dawgs with type DAWG_TYPE_PUNCTUATION; the successors are defined by successors_ vector) is explored and if a letter is found in the successor dawg, a new entry is inserted into dawg_args->updated_active_dawgs with EDGE_REF being either NO_EDGE or an EDGE_REF recorded in constraints vector for the corresponding dawg index
double tesseract::Dict::def_probability_in_context ( const char *  lang,
const char *  context,
int  context_bytes,
const char *  character,
int  character_bytes 
) [inline]

Default (no-op) implementation of probability in context function.

void tesseract::Dict::DisableChoiceAccum (  )  [inline]
void tesseract::Dict::EnableChoiceAccum (  )  [inline]
void tesseract::Dict::End (  ) 
void tesseract::Dict::end_permute (  ) 
void tesseract::Dict::EndDangerousAmbigs (  ) 
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.

void tesseract::Dict::FilterWordChoices (  ) 

Removes from best_choices_ all choices which are not within a reasonable range of the best choice.

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.

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.

int tesseract::Dict::FreeBadChoice ( void *  item1,
void *  item2 
)
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.

int tesseract::Dict::get_top_word_script ( const BLOB_CHOICE_LIST_VECTOR char_choices,
const UNICHARSET unicharset 
)
const LIST& tesseract::Dict::getBestChoices (  )  [inline]
const Dawg* tesseract::Dict::GetDawg ( int  index  )  const [inline]

Return i-th dawg pointer recorded in the dawgs_ vector.

const Dawg* tesseract::Dict::GetFixedLengthDawg ( int  word_length  )  const [inline]

Return the pointer to the Dawg that contains words of length word_length.

Image* tesseract::Dict::getImage (  )  [inline]
const Image* tesseract::Dict::getImage (  )  const [inline]
const int tesseract::Dict::GetMaxFixedLengthDawgIndex (  )  const [inline]
const Dawg* tesseract::Dict::GetPuncDawg (  )  const [inline]

Return the points to the punctuation dawg.

static NODE_REF tesseract::Dict::GetStartingNode ( const Dawg dawg,
EDGE_REF  edge_ref 
) [inline, static]

Returns the appropriate next node given the EDGE_REF.

const Dawg* tesseract::Dict::GetUnambigDawg (  )  const [inline]

Return the points to the unambiguous words dawg.

const UnicharAmbigs& tesseract::Dict::getUnicharAmbigs (  )  [inline]
UNICHARSET& tesseract::Dict::getUnicharset (  )  [inline]
const UNICHARSET& tesseract::Dict::getUnicharset (  )  const [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

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.

int tesseract::Dict::good_choice ( const WERD_CHOICE choice  ) 

Returns true if a good answer is found for the unknown blob rating.

bool tesseract::Dict::has_hyphen_end ( const WERD_CHOICE word  )  const [inline]

Same as above, but check the unichar at the end of the word.

bool tesseract::Dict::has_hyphen_end ( UNICHAR_ID  unichar_id,
bool  first_pos 
) const [inline]

Check whether the word has a hyphen at the end.

int tesseract::Dict::hyphen_base_size (  )  const [inline]

Size of the base word (the part on the line before) of a hyphenated word.

bool tesseract::Dict::hyphenated (  )  const [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.

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.

void tesseract::Dict::init_constraints ( DawgInfoVector constraints  )  const

If hyphenated() returns true, copy the entries from hyphen_constraints_ into the given constraints vector.

void tesseract::Dict::InitChoiceAccum (  ) 

Initializes the data structures used to keep track the good word choices found for a word.

int tesseract::Dict::LengthOfShortestAlphaRun ( const WERD_CHOICE WordChoice  ) 

Returns the length of the shortest alpha run in WordChoice.

int tesseract::Dict::LetterIsOkay ( void *  void_dawg_args,
UNICHAR_ID  unichar_id,
bool  word_end 
) const [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.

void tesseract::Dict::LoadEquivalenceList ( const char *  unichar_strings[]  ) 
void tesseract::Dict::LogNewChoice ( FLOAT32  AdjustFactor,
const float  Certainties[],
bool  raw_choice,
WERD_CHOICE WordChoice 
)

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.

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.

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_.

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.

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 
)
UNICHAR_ID tesseract::Dict::NormalizeUnicharIdForMatch ( UNICHAR_ID  unichar_id  )  const
const int tesseract::Dict::NumDawgs (  )  const [inline]

Return the number of dawgs in the dawgs_ vector.

WERD_CHOICE * tesseract::Dict::permute_all ( const BLOB_CHOICE_LIST_VECTOR char_choices,
const WERD_CHOICE best_choice,
WERD_CHOICE raw_choice 
)
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.

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)

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.

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.

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.

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.

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.

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.

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.

void tesseract::Dict::PrintViableChoice ( FILE *  File,
const char *  Label,
VIABLE_CHOICE  Choice 
)

Dumps a text representation of the specified Choice to File.

double tesseract::Dict::ProbabilityInContext ( const char *  context,
int  context_bytes,
const char *  character,
int  character_bytes 
) [inline]

Calls probability_in_context_ member function.

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.

void tesseract::Dict::ReadFixedLengthDawgs ( DawgType  type,
const STRING lang,
PermuterType  perm,
int  debug_level,
FILE *  file,
DawgVector dawg_vec,
int *  max_wdlen 
) [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.

void tesseract::Dict::remove_hyphen_head ( WERD_CHOICE word  )  const [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.

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_.

void tesseract::Dict::ResetDocumentDictionary (  )  [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_.

void tesseract::Dict::SettupStopperPass1 (  ) 

Sets up stopper variables in preparation for the first pass.

void tesseract::Dict::SettupStopperPass2 (  ) 

Sets up stopper variables in preparation for the second pass.

void tesseract::Dict::SetWordsegRatingAdjustFactor ( float  f  )  [inline]

Set wordseg_rating_adjust_factor_ to the given value.

double tesseract::Dict::StopperAmbigThreshold ( double  f1,
double  f2 
) [inline]
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.

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.

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.

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.

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.

void tesseract::Dict::update_best_choice ( const WERD_CHOICE word,
WERD_CHOICE best_choice 
) [inline]

Copies word into best_choice if its rating is smaller than that of best_choice.

bool tesseract::Dict::valid_bigram ( const WERD_CHOICE word1,
const WERD_CHOICE word2 
) const
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).

int tesseract::Dict::valid_word ( const char *  string  )  const [inline]

This function is used by api/tesseract_cube_combiner.cpp.

int tesseract::Dict::valid_word ( const WERD_CHOICE word  )  const [inline]
int tesseract::Dict::valid_word ( const WERD_CHOICE word,
bool  numbers_ok 
) const
int tesseract::Dict::valid_word_or_number ( const WERD_CHOICE word  )  const [inline]
static bool tesseract::Dict::valid_word_permuter ( uinT8  perm,
bool  numbers_ok 
) [inline, static]

Check all the DAWGs to see if this word is in any of them.

void tesseract::Dict::WriteFixedLengthDawgs ( const GenericVector< SquishedDawg * > &  dawg_vec,
int  num_dawgs,
int  debug_level,
FILE *  output_file 
) [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.


Member Data Documentation

"Multiplying factor of" " current best rate to prune other hypotheses"

"Certainty scaling factor"

"Set to 1 for general debug info" ", to 2 for more details, to 3 to see all the debug messages"

"Worst certainty" " for words that can be inserted into the document dictionary"

"Enable Document Dictionary "

"Worst certainty for using pending dictionary"

"Debug character fragments"

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)

Pointer to go_deeper function that will be modified by various permuters.

"Debug level for hyphenated words."

int(Dict::* tesseract::Dict::letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const

"Load dawg with special word bigrams."

"Load fixed length" " dawgs (e.g. for non-space delimited languages)"

"Load frequent word dawg."

"Load dawg with number patterns."

"Load dawg with punctuation patterns."

"Load system word dawg."

"Load unambiguous word dawg."

"Maximum number of different" " character choices to consider during permutation." " This limit is especially useful when user patterns" " are specified, since overly generic patterns can result in" " dawg search exploring an overly large number of options."

"Maximum size of viterbi list."

"Activate character-level n-gram-based permuter"

"Output file for ambiguities found in the dictionary"

"Turn on character type (property) consistency permuter"

"Debug char permutation process"

"Turn on fixed-length phrasebook search permuter"

"Run only the top choice permuter"

"Turn on word script consistency permuter"

double(Dict::* tesseract::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.

"Save Document Words"

"Save all explored raw choices"

"Debug the whole segmentation process"

"Don't use any alphabetic-specific tricks." "Set to true in the traineddata config file for" " scripts that are cursive or inherently fixed-pitch"

"Default score multiplier for word matches, which may have " "case issues (lower is better)."

"Score multiplier for word matches that have good case " "(lower is better)."

"Score multiplier for word matches which have good case and" "are frequent in the given language (lower is better)."

"Score multiplier for glyph fragment segmentations which " "do not match a dictionary word (lower is better)."

"Score multiplier for poorly cased strings that are not in" " the dictionary and generally look like garbage (lower is" " better)."

"Multipler to for the best choice from the ngram model."

"Score multipler for char type consistency within a word. "

"Score multipler for ngram permuter's best choice" " (only used in the Han script path)."

"Score multipler for script consistency within a word. " "Being a 'reward' factor, it should be <= 1. " "Smaller value implies bigger reward."

"incorporate segmentation cost in word rating?"

"Max certaintly variation allowed in a word (in sigma)"

"Gain factor for ambiguity threshold."

"Certainty offset for ambiguity threshold."

"Certainty to add for each dict char above small word size."

"Stopper debug level"

"Make AcceptableChoice() always return false. Useful" " when there is a need to explore all segmentations"

"Certainty threshold for non-dict words"

"Reject certainty offset"

"Size of dict word to be treated as non-dict word"

"Max words to keep in list"

"Use only the first UTF8 step of the given string" " when computing log probabilities."

"A list of user-provided patterns."

Variable members. These have to be declared and initialized after image_ptr_, which contains the pointer to the params vector - the member of its base CCUtil class. "A list of user-provided words."

"Word for which stopper debug information" " should be printed to stdout"

"Lengths of unichars in word_to_debug"


The documentation for this class was generated from the following files:
Generated on Thu Feb 2 08:19:27 2012 for Tesseract by  doxygen 1.6.3