Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::PermuterState Class Reference

#include <permute.h>

Public Member Functions

 PermuterState ()
 
void Init (const BLOB_CHOICE_LIST_VECTOR &char_choices, const UNICHARSET &unicharset, float default_bias, bool debug)
 
void AddPreference (int start_pos, char *pos_str, float weight)
 
void AddPreference (int char_pos, BLOB_CHOICE *blob_choice, float weight)
 
WERD_CHOICEGetPermutedWord (float *certainties, float *adjust_factor)
 
void set_allow_collision (bool flag)
 
void set_adjust_factor (float factor)
 
void set_debug (bool debug)
 
bool position_marked (int pos)
 

Detailed Description

Definition at line 113 of file permute.h.

Constructor & Destructor Documentation

tesseract::PermuterState::PermuterState ( )

Definition at line 231 of file permute.cpp.

231  {
232  unicharset_ = NULL;
233  char_choices_ = NULL;
234  adjust_factor_ = 1.0f;
235  allow_collision_ = false;
236  word_length_ = 0;
237  debug_ = false;
238 }
#define NULL
Definition: host.h:144

Member Function Documentation

void tesseract::PermuterState::AddPreference ( int  start_pos,
char *  pos_str,
float  weight 
)

Definition at line 266 of file permute.cpp.

266  {
267  ASSERT_HOST(char_choices_ != NULL);
268  ASSERT_HOST(start_pos + strlen(pos_str) - 1 < word_length_);
269  if (debug_) {
270  tprintf("Copy over %s -> %s @ %d ", pos_str, perm_state_, start_pos);
271  }
272  // copy over preferred position without the terminating null
273  if (!allow_collision_) {
274  int len = strlen(pos_str);
275  for (int i = 0; i < len; ++i)
276  if (position_marked(start_pos + i)) return;
277  }
278  strncpy(&perm_state_[start_pos], pos_str, strlen(pos_str));
279  adjust_factor_ *= weight;
280  if (debug_) tprintf("==> %s %f\n", perm_state_, adjust_factor_);
281 }
#define NULL
Definition: host.h:144
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
bool position_marked(int pos)
Definition: permute.h:131
#define ASSERT_HOST(x)
Definition: errcode.h:84
void tesseract::PermuterState::AddPreference ( int  char_pos,
BLOB_CHOICE blob_choice,
float  weight 
)

Definition at line 284 of file permute.cpp.

285  {
286  ASSERT_HOST(char_choices_ != NULL);
287  ASSERT_HOST(char_pos < word_length_);
288  // avoid collision (but this doesn't work if the first choice is favored!
289  if (!allow_collision_ && position_marked(char_pos)) return;
290 
291  if (debug_) {
292  tprintf("Set UID %d -> %s @ %d ",
293  blob_choice->unichar_id(), perm_state_, char_pos);
294  }
295  int pos = find_choice_by_uid(char_choices_->get(char_pos),
296  blob_choice->unichar_id());
297  perm_state_[char_pos] = pos + '0';
298  adjust_factor_ *= weight;
299  if (debug_) tprintf("==> %s %f\n", perm_state_, adjust_factor_);
300 }
int find_choice_by_uid(BLOB_CHOICE_LIST *blob_list, UNICHAR_ID target_uid)
Definition: permute.cpp:110
#define NULL
Definition: host.h:144
T & get(int index) const
UNICHAR_ID unichar_id() const
Definition: ratngs.h:59
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
bool position_marked(int pos)
Definition: permute.h:131
#define ASSERT_HOST(x)
Definition: errcode.h:84
WERD_CHOICE * tesseract::PermuterState::GetPermutedWord ( float *  certainties,
float *  adjust_factor 
)

Definition at line 303 of file permute.cpp.

304  {
305  ASSERT_HOST(char_choices_ != NULL);
306  WERD_CHOICE *word_choice = get_choice_from_posstr(
307  unicharset_, *char_choices_, 0, perm_state_, certainties);
308  float rating = word_choice->rating() * adjust_factor_;
309  word_choice->set_rating(rating);
310  *adjust_factor = adjust_factor_;
311  return word_choice;
312 }
void set_rating(float new_val)
Definition: ratngs.h:255
#define NULL
Definition: host.h:144
WERD_CHOICE * get_choice_from_posstr(const UNICHARSET *unicharset, const BLOB_CHOICE_LIST_VECTOR &char_choices, int start_pos, const char *pos_str, float *certainties)
Definition: permute.cpp:129
#define ASSERT_HOST(x)
Definition: errcode.h:84
float rating() const
Definition: ratngs.h:231
void tesseract::PermuterState::Init ( const BLOB_CHOICE_LIST_VECTOR char_choices,
const UNICHARSET unicharset,
float  default_bias,
bool  debug 
)

Definition at line 240 of file permute.cpp.

243  {
244  ASSERT_HOST(char_choices.length() < MAX_PERM_LENGTH);
245  unicharset_ = &unicharset;
246  char_choices_ = &char_choices;
247  word_length_ = char_choices.length();
248  for (int i = 0; i < word_length_; ++i)
249  perm_state_[i] = kPosFree;
250  perm_state_[word_length_] = '\0';
251  // Skip fragment choice and the mark positions so they remain unchanged.
252  for (int i = 0; i < word_length_; ++i) {
253  UNICHAR_ID unichar_id = get_top_choice_uid(char_choices.get(i));
254  if (unicharset.get_fragment(unichar_id) != NULL)
255  perm_state_[i] = '1';
256  }
257  adjust_factor_ = default_bias;
258  allow_collision_ = false;
259  debug_ = debug;
260 }
UNICHAR_ID get_top_choice_uid(BLOB_CHOICE_LIST *blob_list)
Definition: permute.cpp:99
int UNICHAR_ID
Definition: unichar.h:31
#define NULL
Definition: host.h:144
T & get(int index) const
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
Definition: unicharset.h:610
#define MAX_PERM_LENGTH
Definition: permute.h:36
int length() const
Definition: genericvector.h:63
#define ASSERT_HOST(x)
Definition: errcode.h:84
bool tesseract::PermuterState::position_marked ( int  pos)
inline

Definition at line 131 of file permute.h.

131 { return perm_state_[pos] != kPosFree; }
void tesseract::PermuterState::set_adjust_factor ( float  factor)
inline

Definition at line 129 of file permute.h.

129 { adjust_factor_ = factor; }
void tesseract::PermuterState::set_allow_collision ( bool  flag)
inline

Definition at line 128 of file permute.h.

128 { allow_collision_ = flag; }
void tesseract::PermuterState::set_debug ( bool  debug)
inline

Definition at line 130 of file permute.h.

130 { debug_ = debug; }

The documentation for this class was generated from the following files: