00001
00019 #include "tface.h"
00020 #include "danerror.h"
00021 #include "globals.h"
00022 #include "tordvars.h"
00023 #include "fxid.h"
00024 #include "wordclass.h"
00025 #include "bestfirst.h"
00026 #include "context.h"
00027 #include "gradechop.h"
00028 #include "hyphen.h"
00029
00030 #include "msmenus.h"
00031 #include "djmenus.h"
00032 #include "tessinit.h"
00033 #include "mfvars.h"
00034 #include "variables.h"
00035 #include "metrics.h"
00036 #include "adaptmatch.h"
00037 #include "matchtab.h"
00038 #include "chopper.h"
00039 #include "permdawg.h"
00040 #include "permute.h"
00041 #include "chop.h"
00042 #include "callcpp.h"
00043 #include "badwords.h"
00044
00045 #include <math.h>
00046 #ifdef __UNIX__
00047 #include <unistd.h>
00048 #endif
00049
00050
00051
00052
00053
00054 static PRIORITY pass2_ok_split;
00055 static int pass2_seg_states;
00056 extern int NO_BLOCK;
00057
00058
00059
00060
00064 int start_recog(const char *configfile, const char *textbase) {
00065
00066 program_editup(configfile);
00067 program_editup2(textbase);
00068 return (0);
00069 }
00070
00071
00072
00076 void program_editup(const char *configfile) {
00077 init_ms_debug();
00078 init_dj_debug();
00079
00080 program_variables();
00081 mfeature_variables();
00082
00083 if (configfile != NULL) {
00084
00085
00086 read_variables(configfile);
00087 }
00088
00089 program_init();
00090 mfeature_init();
00091 setup_cp_maps();
00092 }
00093
00094
00095
00099 void program_editup2(const char *textbase) {
00100 if (textbase != NULL) {
00101 strcpy(imagefile, textbase);
00102
00103 edit_with_ocr(textbase);
00104 }
00105
00106 init_metrics();
00107 pass2_ok_split = ok_split;
00108 pass2_seg_states = num_seg_states;
00109 reset_width_tally();
00110 }
00111
00112
00113
00118 void edit_with_ocr(const char *imagename) {
00119 char name[FILENAMESIZE];
00120
00121 if (write_output) {
00122 strcpy(name, imagename);
00123 strcat (name, ".txt");
00124
00125 textfile = open_file (name, "w");
00126 }
00127 if (write_raw_output) {
00128 strcpy(name, imagename);
00129 strcat (name, ".raw");
00130 rawfile = open_file (name, "w");
00131 }
00132 if (record_matcher_output) {
00133 strcpy(name, imagename);
00134 strcat (name, ".mlg");
00135 matcher_fp = open_file (name, "w");
00136 strcpy(name, imagename);
00137 strcat (name, ".ctx");
00138 correct_fp = open_file (name, "r");
00139 }
00140 }
00141
00142
00143
00147 int end_recog() {
00148 program_editdown (0);
00149
00150 return (0);
00151 }
00152
00153
00154
00158 void program_editdown(INT32 elasped_time) {
00159 dj_cleanup();
00160 if (display_text)
00161 cprintf ("\n");
00162 if (!NO_BLOCK && write_output)
00163 fprintf (textfile, "\n");
00164 if (write_raw_output)
00165 fprintf (rawfile, "\n");
00166 if (write_output) {
00167 #ifdef __UNIX__
00168 fsync (fileno (textfile));
00169 #endif
00170 fclose(textfile);
00171 }
00172 if (write_raw_output) {
00173 #ifdef __UNIX__
00174 fsync (fileno (rawfile));
00175 #endif
00176 fclose(rawfile);
00177 }
00178 close_choices();
00179 if (tessedit_save_stats)
00180 save_summary (elasped_time);
00181 end_match_table();
00182 InitChoiceAccum();
00183 if (global_hash != NULL) {
00184 free_mem(global_hash);
00185 global_hash = NULL;
00186 }
00187 end_metrics();
00188 end_permute();
00189 end_permdawg();
00190 free_variables();
00191 }
00192
00193
00194
00198 void set_pass1() {
00199 blob_skip = FALSE;
00200 ok_split = 70.0;
00201 num_seg_states = 15;
00202 SettupPass1();
00203 first_pass = 1;
00204 }
00205
00206
00207
00211 void set_pass2() {
00212 blob_skip = FALSE;
00213 ok_split = pass2_ok_split;
00214 num_seg_states = pass2_seg_states;
00215 SettupPass2();
00216 first_pass = 0;
00217 }
00218
00219
00220
00224 CHOICES_LIST cc_recog(TWERD *tessword,
00225 A_CHOICE *best_choice,
00226 A_CHOICE *best_raw_choice,
00227 BOOL8 tester,
00228 BOOL8 trainer) {
00229 int fx;
00230 CHOICES_LIST results;
00231
00232 if (SetErrorTrap (NULL)) {
00233 cprintf ("Tess copped out!\n");
00234 ReleaseErrorTrap();
00235 class_string (best_choice) = NULL;
00236 return NULL;
00237 }
00238 InitChoiceAccum();
00239 init_match_table();
00240 for (fx = 0; fx < MAX_FX && (acts[OCR] & (FXSELECT << fx)) == 0; fx++);
00241 results =
00242 chop_word_main(tessword,
00243 fx,
00244 best_choice,
00245 best_raw_choice,
00246 tester,
00247 trainer);
00248 DebugWordChoices();
00249 reset_hyphen_word();
00250 ReleaseErrorTrap();
00251 return results;
00252 }
00253
00254
00255
00260 int dict_word(const char *word) {
00261
00262 if (test_freq_words (word))
00263 return FREQ_DAWG_PERM;
00264 else
00265 return valid_word (word);
00266 }