ccmain/tessbox.cpp

Go to the documentation of this file.
00001 
00020 #include "mfcpch.h"
00021 #include          "tfacep.h"
00022 #include          "tfacepp.h"
00023 #include          "tessbox.h"
00024 #include "mfoutline.h"
00025 
00026 #define EXTERN
00027 
00041 WERD_CHOICE *tess_segment_pass1(
00042                                 WERD *word,
00043                                 DENORM *denorm,
00044                                 POLY_MATCHER matcher,
00045                                 WERD_CHOICE *&raw_choice,
00046                                 BLOB_CHOICE_LIST_CLIST *blob_choices,
00047                                 WERD *&outword
00048                                ) {
00049   WERD_CHOICE *result;           // return value
00050   int saved_enable_assoc = 0;
00051   int saved_chop_enable = 0;
00052 
00053   if (word->flag (W_DONT_CHOP)) {
00054     saved_enable_assoc = enable_assoc;
00055     saved_chop_enable = chop_enable;
00056     enable_assoc = 0;
00057     chop_enable = 0;
00058     if (word->flag (W_REP_CHAR))
00059       permute_only_top = 1;
00060   }
00061   set_pass1(); 
00062   //      tprintf("pass1 chop on=%d, seg=%d, onlytop=%d",chop_enable,enable_assoc,permute_only_top);
00063   result = recog_word (word, denorm, matcher, NULL, NULL, FALSE,
00064     raw_choice, blob_choices, outword);
00065   if (word->flag (W_DONT_CHOP)) {
00066     enable_assoc = saved_enable_assoc;
00067     chop_enable = saved_chop_enable;
00068     permute_only_top = 0;
00069   }
00070   return result;
00071 }
00072 
00073 
00087 WERD_CHOICE *tess_segment_pass2(
00088                                 WERD *word,
00089                                 DENORM *denorm,
00090                                 POLY_MATCHER matcher,
00091                                 WERD_CHOICE *&raw_choice,
00092                                 BLOB_CHOICE_LIST_CLIST *blob_choices,
00093                                 WERD *&outword
00094                                ) {
00095   WERD_CHOICE *result;           // return value
00096   int saved_enable_assoc = 0;
00097   int saved_chop_enable = 0;
00098 
00099   if (word->flag (W_DONT_CHOP)) {
00100     saved_enable_assoc = enable_assoc;
00101     saved_chop_enable = chop_enable;
00102     enable_assoc = 0;
00103     chop_enable = 0;
00104     if (word->flag (W_REP_CHAR))
00105       permute_only_top = 1;
00106   }
00107   set_pass2(); 
00108   result = recog_word (word, denorm, matcher, NULL, NULL, FALSE,
00109     raw_choice, blob_choices, outword);
00110   if (word->flag (W_DONT_CHOP)) {
00111     enable_assoc = saved_enable_assoc;
00112     chop_enable = saved_chop_enable;
00113     permute_only_top = 0;
00114   }
00115   return result;
00116 }
00117 
00118 
00136 WERD_CHOICE *correct_segment_pass2(
00137                                    WERD *word,
00138                                    DENORM *denorm,
00139                                    POLY_MATCHER matcher,
00140                                    POLY_TESTER tester,
00141                                    WERD_CHOICE *&raw_choice,
00142                                    BLOB_CHOICE_LIST_CLIST *blob_choices,
00143                                    WERD *&outword
00144                                   ) {
00145   set_pass2(); 
00146   return recog_word (word, denorm, matcher, NULL, tester, TRUE,
00147     raw_choice, blob_choices, outword);
00148 }
00149 
00150 
00165 WERD_CHOICE *test_segment_pass2(
00166                                 WERD *word,
00167                                 DENORM *denorm,
00168                                 POLY_MATCHER matcher,
00169                                 POLY_TESTER tester,
00170                                 WERD_CHOICE *&raw_choice,
00171                                 BLOB_CHOICE_LIST_CLIST *blob_choices,
00172                                 WERD *&outword
00173                                ) {
00174   set_pass2(); 
00175   return recog_word (word, denorm, matcher, tester, NULL, TRUE,
00176     raw_choice, blob_choices, outword);
00177 }
00178 
00179 
00187 BOOL8 tess_acceptable_word(
00188                            WERD_CHOICE *word_choice,
00189                            WERD_CHOICE *raw_choice
00190                           ) {
00191   A_CHOICE choice;               // after context
00192   A_CHOICE tess_raw;             // before
00193 
00194   choice.rating = word_choice->rating ();
00195   choice.certainty = word_choice->certainty ();
00196   choice.string = (char *) word_choice->string ().string ();
00197   tess_raw.rating = raw_choice->rating ();
00198   tess_raw.certainty = raw_choice->certainty ();
00199   tess_raw.string = (char *) raw_choice->string ().string ();
00200   return AcceptableResult (&choice, &tess_raw); // call tess
00201 }
00202 
00203 
00207 BOOL8 tess_adaptable_word(                           //test adaptability
00208                           WERD *word,                //word to test
00209                           WERD_CHOICE *word_choice,  //after context
00210                           WERD_CHOICE *raw_choice    //before context
00211                          ) {
00212   TWERD *tessword;               //converted word
00213   INT32 result;                  //answer
00214 
00215   tessword = make_tess_word (word, NULL);
00216   result = AdaptableWord (tessword, word_choice->string ().string (),
00217     raw_choice->string ().string ());
00218   delete_word(tessword);
00219   return result != 0;
00220 }
00221 
00222 
00234 void tess_cn_matcher(
00235                      PBLOB *pblob,
00236                      PBLOB *blob,
00237                      PBLOB *nblob,
00238                      WERD *word,
00239                      DENORM *denorm,
00240                      BLOB_CHOICE_LIST &ratings
00241                     ) {
00242   LIST result;                   // tess output
00243   TBLOB *tessblob;               // converted blob
00244   TEXTROW tessrow;               // dummy row
00245 
00246   tess_cn_matching = TRUE;       //turn it on
00247   tess_bn_matching = FALSE;
00248   tessblob = make_tess_blob (blob, TRUE); // convert blob
00249   make_tess_row(denorm, &tessrow); // make dummy row
00250   result = AdaptiveClassifier (tessblob, NULL, &tessrow); // classify
00251   free_blob(tessblob); 
00252   convert_choice_list(result, ratings); // make our format
00253 }
00254 
00255 
00267 void tess_bn_matcher(
00268                      PBLOB *pblob,
00269                      PBLOB *blob,
00270                      PBLOB *nblob,
00271                      WERD *word,
00272                      DENORM *denorm,
00273                      BLOB_CHOICE_LIST &ratings
00274                     ) {
00275   LIST result;                   // tess output
00276   TBLOB *tessblob;               // converted blob
00277   TEXTROW tessrow;               // dummy row
00278 
00279   tess_bn_matching = TRUE;       // turn it on
00280   tess_cn_matching = FALSE;
00281   tessblob = make_tess_blob (blob, TRUE); // convert blob
00282   make_tess_row(denorm, &tessrow); // make dummy row
00283   result = AdaptiveClassifier (tessblob, NULL, &tessrow); // classify
00284   free_blob(tessblob); 
00285   convert_choice_list(result, ratings); // make our format
00286 }
00287 
00288 
00300 void tess_default_matcher(
00301                           PBLOB *pblob,
00302                           PBLOB *blob,
00303                           PBLOB *nblob,
00304                           WERD *word,
00305                           DENORM *denorm,
00306                           BLOB_CHOICE_LIST &ratings
00307                          ) {
00308   LIST result;                   // tess output
00309   TBLOB *tessblob;               // converted blob
00310   TEXTROW tessrow;               // dummy row
00311 
00312   tess_bn_matching = FALSE;      // turn it off
00313   tess_cn_matching = FALSE;
00314   tessblob = make_tess_blob (blob, TRUE); // convert blob
00315   make_tess_row(denorm, &tessrow); // make dummy row
00316   result = AdaptiveClassifier (tessblob, NULL, &tessrow); // classify
00317   free_blob(tessblob); 
00318   convert_choice_list(result, ratings); // make our format
00319 }
00320 
00321 
00335 void tess_training_tester(
00336                           PBLOB *blob,
00337                           DENORM *denorm,
00338                           BOOL8 correct,
00339                           char *text,
00340                           INT32 count,
00341                           BLOB_CHOICE_LIST *ratings
00342                          ) {
00343   TBLOB *tessblob;               // converted blob
00344   TEXTROW tessrow;               // dummy row
00345 
00346   if (correct) {
00347     NormMethod = character;      // Force char norm spc 30/11/93
00348     tess_bn_matching = FALSE;    // turn it off
00349     tess_cn_matching = FALSE;
00350     tessblob = make_tess_blob (blob, TRUE); // convert blob
00351     make_tess_row(denorm, &tessrow); // make dummy row
00352     LearnBlob(tessblob, &tessrow, text, count); // learn it
00353     free_blob(tessblob); 
00354   }
00355 }
00356 
00357 
00368 void tess_adapter(
00369                   WERD *word,
00370                   DENORM *denorm,
00371                   const char *string,
00372                   const char *raw_string,
00373                   const char *rejmap
00374                  ) {
00375   TWERD *tessword;               // converted word
00376   static TEXTROW tessrow;        // dummy row
00377 
00378   make_tess_row(denorm, &tessrow); // make dummy row
00379   tessword = make_tess_word (word, &tessrow); // make a word
00380   AdaptToWord(tessword, &tessrow, string, raw_string, rejmap); // adapt to it
00381   delete_word(tessword);  // free it
00382 }
00383 
00384 
00391 void tess_add_doc_word(
00392                        WERD_CHOICE *word_choice
00393                       ) {
00394   A_CHOICE choice;               // after context
00395 
00396   choice.rating = word_choice->rating ();
00397   choice.certainty = word_choice->certainty ();
00398   choice.string = (char *) word_choice->string ().string ();
00399   add_document_word(&choice);
00400 }

Generated on Wed Feb 28 19:49:07 2007 for Tesseract by  doxygen 1.5.1