47 bool word_ending,
WERD_CHOICE *word,
float certainties[],
float *limit,
48 WERD_CHOICE *best_choice,
int *attempts_left,
void *void_more_args) {
49 auto *more_args =
static_cast<DawgArgs *
>(void_more_args);
50 word_ending = (char_choice_index == char_choices.
size()-1);
51 int word_index = word->
length() - 1;
52 if (best_choice->
rating() < *limit)
return;
58 bool checked_unigrams =
false;
61 tprintf(
"checking unigrams in an ngram %s\n",
71 bool unigrams_ok =
true;
75 DawgArgs unigram_dawg_args(&unigram_active_dawgs,
76 &unigram_updated_dawgs,
79 for (
int i = 0; unigrams_ok && i < encoding.
size(); ++i) {
87 word_ending && i == encoding.
size() - 1);
92 unigrams_ok ?
"OK" :
"not OK");
99 checked_unigrams =
true;
100 more_args->permuter = unigram_dawg_args.
permuter;
101 *(more_args->updated_dawgs) = *(unigram_dawg_args.
updated_dawgs);
116 if (output_ambig_words_file_ ==
nullptr) {
117 output_ambig_words_file_ =
119 if (output_ambig_words_file_ ==
nullptr) {
120 tprintf(
"Failed to open output_ambig_words_file %s\n",
127 fprintf(output_ambig_words_file_,
"%s", word_str.
string());
132 fprintf(output_ambig_words_file_,
"%s", word_str.
string());
140 ++(more_args->updated_dawgs);
142 ++(more_args->active_dawgs);
144 prev_char_frag_info, word, certainties, limit,
145 best_choice, attempts_left, more_args);
147 --(more_args->updated_dawgs);
148 --(more_args->active_dawgs);
152 tprintf(
"last unichar not OK at index %d in %s\n",
171 best_choice->make_bad();
172 best_choice->set_rating(rating_limit);
185 char_choices, 0,
nullptr, &word, certainties, &rating_limit, best_choice,
186 &attempts_left, &dawg_args);
187 delete[] active_dawgs;
200 int char_choice_index,
209 tprintf(
"%s permute_choices: char_choice_index=%d"
210 " limit=%g rating=%g, certainty=%g word=%s\n",
211 debug, char_choice_index, *limit, word->
rating(),
214 if (char_choice_index < char_choices.
length()) {
215 BLOB_CHOICE_IT blob_choice_it;
216 blob_choice_it.set_to_list(char_choices.
get(char_choice_index));
217 for (blob_choice_it.mark_cycle_pt(); !blob_choice_it.cycled_list();
218 blob_choice_it.forward()) {
221 char_choice_index, prev_char_frag_info, word,
222 certainties, limit, best_choice, attempts_left, more_args);
223 if (*attempts_left <= 0) {
224 if (debug)
tprintf(
"permute_choices(): attempts_left is 0\n");
243 int char_choice_index,
251 int word_ending = (char_choice_index == char_choices.
length() - 1);
256 blob_choice.
certainty(), prev_char_frag_info, debug,
257 word_ending, &char_frag_info)) {
261 if (char_frag_info.
unichar_id == INVALID_UNICHAR_ID) {
263 &char_frag_info, word, certainties, limit,
264 best_choice, attempts_left, more_args);
269 float old_rating = word->
rating();
271 uint8_t old_permuter = word->
permuter();
279 &char_frag_info, word_ending, word, certainties,
280 limit, best_choice, attempts_left, more_args);
315 float curr_rating,
float curr_certainty,
317 const char *debug,
int word_ending,
322 prev_char_frag_info !=
nullptr ? prev_char_frag_info->
fragment :
nullptr;
325 if (debug && (prev_fragment || this_fragment)) {
326 tprintf(
"%s check fragments: choice=%s word_ending=%d\n", debug,
338 char_frag_info->
fragment = this_fragment;
339 char_frag_info->
rating = curr_rating;
340 char_frag_info->
certainty = curr_certainty;
342 if (prev_fragment && !this_fragment) {
343 if (debug)
tprintf(
"Skip choice with incomplete fragment\n");
348 char_frag_info->
unichar_id = INVALID_UNICHAR_ID;
351 if (debug)
tprintf(
"Non-matching fragment piece\n");
359 tprintf(
"Built character %s from fragments\n",
364 if (debug)
tprintf(
"Record fragment continuation\n");
365 char_frag_info->
fragment = this_fragment;
369 prev_char_frag_info->
rating + curr_rating;
372 std::min(curr_certainty, prev_char_frag_info->
certainty);
375 if (debug)
tprintf(
"Record fragment beginning\n");
378 tprintf(
"Non-starting fragment piece with no prev_fragment\n");
384 if (word_ending && char_frag_info->
fragment) {
385 if (debug)
tprintf(
"Word can not end with a fragment\n");
DLLSYM void tprintf(const char *format,...)
UNICHAR_ID unichar_id() const
void set_certainty(float new_val)
const STRING debug_string() const
void remove_last_unichar_id()
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
UNICHAR_ID unichar_id(int index) const
void set_rating(float new_val)
const UNICHARSET * unicharset() const
void set_permuter(uint8_t perm)
void append_unichar_id(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, int blob_count, float rating, float certainty)
const char * string() const
bool is_beginning() const
bool is_continuation_of(const CHAR_FRAGMENT *fragment) const
static STRING to_string(const char *unichar, int pos, int total, bool natural)
const char * get_unichar() const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
bool get_isngram(UNICHAR_ID unichar_id) const
const char * id_to_unichar(UNICHAR_ID id) const
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
const CHAR_FRAGMENT * fragment
DawgPositionVector * updated_dawgs
DawgPositionVector * active_dawgs
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)
int(Dict::* letter_is_okay_)(void *void_dawg_args, const UNICHARSET &unicharset, UNICHAR_ID unichar_id, bool word_end) const
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.
int max_permuter_attempts
void update_best_choice(const WERD_CHOICE &word, WERD_CHOICE *best_choice)
WERD_CHOICE * dawg_permute_and_select(const BLOB_CHOICE_LIST_VECTOR &char_choices, float rating_limit)
char * output_ambig_words_file
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)
void init_active_dawgs(DawgPositionVector *active_dawgs, bool ambigs_mode) const
const UNICHARSET & getUnicharset() const
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)