54 bool word_ending,
WERD_CHOICE *word,
float certainties[],
float *limit,
55 WERD_CHOICE *best_choice,
int *attempts_left,
void *void_more_args) {
57 word_ending = (char_choice_index == char_choices.
size()-1);
58 int word_index = word->
length() - 1;
59 if (best_choice->
rating() < *limit)
return;
65 bool checked_unigrams =
false;
68 tprintf(
"checking unigrams in an ngram %s\n",
78 bool unigrams_ok =
true;
82 DawgArgs unigram_dawg_args(&unigram_active_dawgs,
83 &unigram_updated_dawgs,
86 for (
int i = 0; unigrams_ok && i < encoding.
size(); ++i) {
94 word_ending && i == encoding.
size() - 1);
99 unigrams_ok ?
"OK" :
"not OK");
106 checked_unigrams =
true;
115 more_args, word->
unichar_id(word_index), word_ending)) {
122 if (output_ambig_words_file_ == NULL) {
123 output_ambig_words_file_ =
125 if (output_ambig_words_file_ == NULL) {
126 tprintf(
"Failed to open output_ambig_words_file %s\n",
133 fprintf(output_ambig_words_file_,
"%s", word_str.
string());
138 fprintf(output_ambig_words_file_,
"%s", word_str.
string());
150 prev_char_frag_info, word, certainties, limit,
151 best_choice, attempts_left, more_args);
158 tprintf(
"last unichar not OK at index %d in %s\n",
191 char_choices, 0, NULL, &word, certainties, &rating_limit, best_choice,
192 &attempts_left, &dawg_args);
193 delete[] active_dawgs;
206 int char_choice_index,
215 tprintf(
"%s permute_choices: char_choice_index=%d" 216 " limit=%g rating=%g, certainty=%g word=%s\n",
217 debug, char_choice_index, *limit, word->
rating(),
220 if (char_choice_index < char_choices.
length()) {
221 BLOB_CHOICE_IT blob_choice_it;
222 blob_choice_it.set_to_list(char_choices.
get(char_choice_index));
223 for (blob_choice_it.mark_cycle_pt(); !blob_choice_it.cycled_list();
224 blob_choice_it.forward()) {
227 char_choice_index, prev_char_frag_info, word,
228 certainties, limit, best_choice, attempts_left, more_args);
229 if (*attempts_left <= 0) {
230 if (debug)
tprintf(
"permute_choices(): attempts_left is 0\n");
249 int char_choice_index,
258 (char_choice_index == char_choices.
length() - 1) ?
true :
false;
263 blob_choice.
certainty(), prev_char_frag_info, debug,
264 word_ending, &char_frag_info)) {
268 if (char_frag_info.
unichar_id == INVALID_UNICHAR_ID) {
270 &char_frag_info, word, certainties, limit,
271 best_choice, attempts_left, more_args);
276 float old_rating = word->
rating();
286 &char_frag_info, word_ending, word, certainties,
287 limit, best_choice, attempts_left, more_args);
322 float curr_rating,
float curr_certainty,
324 const char *debug,
int word_ending,
329 prev_char_frag_info != NULL ? prev_char_frag_info->
fragment : NULL;
332 if (debug && (prev_fragment || this_fragment)) {
333 tprintf(
"%s check fragments: choice=%s word_ending=%d\n", debug,
345 char_frag_info->
fragment = this_fragment;
346 char_frag_info->
rating = curr_rating;
347 char_frag_info->
certainty = curr_certainty;
349 if (prev_fragment && !this_fragment) {
350 if (debug)
tprintf(
"Skip choice with incomplete fragment\n");
355 char_frag_info->
unichar_id = INVALID_UNICHAR_ID;
358 if (debug)
tprintf(
"Non-matching fragment piece\n");
366 tprintf(
"Built character %s from fragments\n",
371 if (debug)
tprintf(
"Record fragment continuation\n");
372 char_frag_info->
fragment = this_fragment;
376 prev_char_frag_info->
rating + curr_rating;
382 if (debug)
tprintf(
"Record fragment beginning\n");
385 tprintf(
"Non-starting fragment piece with no prev_fragment\n");
391 if (word_ending && char_frag_info->
fragment) {
392 if (debug)
tprintf(
"Word can not end with a fragment\n");
void go_deeper_dawg_fxn(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, bool word_ending, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *void_more_args)
int(Dict::* letter_is_okay_)(void *void_dawg_args, UNICHAR_ID unichar_id, bool word_end) const
char * output_ambig_words_file
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
DawgPositionVector * updated_dawgs
void set_rating(float new_val)
UNICHAR_ID unichar_id(int index) const
WERD_CHOICE * dawg_permute_and_select(const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
bool fragment_state_okay(UNICHAR_ID curr_unichar_id, float curr_rating, float curr_certainty, const CHAR_FRAGMENT_INFO *prev_char_frag_info, const char *debug, int word_ending, CHAR_FRAGMENT_INFO *char_frag_info)
void set_permuter(uinT8 perm)
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)
const UNICHARSET & getUnicharset() const
void update_best_choice(const WERD_CHOICE &word, WERD_CHOICE *best_choice)
int max_permuter_attempts
bool is_continuation_of(const CHAR_FRAGMENT *fragment) const
UNICHAR_ID unichar_id() const
const CHAR_FRAGMENT * fragment
const char * string() const
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
void make_bad()
Set the fields in this choice to be default (bad) values.
void remove_last_unichar_id()
void set_certainty(float new_val)
const char * get_unichar() const
static STRING to_string(const char *unichar, int pos, int total, bool natural)
UNICHAR_ID TESS_API unichar_to_id(const char *const unichar_repr) const
DawgPositionVector * active_dawgs
void(Dict::* go_deeper_fxn_)(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, bool word_ending, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *void_more_args)
Pointer to go_deeper function.
bool is_beginning() const
void permute_choices(const char *debug, const BLOB_CHOICE_LIST_VECTOR &char_choices, int char_choice_index, const CHAR_FRAGMENT_INFO *prev_char_frag_info, WERD_CHOICE *word, float certainties[], float *limit, WERD_CHOICE *best_choice, int *attempts_left, void *more_args)
const char * id_to_unichar(UNICHAR_ID id) const
const STRING debug_string() const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
void append_unichar_id(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)