/** * copy_choices * * Copy a list of choices. This means that there will be two copies * in memory. */ CHOICES copy_choices(CHOICES choices) { CHOICES l; CHOICES result = NIL; iterate_list(l, choices) { A_CHOICE *choice = (A_CHOICE *)(first_node(l)); result = push (result, (LIST) new_choice (class_string(choice), class_lengths(choice), class_rating(choice), class_certainty(choice), class_config(choice), class_script_id(choice), class_permuter(choice), class_fragment_mark(choice), class_fragment_lengths(choice))); }
/********************************************************************** * save_answer * * Write an answer to the output file that is the raw guess (without * context) directly from the classifier. **********************************************************************/ void save_answer(TWERD *word, TEXTROW *row, A_CHOICE *best_choice, A_CHOICE *raw_choice, int firstpass) { static TEXTROW *last_row; char raw_answer[CHARS_PER_LINE]; int answer_already; int good_answer; char *string = NULL; if (best_choice) { good_answer = AcceptableResult (best_choice, raw_choice); string = class_string (best_choice); } else { good_answer = FALSE; } if (firstpass) { /* First pass */ if (string) { /* Got answer */ add_document_word(best_choice); word->guess = string; fix_quotes (word->guess); strcpy (raw_answer, word->guess); record_certainty (class_certainty (best_choice), 1); if (good_answer) { record_certainty (class_certainty (best_choice), 2); strcat (raw_answer, " "); strcat (raw_answer, class_string (raw_choice)); word->guess = strsave (raw_answer); word->guess[strlen (string)] = 0; if (string) { strfree(string); class_string (best_choice) = NULL; } } else { /* Not good enough */ if (word->guess) strfree (word->guess); word->guess = NULL; } } else { word->guess = NULL; raw_answer[0] = '\0'; } } else { /* Second pass */ answer_already = (word->guess != NULL); if (answer_already) { write_text_files (word, &word->guess[strlen (word->guess) + 1], (row != last_row), TRUE, TRUE); } else { /* Required second pass */ if (string) { if (!good_answer && tessedit_save_stats) { SaveBadWord (string, class_certainty (best_choice)); } record_certainty (class_certainty (best_choice), 2); word->guess = class_string (best_choice); fix_quotes (word->guess); write_text_files (word, class_string (raw_choice), (row != last_row), good_answer, FALSE); } } } /* Word Display */ if (display_text) { if (row != last_row) cprintf ("\n"); if (word->guess && strlen (word->guess)) cprintf ("%s ", word->guess); else cprintf ("%s ", raw_answer); fflush(stdout); } last_row = row; }