Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

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

`#include <permute.h>`

List of all members.

## 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_CHOICE * | GetPermutedWord (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.

{
unicharset_ = NULL;
char_choices_ = NULL;
adjust_factor_ = 1.0f;
allow_collision_ = false;
word_length_ = 0;
debug_ = false;
}

## Member Function Documentation

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

Definition at line 266 of file permute.cpp.

{
ASSERT_HOST(char_choices_ != NULL);
ASSERT_HOST(start_pos + strlen(pos_str) - 1 < word_length_);
if (debug_) {
tprintf("Copy over %s -> %s @ %d ", pos_str, perm_state_, start_pos);
}
// copy over preferred position without the terminating null
if (!allow_collision_) {
int len = strlen(pos_str);
for (int i = 0; i < len; ++i)
if (position_marked(start_pos + i)) return;
}
strncpy(&perm_state_[start_pos], pos_str, strlen(pos_str));
adjust_factor_ *= weight;
if (debug_) tprintf("==> %s %f\n", perm_state_, adjust_factor_);
}

void tesseract::PermuterState::AddPreference | ( | int | char_pos,
|  | BLOB_CHOICE * | blob_choice,
|  | float | weight
| ) |  |

Definition at line 284 of file permute.cpp.

{
ASSERT_HOST(char_choices_ != NULL);
ASSERT_HOST(char_pos < word_length_);
// avoid collision (but this doesn't work if the first choice is favored!
if (!allow_collision_ && position_marked(char_pos)) return;
if (debug_) {
tprintf("Set UID %d -> %s @ %d ",
blob_choice->unichar_id(), perm_state_, char_pos);
}
int pos = find_choice_by_uid(char_choices_->get(char_pos),
blob_choice->unichar_id());
perm_state_[char_pos] = pos + '0';
adjust_factor_ *= weight;
if (debug_) tprintf("==> %s %f\n", perm_state_, adjust_factor_);
}

WERD_CHOICE * tesseract::PermuterState::GetPermutedWord | ( | float * | certainties,
|  | float * | adjust_factor
| ) |  |

Definition at line 303 of file permute.cpp.

{
ASSERT_HOST(char_choices_ != NULL);
WERD_CHOICE *word_choice = get_choice_from_posstr(
unicharset_, *char_choices_, 0, perm_state_, certainties);
float rating = word_choice->rating() * adjust_factor_;
word_choice->set_rating(rating);
*adjust_factor = adjust_factor_;
return word_choice;
}

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.

{
ASSERT_HOST(char_choices.length() < MAX_PERM_LENGTH);
unicharset_ = &unicharset;
char_choices_ = &char_choices;
word_length_ = char_choices.length();
for (int i = 0; i < word_length_; ++i)
perm_state_[i] = kPosFree;
perm_state_[word_length_] = '\0';
// Skip fragment choice and the mark positions so they remain unchanged.
for (int i = 0; i < word_length_; ++i) {
UNICHAR_ID unichar_id = get_top_choice_uid(char_choices.get(i));
if (unicharset.get_fragment(unichar_id) != NULL)
perm_state_[i] = '1';
}
adjust_factor_ = default_bias;
allow_collision_ = false;
debug_ = debug;
}

bool tesseract::PermuterState::position_marked | ( | int | pos | ) |

inline

Definition at line 131 of file permute.h.

{ return perm_state_[pos] != kPosFree; }

void tesseract::PermuterState::set_adjust_factor | ( | float | factor | ) |

inline

Definition at line 129 of file permute.h.

{ adjust_factor_ = factor; }

void tesseract::PermuterState::set_allow_collision | ( | bool | flag | ) |

inline

Definition at line 128 of file permute.h.

{ allow_collision_ = flag; }

void tesseract::PermuterState::set_debug | ( | bool | debug | ) |

inline

Definition at line 130 of file permute.h.

{ debug_ = debug; }

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

- /mnt/data/src/tesseract-ocr/dict/permute.h
- /mnt/data/src/tesseract-ocr/dict/permute.cpp