46 bool word_ending,
WERD_CHOICE *word,
float certainties[],
float *limit,
47 WERD_CHOICE *best_choice,
int *attempts_left,
void *void_more_args) {
48 auto *more_args = static_cast<DawgArgs *>(void_more_args);
49 word_ending = (char_choice_index == char_choices.
size()-1);
50 int word_index = word->
length() - 1;
51 if (best_choice->
rating() < *limit)
return;
57 bool checked_unigrams =
false;
60 tprintf(
"checking unigrams in an ngram %s\n",
70 bool unigrams_ok =
true;
74 DawgArgs unigram_dawg_args(&unigram_active_dawgs,
75 &unigram_updated_dawgs,
78 for (
int i = 0; unigrams_ok && i < encoding.
size(); ++i) {
86 word_ending && i == encoding.
size() - 1);
91 unigrams_ok ?
"OK" :
"not OK");
98 checked_unigrams =
true;
99 more_args->permuter = unigram_dawg_args.
permuter;
100 *(more_args->updated_dawgs) = *(unigram_dawg_args.
updated_dawgs);
115 if (output_ambig_words_file_ ==
nullptr) {
116 output_ambig_words_file_ =
118 if (output_ambig_words_file_ ==
nullptr) {
119 tprintf(
"Failed to open output_ambig_words_file %s\n",
126 fprintf(output_ambig_words_file_,
"%s", word_str.
c_str());
131 fprintf(output_ambig_words_file_,
"%s", word_str.
c_str());
139 ++(more_args->updated_dawgs);
141 ++(more_args->active_dawgs);
143 prev_char_frag_info, word, certainties, limit,
144 best_choice, attempts_left, more_args);
146 --(more_args->updated_dawgs);
147 --(more_args->active_dawgs);
151 tprintf(
"last unichar not OK at index %d in %s\n",
175 new DawgPositionVector[char_choices.
size() + 1];
177 DawgArgs dawg_args(&(active_dawgs[0]), &(active_dawgs[1]),
NO_PERM);
184 char_choices, 0,
nullptr, &word, certainties, &rating_limit, best_choice,
185 &attempts_left, &dawg_args);
186 delete[] active_dawgs;
199 int char_choice_index,
208 tprintf(
"%s permute_choices: char_choice_index=%d"
209 " limit=%g rating=%g, certainty=%g word=%s\n",
210 debug, char_choice_index, *limit, word->
rating(),
213 if (char_choice_index < char_choices.
size()) {
214 BLOB_CHOICE_IT blob_choice_it;
215 blob_choice_it.set_to_list(char_choices.
get(char_choice_index));
216 for (blob_choice_it.mark_cycle_pt(); !blob_choice_it.cycled_list();
217 blob_choice_it.forward()) {
220 char_choice_index, prev_char_frag_info, word,
221 certainties, limit, best_choice, attempts_left, more_args);
222 if (*attempts_left <= 0) {
223 if (debug)
tprintf(
"permute_choices(): attempts_left is 0\n");
242 int char_choice_index,
250 int word_ending = (char_choice_index == char_choices.
size() - 1);
255 blob_choice.
certainty(), prev_char_frag_info, debug,
256 word_ending, &char_frag_info)) {
260 if (char_frag_info.
unichar_id == INVALID_UNICHAR_ID) {
262 &char_frag_info, word, certainties, limit,
263 best_choice, attempts_left, more_args);
268 float old_rating = word->
rating();
270 uint8_t old_permuter = word->
permuter();
278 &char_frag_info, word_ending, word, certainties,
279 limit, best_choice, attempts_left, more_args);
314 float curr_rating,
float curr_certainty,
316 const char *debug,
int word_ending,
321 prev_char_frag_info !=
nullptr ? prev_char_frag_info->
fragment :
nullptr;
324 if (debug && (prev_fragment || this_fragment)) {
325 tprintf(
"%s check fragments: choice=%s word_ending=%d\n", debug,
337 char_frag_info->
fragment = this_fragment;
338 char_frag_info->
rating = curr_rating;
339 char_frag_info->
certainty = curr_certainty;
341 if (prev_fragment && !this_fragment) {
342 if (debug)
tprintf(
"Skip choice with incomplete fragment\n");
347 char_frag_info->
unichar_id = INVALID_UNICHAR_ID;
350 if (debug)
tprintf(
"Non-matching fragment piece\n");
358 tprintf(
"Built character %s from fragments\n",
363 if (debug)
tprintf(
"Record fragment continuation\n");
364 char_frag_info->
fragment = this_fragment;
368 prev_char_frag_info->
rating + curr_rating;
371 std::min(curr_certainty, prev_char_frag_info->
certainty);
374 if (debug)
tprintf(
"Record fragment beginning\n");
377 tprintf(
"Non-starting fragment piece with no prev_fragment\n");
383 if (word_ending && char_frag_info->
fragment) {
384 if (debug)
tprintf(
"Word can not end with a fragment\n");