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

#include <ratngs.h>

Public Member Functions

 WERD_CHOICE (const UNICHARSET *unicharset)
 
 WERD_CHOICE (const UNICHARSET *unicharset, int reserved)
 
 WERD_CHOICE (const char *src_string, const char *src_lengths, float src_rating, float src_certainty, uinT8 src_permuter, const UNICHARSET &unicharset)
 
 WERD_CHOICE (const char *src_string, const UNICHARSET &unicharset)
 
 WERD_CHOICE (const WERD_CHOICE &word)
 
 ~WERD_CHOICE ()
 
const UNICHARSETunicharset () const
 
int length () const
 
const UNICHAR_IDunichar_ids () const
 
const UNICHAR_ID unichar_id (int index) const
 
const char * fragment_lengths () const
 
const char fragment_length (int index) const
 
float rating () const
 
float certainty () const
 
uinT8 permuter () const
 
const char * permuter_name () const
 
bool fragment_mark () const
 
BLOB_CHOICE_LIST_CLIST * blob_choices ()
 
void set_unichar_id (UNICHAR_ID unichar_id, int index)
 
void set_fragment_length (char flen, int index)
 
void set_rating (float new_val)
 
void set_certainty (float new_val)
 
void set_permuter (uinT8 perm)
 
void set_fragment_mark (bool new_fragment_mark)
 
void set_length (int len)
 
void set_blob_choices (BLOB_CHOICE_LIST_CLIST *blob_choices)
 
void double_the_size ()
 Make more space in unichar_id_ and fragment_lengths_ arrays. More...
 
void init (int reserved)
 
void init (const char *src_string, const char *src_lengths, float src_rating, float src_certainty, uinT8 src_permuter)
 
void make_bad ()
 Set the fields in this choice to be default (bad) values. More...
 
void append_unichar_id_space_allocated (UNICHAR_ID unichar_id, char fragment_length, float rating, float certainty)
 
void append_unichar_id (UNICHAR_ID unichar_id, char fragment_length, float rating, float certainty)
 
void set_unichar_id (UNICHAR_ID unichar_id, char fragment_length, float rating, float certainty, int index)
 
bool contains_unichar_id (UNICHAR_ID unichar_id) const
 
void remove_unichar_ids (int index, int num)
 
void remove_last_unichar_id ()
 
void remove_unichar_id (int index)
 
bool has_rtl_unichar_id () const
 
void reverse_and_mirror_unichar_ids ()
 
void punct_stripped (int *start_core, int *end_core) const
 
WERD_CHOICE shallow_copy (int start, int end) const
 
void string_and_lengths (STRING *word_str, STRING *word_lengths_str) const
 
const STRING debug_string () const
 
bool set_unichars_in_script_order (bool in_script_order)
 
bool unichars_in_script_order () const
 
const STRINGunichar_string () const
 
const STRINGunichar_lengths () const
 
const void print () const
 
const void print (const char *msg) const
 
WERD_CHOICEoperator+= (const WERD_CHOICE &second)
 
WERD_CHOICEoperator= (const WERD_CHOICE &source)
 

Static Public Attributes

static const float kBadRating = 100000.0
 

Detailed Description

Definition at line 186 of file ratngs.h.

Constructor & Destructor Documentation

WERD_CHOICE::WERD_CHOICE ( const UNICHARSET unicharset)
inline

Definition at line 190 of file ratngs.h.

191  : unicharset_(unicharset) { this->init(8); }
void init(int reserved)
Definition: ratngs.h:293
WERD_CHOICE::WERD_CHOICE ( const UNICHARSET unicharset,
int  reserved 
)
inline

Definition at line 192 of file ratngs.h.

193  : unicharset_(unicharset) { this->init(reserved); }
void init(int reserved)
Definition: ratngs.h:293
WERD_CHOICE::WERD_CHOICE ( const char *  src_string,
const char *  src_lengths,
float  src_rating,
float  src_certainty,
uinT8  src_permuter,
const UNICHARSET unicharset 
)
inline

Definition at line 194 of file ratngs.h.

200  : unicharset_(&unicharset) {
201  this->init(src_string, src_lengths, src_rating,
202  src_certainty, src_permuter);
203  }
void init(int reserved)
Definition: ratngs.h:293
WERD_CHOICE::WERD_CHOICE ( const char *  src_string,
const UNICHARSET unicharset 
)

WERD_CHOICE::WERD_CHOICE

Constructor to build a WERD_CHOICE from the given string. The function assumes that src_string is not NULL.

Definition at line 112 of file ratngs.cpp.

114  : unicharset_(&unicharset){
115  STRING src_lengths;
116  const char *ptr = src_string;
117  const char *end = src_string + strlen(src_string);
118  int step = unicharset.step(ptr);
119  for (; ptr < end && step > 0;
120  step = unicharset.step(ptr), src_lengths += step, ptr += step);
121  if (step != 0 && ptr == end) {
122  this->init(src_string, src_lengths.string(),
123  0.0, 0.0, NO_PERM);
124  } else { // there must have been an invalid unichar in the string
125  this->init(8);
126  this->make_bad();
127  }
128 }
void make_bad()
Set the fields in this choice to be default (bad) values.
Definition: ratngs.h:321
const char * string() const
Definition: strngs.cpp:156
Definition: strngs.h:40
int step(const char *str) const
Definition: unicharset.cpp:192
void init(int reserved)
Definition: ratngs.h:293
WERD_CHOICE::WERD_CHOICE ( const WERD_CHOICE word)
inline

Definition at line 205 of file ratngs.h.

205  : unicharset_(word.unicharset_) {
206  this->init(word.length());
207  this->operator=(word);
208  }
int length() const
Definition: ratngs.h:214
WERD_CHOICE & operator=(const WERD_CHOICE &source)
Definition: ratngs.cpp:394
void init(int reserved)
Definition: ratngs.h:293
WERD_CHOICE::~WERD_CHOICE ( )

WERD_CHOICE::~WERD_CHOICE

Definition at line 168 of file ratngs.cpp.

168  {
169  delete[] unichar_ids_;
170  delete[] fragment_lengths_;
171  delete_blob_choices();
172 }

Member Function Documentation

void WERD_CHOICE::append_unichar_id ( UNICHAR_ID  unichar_id,
char  fragment_length,
float  rating,
float  certainty 
)

append_unichar_id

Make sure there is enough space in the word for the new unichar id and call append_unichar_id_space_allocated().

Definition at line 313 of file ratngs.cpp.

315  {
316  if (length_ == reserved_) {
317  this->double_the_size();
318  }
320  rating, certainty);
321 }
float certainty() const
Definition: ratngs.h:234
const char fragment_length(int index) const
Definition: ratngs.h:227
void double_the_size()
Make more space in unichar_id_ and fragment_lengths_ arrays.
Definition: ratngs.h:277
void append_unichar_id_space_allocated(UNICHAR_ID unichar_id, char fragment_length, float rating, float certainty)
Definition: ratngs.h:331
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
float rating() const
Definition: ratngs.h:231
void WERD_CHOICE::append_unichar_id_space_allocated ( UNICHAR_ID  unichar_id,
char  fragment_length,
float  rating,
float  certainty 
)
inline

This function assumes that there is enough space reserved in the WERD_CHOICE for adding another unichar. This is an efficient alternative to append_unichar_id().

Definition at line 331 of file ratngs.h.

333  {
334  assert(reserved_ > length_);
335  length_++;
337  rating, certainty, length_-1);
338  }
float certainty() const
Definition: ratngs.h:234
const char fragment_length(int index) const
Definition: ratngs.h:227
void set_unichar_id(UNICHAR_ID unichar_id, int index)
Definition: ratngs.h:247
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
float rating() const
Definition: ratngs.h:231
BLOB_CHOICE_LIST_CLIST* WERD_CHOICE::blob_choices ( )
inline

Definition at line 244 of file ratngs.h.

244  {
245  return blob_choices_;
246  }
float WERD_CHOICE::certainty ( ) const
inline

Definition at line 234 of file ratngs.h.

234  {
235  return certainty_;
236  }
bool WERD_CHOICE::contains_unichar_id ( UNICHAR_ID  unichar_id) const

contains_unichar_id

Returns true if unichar_ids_ contain the given unichar_id, false otherwise.

Definition at line 197 of file ratngs.cpp.

197  {
198  for (int i = 0; i < length_; ++i) {
199  if (unichar_ids_[i] == unichar_id) {
200  return true;
201  }
202  }
203  return false;
204 }
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
const STRING WERD_CHOICE::debug_string ( ) const
inline

Definition at line 373 of file ratngs.h.

373  {
374  STRING word_str;
375  for (int i = 0; i < length_; ++i) {
376  word_str += unicharset_->debug_str(unichar_ids_[i]);
377  word_str += " ";
378  }
379  return word_str;
380  }
STRING debug_str(UNICHAR_ID id) const
Definition: unicharset.cpp:285
Definition: strngs.h:40
void WERD_CHOICE::double_the_size ( )
inline

Make more space in unichar_id_ and fragment_lengths_ arrays.

Definition at line 277 of file ratngs.h.

277  {
278  if (reserved_ > 0) {
280  reserved_, unichar_ids_);
282  reserved_, fragment_lengths_);
283  reserved_ *= 2;
284  } else {
285  unichar_ids_ = new UNICHAR_ID[1];
286  fragment_lengths_ = new char[1];
287  reserved_ = 1;
288  }
289  }
int UNICHAR_ID
Definition: unichar.h:31
static T * double_the_size_memcpy(int current_size, T *data)
const char WERD_CHOICE::fragment_length ( int  index) const
inline

Definition at line 227 of file ratngs.h.

227  {
228  assert(index < length_);
229  return fragment_lengths_[index];
230  }
const char* WERD_CHOICE::fragment_lengths ( ) const
inline

Definition at line 224 of file ratngs.h.

224  {
225  return fragment_lengths_;
226  }
bool WERD_CHOICE::fragment_mark ( ) const
inline

Definition at line 241 of file ratngs.h.

241  {
242  return fragment_mark_;
243  }
bool WERD_CHOICE::has_rtl_unichar_id ( ) const

has_rtl_unichar_id

Returns true if unichar_ids contain at least one "strongly" RTL unichar.

Definition at line 276 of file ratngs.cpp.

276  {
277  int i;
278  for (i = 0; i < length_; ++i) {
279  UNICHARSET::Direction dir = unicharset_->get_direction(unichar_ids_[i]);
280  if (dir == UNICHARSET::U_RIGHT_TO_LEFT ||
282  return true;
283  }
284  }
285  return false;
286 }
Direction get_direction(UNICHAR_ID unichar_id) const
Definition: unicharset.h:579
void WERD_CHOICE::init ( int  reserved)
inline

Initializes WERD_CHOICE - reserves length slots in unichar_ids_ and fragment_length_ arrays. Sets other values to default (blank) values.

Definition at line 293 of file ratngs.h.

293  {
294  reserved_ = reserved;
295  if (reserved > 0) {
296  unichar_ids_ = new UNICHAR_ID[reserved];
297  fragment_lengths_ = new char[reserved];
298  } else {
299  unichar_ids_ = NULL;
300  fragment_lengths_ = NULL;
301  }
302  length_ = 0;
303  rating_ = 0.0;
304  certainty_ = MAX_FLOAT32;
305  permuter_ = NO_PERM;
306  fragment_mark_ = false;
307  blob_choices_ = NULL;
308  unichars_in_script_order_ = false; // Tesseract is strict left-to-right.
309  }
int UNICHAR_ID
Definition: unichar.h:31
#define NULL
Definition: host.h:144
#define MAX_FLOAT32
Definition: host.h:124
void WERD_CHOICE::init ( const char *  src_string,
const char *  src_lengths,
float  src_rating,
float  src_certainty,
uinT8  src_permuter 
)

Helper function to build a WERD_CHOICE from the given string, fragment lengths, rating, certainty and permuter. The function assumes that src_string is not NULL. src_lengths argument could be NULL, in which case the unichars in src_string are assumed to all be of length 1.

WERD_CHOICE::init

Helper function to build a WERD_CHOICE from the given string, fragment lengths, rating, certainty and permuter.

The function assumes that src_string is not NULL. src_lengths argument could be NULL, in which case the unichars in src_string are assumed to all be of length 1.

Definition at line 140 of file ratngs.cpp.

144  {
145  int src_string_len = strlen(src_string);
146  if (src_string_len == 0) {
147  this->init(8);
148  } else {
149  this->init(src_lengths ? strlen(src_lengths): src_string_len);
150  length_ = reserved_;
151  int offset = 0;
152  for (int i = 0; i < length_; ++i) {
153  int unichar_length = src_lengths ? src_lengths[i] : 1;
154  unichar_ids_[i] =
155  unicharset_->unichar_to_id(src_string+offset, unichar_length);
156  fragment_lengths_[i] = 1;
157  offset += unichar_length;
158  }
159  }
160  rating_ = src_rating;
161  certainty_ = src_certainty;
162  permuter_ = src_permuter;
163 }
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:176
void init(int reserved)
Definition: ratngs.h:293
int WERD_CHOICE::length ( ) const
inline

Definition at line 214 of file ratngs.h.

214  {
215  return length_;
216  }
void WERD_CHOICE::make_bad ( )
inline

Set the fields in this choice to be default (bad) values.

Definition at line 321 of file ratngs.h.

321  {
322  length_ = 0;
323  rating_ = kBadRating;
324  certainty_ = -MAX_FLOAT32;
325  fragment_mark_ = false;
326  }
static const float kBadRating
Definition: ratngs.h:188
#define MAX_FLOAT32
Definition: host.h:124
WERD_CHOICE & WERD_CHOICE::operator+= ( const WERD_CHOICE second)

WERD_CHOICE::operator+=

Cat a second word rating on the end of this current one. The ratings are added and the confidence is the min. If the permuters are NOT the same the permuter is set to COMPOUND_PERM

Definition at line 330 of file ratngs.cpp.

330  {
331  // TODO(daria): find out why the choice was cleared this way if any
332  // of the pieces are empty. Add the description of this behavior
333  // to the comments.
334  // if (word_string.length () == 0 || second.word_string.length () == 0) {
335  // word_string = NULL; //make it empty
336  // word_lengths = NULL;
337  // delete_blob_choices();
338  // } else {
339  ASSERT_HOST(unicharset_ == second.unicharset_);
340  while (reserved_ < length_ + second.length()) {
341  this->double_the_size();
342  }
343  const UNICHAR_ID *other_unichar_ids = second.unichar_ids();
344  const char *other_fragment_lengths = second.fragment_lengths();
345  for (int i = 0; i < second.length(); ++i) {
346  unichar_ids_[length_ + i] = other_unichar_ids[i];
347  fragment_lengths_[length_ + i] = other_fragment_lengths[i];
348  }
349  length_ += second.length();
350  rating_ += second.rating(); // add ratings
351  if (second.certainty() < certainty_) // take min
352  certainty_ = second.certainty();
353  if (permuter_ == NO_PERM) {
354  permuter_ = second.permuter();
355  } else if (second.permuter() != NO_PERM &&
356  second.permuter() != permuter_) {
357  permuter_ = COMPOUND_PERM;
358  }
359 
360  // Append a deep copy of second blob_choices if it exists.
361  if (second.blob_choices_ != NULL) {
362  if (this->blob_choices_ == NULL)
363  this->blob_choices_ = new BLOB_CHOICE_LIST_CLIST;
364 
365  BLOB_CHOICE_LIST_C_IT this_blob_choices_it;
366  BLOB_CHOICE_LIST_C_IT second_blob_choices_it;
367 
368  this_blob_choices_it.set_to_list(this->blob_choices_);
369  this_blob_choices_it.move_to_last();
370 
371  second_blob_choices_it.set_to_list(second.blob_choices_);
372 
373  for (second_blob_choices_it.mark_cycle_pt();
374  !second_blob_choices_it.cycled_list();
375  second_blob_choices_it.forward()) {
376 
377  BLOB_CHOICE_LIST* blob_choices_copy = new BLOB_CHOICE_LIST();
378  blob_choices_copy->deep_copy(second_blob_choices_it.data(),
380 
381  this_blob_choices_it.add_after_then_move(blob_choices_copy);
382  }
383  }
384  return *this;
385 }
int length() const
Definition: ratngs.h:214
int UNICHAR_ID
Definition: unichar.h:31
const UNICHAR_ID * unichar_ids() const
Definition: ratngs.h:217
float certainty() const
Definition: ratngs.h:234
#define NULL
Definition: host.h:144
const char * fragment_lengths() const
Definition: ratngs.h:224
uinT8 permuter() const
Definition: ratngs.h:237
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:126
void double_the_size()
Make more space in unichar_id_ and fragment_lengths_ arrays.
Definition: ratngs.h:277
#define ASSERT_HOST(x)
Definition: errcode.h:84
float rating() const
Definition: ratngs.h:231
WERD_CHOICE & WERD_CHOICE::operator= ( const WERD_CHOICE source)

WERD_CHOICE::operator=

Allocate enough memory to hold a copy of source and copy over all the information from source to this WERD_CHOICE.

Definition at line 394 of file ratngs.cpp.

394  {
395  while (reserved_ < source.length()) {
396  this->double_the_size();
397  }
398 
399  unicharset_ = source.unicharset_;
400  const UNICHAR_ID *other_unichar_ids = source.unichar_ids();
401  const char *other_fragment_lengths = source.fragment_lengths();
402  for (int i = 0; i < source.length(); ++i) {
403  unichar_ids_[i] = other_unichar_ids[i];
404  fragment_lengths_[i] = other_fragment_lengths[i];
405  }
406  length_ = source.length();
407  rating_ = source.rating();
408  certainty_ = source.certainty();
409  permuter_ = source.permuter();
410  fragment_mark_ = source.fragment_mark();
411 
412  // Delete existing blob_choices
413  this->delete_blob_choices();
414 
415  // Deep copy blob_choices of source
416  if (source.blob_choices_ != NULL) {
417  BLOB_CHOICE_LIST_C_IT this_blob_choices_it;
418  BLOB_CHOICE_LIST_C_IT source_blob_choices_it;
419 
420  this->blob_choices_ = new BLOB_CHOICE_LIST_CLIST();
421 
422  this_blob_choices_it.set_to_list(this->blob_choices_);
423  source_blob_choices_it.set_to_list(source.blob_choices_);
424 
425  for (source_blob_choices_it.mark_cycle_pt();
426  !source_blob_choices_it.cycled_list();
427  source_blob_choices_it.forward()) {
428 
429  BLOB_CHOICE_LIST* blob_choices_copy = new BLOB_CHOICE_LIST();
430  blob_choices_copy->deep_copy(source_blob_choices_it.data(),
432 
433  this_blob_choices_it.add_after_then_move(blob_choices_copy);
434  }
435  }
436  return *this;
437 }
int length() const
Definition: ratngs.h:214
int UNICHAR_ID
Definition: unichar.h:31
const UNICHAR_ID * unichar_ids() const
Definition: ratngs.h:217
float certainty() const
Definition: ratngs.h:234
#define NULL
Definition: host.h:144
const char * fragment_lengths() const
Definition: ratngs.h:224
uinT8 permuter() const
Definition: ratngs.h:237
bool fragment_mark() const
Definition: ratngs.h:241
static BLOB_CHOICE * deep_copy(const BLOB_CHOICE *src)
Definition: ratngs.h:126
void double_the_size()
Make more space in unichar_id_ and fragment_lengths_ arrays.
Definition: ratngs.h:277
float rating() const
Definition: ratngs.h:231
uinT8 WERD_CHOICE::permuter ( ) const
inline

Definition at line 237 of file ratngs.h.

237  {
238  return permuter_;
239  }
const char * WERD_CHOICE::permuter_name ( ) const

Definition at line 174 of file ratngs.cpp.

174  {
175  return kPermuterTypeNames[permuter_];
176 }
const void WERD_CHOICE::print ( ) const
inline

Definition at line 406 of file ratngs.h.

406 { this->print(""); }
const void print() const
Definition: ratngs.h:406
const void WERD_CHOICE::print ( const char *  msg) const

WERD_CHOICE::print

Print WERD_CHOICE to stdout.

Definition at line 457 of file ratngs.cpp.

457  {
458  tprintf("%s WERD_CHOICE:\n", msg);
459  tprintf("length_ %d reserved_ %d permuter_ %d\n",
460  length_, reserved_, permuter_);
461  tprintf("rating_ %.4f certainty_ %.4f", rating_, certainty_);
462  if (fragment_mark_) {
463  tprintf(" fragment_mark_ true");
464  }
465  tprintf("\n");
466  if (unichar_string_.length() > 0) {
467  tprintf("unichar_string_ %s unichar_lengths_ %s\n",
468  unichar_string_.string(), unichar_lengths_.string());
469  }
470  tprintf("unichar_ids: ");
471  int i;
472  for (i = 0; i < length_; ++i) {
473  tprintf("%d ", unichar_ids_[i]);
474  }
475  tprintf("\nfragment_lengths_: ");
476  for (i = 0; i < length_; ++i) {
477  tprintf("%d ", fragment_lengths_[i]);
478  }
479  tprintf("\n");
480  fflush(stdout);
481 }
inT32 length() const
Definition: strngs.cpp:151
const char * string() const
Definition: strngs.cpp:156
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void WERD_CHOICE::punct_stripped ( int *  start,
int *  end 
) const

punct_stripped

Returns the half-open interval of unichar_id indices [start, end) which enclose the core portion of this word – the part after stripping punctuation from the left and right.

Definition at line 245 of file ratngs.cpp.

245  {
246  *start = 0;
247  *end = length() - 1;
248  while (*start < length() &&
249  unicharset()->get_ispunctuation(unichar_id(*start))) {
250  (*start)++;
251  }
252  while (*end > -1 &&
253  unicharset()->get_ispunctuation(unichar_id(*end))) {
254  (*end)--;
255  }
256  (*end)++;
257 }
int length() const
Definition: ratngs.h:214
const UNICHARSET * unicharset() const
Definition: ratngs.h:211
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
float WERD_CHOICE::rating ( ) const
inline

Definition at line 231 of file ratngs.h.

231  {
232  return rating_;
233  }
void WERD_CHOICE::remove_last_unichar_id ( )
inline

Definition at line 356 of file ratngs.h.

356 { --length_; }
void WERD_CHOICE::remove_unichar_id ( int  index)
inline

Definition at line 357 of file ratngs.h.

357  {
358  this->remove_unichar_ids(index, 1);
359  }
void remove_unichar_ids(int index, int num)
Definition: ratngs.cpp:213
void WERD_CHOICE::remove_unichar_ids ( int  start,
int  num 
)

remove_unichar_ids

Removes num unichar ids starting from index start from unichar_ids_ and updates length_ and fragment_lengths_ to reflect this change. Note: this function does not modify rating_ and certainty_.

Definition at line 213 of file ratngs.cpp.

213  {
214  ASSERT_HOST(start >= 0 && start + num <= length_);
215  for (int i = start; i+num < length_; ++i) {
216  unichar_ids_[i] = unichar_ids_[i+num];
217  fragment_lengths_[i] = fragment_lengths_[i+num];
218  }
219  length_ -= num;
220 }
#define ASSERT_HOST(x)
Definition: errcode.h:84
void WERD_CHOICE::reverse_and_mirror_unichar_ids ( )

reverse_and_mirror_unichar_ids

Reverses and mirrors unichars in unichar_ids.

Definition at line 227 of file ratngs.cpp.

227  {
228  for (int i = 0; i < length_/2; ++i) {
229  UNICHAR_ID tmp_id = unichar_ids_[i];
230  unichar_ids_[i] = unicharset_->get_mirror(unichar_ids_[length_-1-i]);
231  unichar_ids_[length_-1-i] = unicharset_->get_mirror(tmp_id);
232  }
233  if (length_ % 2 != 0) {
234  unichar_ids_[length_/2] = unicharset_->get_mirror(unichar_ids_[length_/2]);
235  }
236 }
int UNICHAR_ID
Definition: unichar.h:31
UNICHAR_ID get_mirror(UNICHAR_ID unichar_id) const
Definition: unicharset.h:586
void WERD_CHOICE::set_blob_choices ( BLOB_CHOICE_LIST_CLIST *  blob_choices)

WERD_CHOICE::set_blob_choices

Delete current blob_choices. Set the blob_choices to the given new list.

Definition at line 184 of file ratngs.cpp.

184  {
185  if (blob_choices_ != blob_choices) {
186  delete_blob_choices();
187  blob_choices_ = blob_choices;
188  }
189 }
BLOB_CHOICE_LIST_CLIST * blob_choices()
Definition: ratngs.h:244
void WERD_CHOICE::set_certainty ( float  new_val)
inline

Definition at line 258 of file ratngs.h.

258  {
259  certainty_ = new_val;
260  }
void WERD_CHOICE::set_fragment_length ( char  flen,
int  index 
)
inline

Definition at line 251 of file ratngs.h.

251  {
252  assert(index < length_);
253  fragment_lengths_[index] = flen;
254  }
void WERD_CHOICE::set_fragment_mark ( bool  new_fragment_mark)
inline

Definition at line 264 of file ratngs.h.

264  {
265  fragment_mark_ = new_fragment_mark;
266  }
void WERD_CHOICE::set_length ( int  len)
inline

Definition at line 270 of file ratngs.h.

270  {
271  ASSERT_HOST(reserved_ >= len);
272  length_ = len;
273  }
#define ASSERT_HOST(x)
Definition: errcode.h:84
void WERD_CHOICE::set_permuter ( uinT8  perm)
inline

Definition at line 261 of file ratngs.h.

261  {
262  permuter_ = perm;
263  }
void WERD_CHOICE::set_rating ( float  new_val)
inline

Definition at line 255 of file ratngs.h.

255  {
256  rating_ = new_val;
257  }
void WERD_CHOICE::set_unichar_id ( UNICHAR_ID  unichar_id,
int  index 
)
inline

Definition at line 247 of file ratngs.h.

247  {
248  assert(index < length_);
249  unichar_ids_[index] = unichar_id;
250  }
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
void WERD_CHOICE::set_unichar_id ( UNICHAR_ID  unichar_id,
char  fragment_length,
float  rating,
float  certainty,
int  index 
)
inline

Definition at line 343 of file ratngs.h.

344  {
345  assert(index < length_);
346  unichar_ids_[index] = unichar_id;
347  fragment_lengths_[index] = fragment_length;
348  rating_ += rating;
349  if (certainty < certainty_) {
350  certainty_ = certainty;
351  }
352  }
float certainty() const
Definition: ratngs.h:234
const char fragment_length(int index) const
Definition: ratngs.h:227
const UNICHAR_ID unichar_id(int index) const
Definition: ratngs.h:220
float rating() const
Definition: ratngs.h:231
bool WERD_CHOICE::set_unichars_in_script_order ( bool  in_script_order)
inline

Definition at line 385 of file ratngs.h.

385  {
386  return unichars_in_script_order_ = in_script_order;
387  }
WERD_CHOICE WERD_CHOICE::shallow_copy ( int  start,
int  end 
) const

Definition at line 259 of file ratngs.cpp.

259  {
260  ASSERT_HOST(start >= 0 && start <= length_);
261  ASSERT_HOST(end >= 0 && end <= length_);
262  if (end < start) { end = start; }
263  WERD_CHOICE retval(unicharset_, end - start);
264  for (int i = start; i < end; i++) {
265  retval.append_unichar_id_space_allocated(
266  unichar_ids_[i], fragment_lengths_[i], 0.0f, 0.0f);
267  }
268  return retval;
269 }
#define f(xc, yc)
Definition: imgscale.cpp:39
#define ASSERT_HOST(x)
Definition: errcode.h:84
void WERD_CHOICE::string_and_lengths ( STRING word_str,
STRING word_lengths_str 
) const

string_and_lengths

Populates the given word_str with unichars from unichar_ids and and word_lengths_str with the corresponding unichar lengths.

Definition at line 294 of file ratngs.cpp.

295  {
296  *word_str = "";
297  if (word_lengths_str != NULL) *word_lengths_str = "";
298  for (int i = 0; i < length_; ++i) {
299  const char *ch = unicharset_->id_to_unichar_ext(unichar_ids_[i]);
300  *word_str += ch;
301  if (word_lengths_str != NULL) {
302  *word_lengths_str += strlen(ch);
303  }
304  }
305 }
const char *const id_to_unichar_ext(UNICHAR_ID id) const
Definition: unicharset.cpp:241
#define NULL
Definition: host.h:144
const UNICHAR_ID WERD_CHOICE::unichar_id ( int  index) const
inline

Definition at line 220 of file ratngs.h.

220  {
221  assert(index < length_);
222  return unichar_ids_[index];
223  }
const UNICHAR_ID* WERD_CHOICE::unichar_ids ( ) const
inline

Definition at line 217 of file ratngs.h.

217  {
218  return unichar_ids_;
219  }
const STRING& WERD_CHOICE::unichar_lengths ( ) const
inline

Definition at line 402 of file ratngs.h.

402  {
403  this->string_and_lengths(&unichar_string_, &unichar_lengths_);
404  return unichar_lengths_;
405  }
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
Definition: ratngs.cpp:294
const STRING& WERD_CHOICE::unichar_string ( ) const
inline

Definition at line 395 of file ratngs.h.

395  {
396  this->string_and_lengths(&unichar_string_, &unichar_lengths_);
397  return unichar_string_;
398  }
void string_and_lengths(STRING *word_str, STRING *word_lengths_str) const
Definition: ratngs.cpp:294
bool WERD_CHOICE::unichars_in_script_order ( ) const
inline

Definition at line 389 of file ratngs.h.

389  {
390  return unichars_in_script_order_;
391  }
const UNICHARSET* WERD_CHOICE::unicharset ( ) const
inline

Definition at line 211 of file ratngs.h.

211  {
212  return unicharset_;
213  }

Member Data Documentation

const float WERD_CHOICE::kBadRating = 100000.0
static

Definition at line 188 of file ratngs.h.


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