Tesseract  3.02
tesseract-ocr/ccstruct/ratngs.h File Reference
#include <assert.h>
#include "clst.h"
#include "genericvector.h"
#include "notdll.h"
#include "unichar.h"
#include "unicharset.h"
#include "werd.h"

Go to the source code of this file.

Classes

class  BLOB_CHOICE
class  WERD_CHOICE

Typedefs

typedef GenericVector
< BLOB_CHOICE_LIST * > 
BLOB_CHOICE_LIST_VECTOR
typedef GenericVector
< WERD_CHOICE_LIST * > 
WERD_CHOICE_LIST_VECTOR

Functions

 ELISTIZEH (BLOB_CHOICE) CLISTIZEH(BLOB_CHOICE_LIST) enum PermuterType
bool EqualIgnoringCaseAndTerminalPunct (const WERD_CHOICE &word1, const WERD_CHOICE &word2)
void print_ratings_list (const char *msg, BLOB_CHOICE_LIST *ratings)
void print_ratings_list (const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET &current_unicharset)
void print_ratings_info (FILE *fp, BLOB_CHOICE_LIST *ratings, const UNICHARSET &current_unicharset)
void print_char_choices_list (const char *msg, const BLOB_CHOICE_LIST_VECTOR &char_choices, const UNICHARSET &current_unicharset, BOOL8 detailed)
void print_word_alternates_list (WERD_CHOICE *word, GenericVector< WERD_CHOICE * > *alternates)

Typedef Documentation

typedef GenericVector<BLOB_CHOICE_LIST *> BLOB_CHOICE_LIST_VECTOR

Definition at line 438 of file ratngs.h.

typedef GenericVector<WERD_CHOICE_LIST *> WERD_CHOICE_LIST_VECTOR

Definition at line 439 of file ratngs.h.


Function Documentation

ELISTIZEH ( BLOB_CHOICE  )

Definition at line 158 of file ratngs.h.

                  {
  NO_PERM,            // 0
  PUNC_PERM,          // 1
  TOP_CHOICE_PERM,    // 2
  LOWER_CASE_PERM,    // 3
  UPPER_CASE_PERM,    // 4
  NGRAM_PERM,         // 5
  NUMBER_PERM,        // 6
  USER_PATTERN_PERM,  // 7
  SYSTEM_DAWG_PERM,   // 8
  DOC_DAWG_PERM,      // 9
  USER_DAWG_PERM,     // 10
  FREQ_DAWG_PERM,     // 11
  COMPOUND_PERM,      // 12
};
bool EqualIgnoringCaseAndTerminalPunct ( const WERD_CHOICE word1,
const WERD_CHOICE word2 
)

Definition at line 483 of file ratngs.cpp.

                                                                 {
  const UNICHARSET *uchset = word1.unicharset();
  if (word2.unicharset() != uchset) return false;
  int w1start, w1end;
  word1.punct_stripped(&w1start, &w1end);
  int w2start, w2end;
  word2.punct_stripped(&w2start, &w2end);
  if (w1end - w1start != w2end - w2start) return false;
  for (int i = 0; i < w1end - w1start; i++) {
    if (uchset->to_lower(word1.unichar_id(w1start + i)) !=
        uchset->to_lower(word2.unichar_id(w2start + i))) {
        return false;
    }
  }
  return true;
}
void print_char_choices_list ( const char *  msg,
const BLOB_CHOICE_LIST_VECTOR char_choices,
const UNICHARSET current_unicharset,
BOOL8  detailed 
)

print_char_choices_list

Definition at line 610 of file ratngs.cpp.

                                             {
  if (*msg != '\0') tprintf("%s\n", msg);
  for (int x = 0; x < char_choices.length(); ++x) {
    BLOB_CHOICE_IT c_it;
    c_it.set_to_list(char_choices.get(x));
    tprintf("\nchar[%d]: %s\n", x,
            current_unicharset.debug_str( c_it.data()->unichar_id()).string());
    if (detailed)
      print_ratings_list("", char_choices.get(x), current_unicharset);
  }
}
void print_ratings_info ( FILE *  fp,
BLOB_CHOICE_LIST *  ratings,
const UNICHARSET current_unicharset 
)

print_ratings_info

Send all the ratings out to the logfile.

Parameters:
fpfile to use
ratingslist of results
current_unicharsetunicharset that can be used for id-to-unichar conversion

Definition at line 564 of file ratngs.cpp.

                                                              {
  inT32 index;                    // to list
  const char* first_char = NULL;  // character
  FLOAT32 first_rat;              // rating
  FLOAT32 first_cert;             // certainty
  const char* sec_char = NULL;    // character
  FLOAT32 sec_rat = 0.0f;         // rating
  FLOAT32 sec_cert = 0.0f;        // certainty
  BLOB_CHOICE_IT c_it = ratings;  // iterator

  index = ratings->length();
  if (index > 0) {
    first_char = current_unicharset.id_to_unichar(c_it.data()->unichar_id());
    first_rat = c_it.data()->rating();
    first_cert = -c_it.data()->certainty();
    if (index > 1) {
      sec_char = current_unicharset.id_to_unichar(
          c_it.data_relative(1)->unichar_id());
      sec_rat = c_it.data_relative(1)->rating();
      sec_cert = -c_it.data_relative(1)->certainty();
    } else {
      sec_char = NULL;
      sec_rat = -1;
      sec_cert = -1;
    }
  } else {
    first_char = NULL;
    first_rat = -1;
    first_cert = -1;
  }
  if (first_char != NULL && (*first_char == '\0' || *first_char == ' '))
    first_char = NULL;
  if (sec_char != NULL && (*sec_char == '\0' || *sec_char == ' '))
    sec_char = NULL;
  tprintf(" " INT32FORMAT " %s %g %g %s %g %g\n",
          ratings->length(),
          first_char != NULL ? first_char : "~",
          first_rat, first_cert, sec_char != NULL ? sec_char : "~",
          sec_rat, sec_cert);
}
void print_ratings_list ( const char *  msg,
BLOB_CHOICE_LIST *  ratings 
)

print_ratings_list

Print ratings list (unichar ids only).

Definition at line 536 of file ratngs.cpp.

                                                                    {
  if (ratings->length() == 0) {
    tprintf("%s:<none>\n", msg);
    return;
  }
  if (*msg != '\0') {
    tprintf("%s\n", msg);
  }
  BLOB_CHOICE_IT c_it;
  c_it.set_to_list(ratings);
  for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
    c_it.data()->print(NULL);
    if (!c_it.at_last()) tprintf("\n");
  }
  tprintf("\n");
  fflush(stdout);
}
void print_ratings_list ( const char *  msg,
BLOB_CHOICE_LIST *  ratings,
const UNICHARSET current_unicharset 
)

print_ratings_list

Send all the ratings out to the logfile.

Parameters:
msgintro message
ratingslist of ratings
current_unicharsetunicharset that can be used for id-to-unichar conversion

Definition at line 511 of file ratngs.cpp.

                                                              {
  if (ratings->length() == 0) {
    tprintf("%s:<none>\n", msg);
    return;
  }
  if (*msg != '\0') {
    tprintf("%s\n", msg);
  }
  BLOB_CHOICE_IT c_it;
  c_it.set_to_list(ratings);
  for (c_it.mark_cycle_pt(); !c_it.cycled_list(); c_it.forward()) {
    c_it.data()->print(&current_unicharset);
    if (!c_it.at_last()) tprintf("\n");
  }
  tprintf("\n");
  fflush(stdout);
}
void print_word_alternates_list ( WERD_CHOICE word,
GenericVector< WERD_CHOICE * > *  alternates 
)

print_word_alternates_list

Definition at line 628 of file ratngs.cpp.

                                              {
  if (!word || !alternates) return;

  STRING alternates_str;
  for (int i = 0; i < alternates->size(); i++) {
    if (i > 0) alternates_str += "\", \"";
    alternates_str += alternates->get(i)->unichar_string();
  }
  tprintf("Alternates for \"%s\": {\"%s\"}\n",
          word->unichar_string().string(), alternates_str.string());
}