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");