All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::ViterbiStateEntry Struct Reference

#include <lm_state.h>

Inheritance diagram for tesseract::ViterbiStateEntry:
ELIST_LINK

Public Member Functions

 ViterbiStateEntry (ViterbiStateEntry *pe, BLOB_CHOICE *b, float c, float ol, const LMConsistencyInfo &ci, const AssociateStats &as, LanguageModelFlagsType tcf, LanguageModelDawgInfo *d, LanguageModelNgramInfo *n, const char *debug_uch)
 
 ~ViterbiStateEntry ()
 
bool Consistent () const
 
bool HasAlnumChoice (const UNICHARSET &unicharset)
 
void Print (const char *msg) const
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static int Compare (const void *e1, const void *e2)
 

Public Attributes

float cost
 
BLOB_CHOICEcurr_b
 Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this). More...
 
ViterbiStateEntryparent_vse
 
ViterbiStateEntrycompeting_vse
 
float ratings_sum
 
float min_certainty
 
int adapted
 
int length
 
float outline_length
 
LMConsistencyInfo consistency_info
 
AssociateStats associate_stats
 
LanguageModelFlagsType top_choice_flags
 
LanguageModelDawgInfodawg_info
 
LanguageModelNgramInfongram_info
 
bool updated
 
STRINGdebug_str
 

Detailed Description

Struct for storing the information about a path in the segmentation graph explored by Viterbi search.

Definition at line 95 of file lm_state.h.

Constructor & Destructor Documentation

tesseract::ViterbiStateEntry::ViterbiStateEntry ( ViterbiStateEntry pe,
BLOB_CHOICE b,
float  c,
float  ol,
const LMConsistencyInfo ci,
const AssociateStats as,
LanguageModelFlagsType  tcf,
LanguageModelDawgInfo d,
LanguageModelNgramInfo n,
const char *  debug_uch 
)
inline

Definition at line 96 of file lm_state.h.

104  : cost(c), curr_b(b), parent_vse(pe), competing_vse(NULL),
105  ratings_sum(b->rating()),
109  updated(true) {
110  debug_str = (debug_uch == NULL) ? NULL : new STRING();
111  if (pe != NULL) {
112  ratings_sum += pe->ratings_sum;
113  if (pe->min_certainty < min_certainty) {
114  min_certainty = pe->min_certainty;
115  }
116  adapted += pe->adapted;
117  length += pe->length;
118  outline_length += pe->outline_length;
119  if (debug_uch != NULL) *debug_str += *(pe->debug_str);
120  }
121  if (debug_str != NULL && debug_uch != NULL) *debug_str += debug_uch;
122  }
LMConsistencyInfo consistency_info
Definition: lm_state.h:173
BLOB_CHOICE * curr_b
Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this).
Definition: lm_state.h:160
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:186
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:182
bool IsAdapted() const
Definition: ratngs.h:135
ViterbiStateEntry * parent_vse
Definition: lm_state.h:161
LanguageModelFlagsType top_choice_flags
Definition: lm_state.h:178
float rating() const
Definition: ratngs.h:79
AssociateStats associate_stats
Definition: lm_state.h:174
ParamsEditor * pe
Definition: pgedit.cpp:108
ViterbiStateEntry * competing_vse
Definition: lm_state.h:164
Definition: strngs.h:44
#define NULL
Definition: host.h:144
float certainty() const
Definition: ratngs.h:82
tesseract::ViterbiStateEntry::~ViterbiStateEntry ( )
inline

Definition at line 123 of file lm_state.h.

123  {
124  delete dawg_info;
125  delete ngram_info;
126  delete debug_str;
127  }
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:186
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:182

Member Function Documentation

static int tesseract::ViterbiStateEntry::Compare ( const void *  e1,
const void *  e2 
)
inlinestatic

Comparator function for sorting ViterbiStateEntry_LISTs in non-increasing order of costs.

Definition at line 130 of file lm_state.h.

130  {
131  const ViterbiStateEntry *ve1 =
132  *reinterpret_cast<const ViterbiStateEntry * const *>(e1);
133  const ViterbiStateEntry *ve2 =
134  *reinterpret_cast<const ViterbiStateEntry * const *>(e2);
135  return (ve1->cost < ve2->cost) ? -1 : 1;
136  }
ViterbiStateEntry(ViterbiStateEntry *pe, BLOB_CHOICE *b, float c, float ol, const LMConsistencyInfo &ci, const AssociateStats &as, LanguageModelFlagsType tcf, LanguageModelDawgInfo *d, LanguageModelNgramInfo *n, const char *debug_uch)
Definition: lm_state.h:96
bool tesseract::ViterbiStateEntry::Consistent ( ) const
inline

Definition at line 137 of file lm_state.h.

137  {
139  return true;
140  }
141  return consistency_info.Consistent();
142  }
LMConsistencyInfo consistency_info
Definition: lm_state.h:173
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:182
#define NULL
Definition: host.h:144
bool tesseract::ViterbiStateEntry::HasAlnumChoice ( const UNICHARSET unicharset)
inline

Returns true if this VSE has an alphanumeric character as its classifier result.

Definition at line 145 of file lm_state.h.

145  {
146  if (curr_b == NULL) return false;
147  UNICHAR_ID unichar_id = curr_b->unichar_id();
148  if (unicharset.get_isalpha(unichar_id) ||
149  unicharset.get_isdigit(unichar_id))
150  return true;
151  return false;
152  }
BLOB_CHOICE * curr_b
Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this).
Definition: lm_state.h:160
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:470
int UNICHAR_ID
Definition: unichar.h:33
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:449
#define NULL
Definition: host.h:144
UNICHAR_ID unichar_id() const
Definition: ratngs.h:76
void tesseract::ViterbiStateEntry::Print ( const char *  msg) const

Definition at line 27 of file lm_state.cpp.

27  {
28  tprintf("%s ViterbiStateEntry", msg);
29  if (updated) tprintf("(NEW)");
30  if (this->debug_str != NULL) {
31  tprintf(" str=%s", this->debug_str->string());
32  }
33  tprintf(" with ratings_sum=%.4f length=%d cost=%.6f",
34  this->ratings_sum, this->length, this->cost);
35  if (this->top_choice_flags) {
36  tprintf(" top_choice_flags=0x%x", this->top_choice_flags);
37  }
38  if (!this->Consistent()) {
39  tprintf(" inconsistent=(punc %d case %d chartype %d script %d font %d)",
45  }
46  if (this->dawg_info) tprintf(" permuter=%d", this->dawg_info->permuter);
47  if (this->ngram_info) {
48  tprintf(" ngram_cl_cost=%g context=%s ngram pruned=%d",
50  this->ngram_info->context.string(),
51  this->ngram_info->pruned);
52  }
53  if (this->associate_stats.shape_cost > 0.0f) {
54  tprintf(" shape_cost=%g", this->associate_stats.shape_cost);
55  }
56  tprintf(" %s",
57  XHeightConsistencyEnumName[this->consistency_info.xht_decision]);
58 
59  tprintf("\n");
60 }
LMConsistencyInfo consistency_info
Definition: lm_state.h:173
#define tprintf(...)
Definition: tprintf.h:31
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:186
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:182
LanguageModelFlagsType top_choice_flags
Definition: lm_state.h:178
bool Consistent() const
Definition: lm_state.h:137
float ngram_and_classifier_cost
-[ ln(P_classifier(path)) + scale_factor * ln(P_ngram_model(path)) ]
Definition: lm_state.h:90
AssociateStats associate_stats
Definition: lm_state.h:174
int NumInconsistentChartype() const
XHeightConsistencyEnum xht_decision
#define NULL
Definition: host.h:144
const char * string() const
Definition: strngs.cpp:193

Member Data Documentation

int tesseract::ViterbiStateEntry::adapted

Definition at line 170 of file lm_state.h.

AssociateStats tesseract::ViterbiStateEntry::associate_stats

Definition at line 174 of file lm_state.h.

ViterbiStateEntry* tesseract::ViterbiStateEntry::competing_vse

Pointer to a case-competing ViterbiStateEntry in the same list that represents a path ending in the same letter of the opposite case.

Definition at line 164 of file lm_state.h.

LMConsistencyInfo tesseract::ViterbiStateEntry::consistency_info

Definition at line 173 of file lm_state.h.

float tesseract::ViterbiStateEntry::cost

The cost is an adjusted ratings sum, that is adjusted by all the language model components that use Viterbi search.

Definition at line 157 of file lm_state.h.

BLOB_CHOICE* tesseract::ViterbiStateEntry::curr_b

Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this).

Definition at line 160 of file lm_state.h.

LanguageModelDawgInfo* tesseract::ViterbiStateEntry::dawg_info

Extra information maintained by Dawg laguage model component (owned by ViterbiStateEntry).

Definition at line 182 of file lm_state.h.

STRING* tesseract::ViterbiStateEntry::debug_str

UTF8 string representing the path corresponding to this vse. Populated only in when language_model_debug_level > 0.

Definition at line 191 of file lm_state.h.

int tesseract::ViterbiStateEntry::length

Definition at line 171 of file lm_state.h.

float tesseract::ViterbiStateEntry::min_certainty

Definition at line 169 of file lm_state.h.

LanguageModelNgramInfo* tesseract::ViterbiStateEntry::ngram_info

Extra information maintained by Ngram laguage model component (owned by ViterbiStateEntry).

Definition at line 186 of file lm_state.h.

float tesseract::ViterbiStateEntry::outline_length

Definition at line 172 of file lm_state.h.

ViterbiStateEntry* tesseract::ViterbiStateEntry::parent_vse

Definition at line 161 of file lm_state.h.

float tesseract::ViterbiStateEntry::ratings_sum

Various information about the characters on the path represented by this ViterbiStateEntry.

Definition at line 168 of file lm_state.h.

LanguageModelFlagsType tesseract::ViterbiStateEntry::top_choice_flags

Flags for marking the entry as a top choice path with the smallest rating or lower/upper case letters).

Definition at line 178 of file lm_state.h.

bool tesseract::ViterbiStateEntry::updated

Definition at line 188 of file lm_state.h.


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