tesseract  4.0.0-1-g2a2b
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 93 of file lm_state.h.

Constructor & Destructor Documentation

◆ ViterbiStateEntry()

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 94 of file lm_state.h.

102  : cost(c), curr_b(b), parent_vse(pe), competing_vse(nullptr),
103  ratings_sum(b->rating()),
107  updated(true) {
108  debug_str = (debug_uch == nullptr) ? nullptr : new STRING();
109  if (pe != nullptr) {
110  ratings_sum += pe->ratings_sum;
111  if (pe->min_certainty < min_certainty) {
112  min_certainty = pe->min_certainty;
113  }
114  adapted += pe->adapted;
115  length += pe->length;
116  outline_length += pe->outline_length;
117  if (debug_uch != nullptr) *debug_str += *(pe->debug_str);
118  }
119  if (debug_str != nullptr && debug_uch != nullptr) *debug_str += debug_uch;
120  }
float certainty() const
Definition: ratngs.h:83
AssociateStats associate_stats
Definition: lm_state.h:172
BLOB_CHOICE * curr_b
Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this).
Definition: lm_state.h:158
ViterbiStateEntry * competing_vse
Definition: lm_state.h:162
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:184
bool IsAdapted() const
Definition: ratngs.h:136
LMConsistencyInfo consistency_info
Definition: lm_state.h:171
float rating() const
Definition: ratngs.h:80
Definition: strngs.h:45
LanguageModelFlagsType top_choice_flags
Definition: lm_state.h:176
ViterbiStateEntry * parent_vse
Definition: lm_state.h:159
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:180

◆ ~ViterbiStateEntry()

tesseract::ViterbiStateEntry::~ViterbiStateEntry ( )
inline

Definition at line 121 of file lm_state.h.

121  {
122  delete dawg_info;
123  delete ngram_info;
124  delete debug_str;
125  }
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:184
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:180

Member Function Documentation

◆ Compare()

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 128 of file lm_state.h.

128  {
129  const ViterbiStateEntry *ve1 =
130  *static_cast<const ViterbiStateEntry *const *>(e1);
131  const ViterbiStateEntry *ve2 =
132  *static_cast<const ViterbiStateEntry *const *>(e2);
133  return (ve1->cost < ve2->cost) ? -1 : 1;
134  }
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:94

◆ Consistent()

bool tesseract::ViterbiStateEntry::Consistent ( ) const
inline

Definition at line 135 of file lm_state.h.

135  {
136  if (dawg_info != nullptr && consistency_info.NumInconsistentCase() == 0) {
137  return true;
138  }
139  return consistency_info.Consistent();
140  }
LMConsistencyInfo consistency_info
Definition: lm_state.h:171
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:180

◆ HasAlnumChoice()

bool tesseract::ViterbiStateEntry::HasAlnumChoice ( const UNICHARSET unicharset)
inline

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

Definition at line 143 of file lm_state.h.

143  {
144  if (curr_b == nullptr) return false;
145  UNICHAR_ID unichar_id = curr_b->unichar_id();
146  if (unicharset.get_isalpha(unichar_id) ||
147  unicharset.get_isdigit(unichar_id))
148  return true;
149  return false;
150  }
int UNICHAR_ID
Definition: unichar.h:35
BLOB_CHOICE * curr_b
Pointers to BLOB_CHOICE and parent ViterbiStateEntry (not owned by this).
Definition: lm_state.h:158
bool get_isalpha(UNICHAR_ID unichar_id) const
Definition: unicharset.h:486
bool get_isdigit(UNICHAR_ID unichar_id) const
Definition: unicharset.h:507
UNICHAR_ID unichar_id() const
Definition: ratngs.h:77

◆ Print()

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 != nullptr) {
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 }
float ngram_and_classifier_cost
-[ ln(P_classifier(path)) + scale_factor * ln(P_ngram_model(path)) ]
Definition: lm_state.h:88
AssociateStats associate_stats
Definition: lm_state.h:172
const char * string() const
Definition: strngs.cpp:196
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:184
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
LMConsistencyInfo consistency_info
Definition: lm_state.h:171
LanguageModelFlagsType top_choice_flags
Definition: lm_state.h:176
XHeightConsistencyEnum xht_decision
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:180

Member Data Documentation

◆ adapted

int tesseract::ViterbiStateEntry::adapted

Definition at line 168 of file lm_state.h.

◆ associate_stats

AssociateStats tesseract::ViterbiStateEntry::associate_stats

Definition at line 172 of file lm_state.h.

◆ competing_vse

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 162 of file lm_state.h.

◆ consistency_info

LMConsistencyInfo tesseract::ViterbiStateEntry::consistency_info

Definition at line 171 of file lm_state.h.

◆ cost

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 155 of file lm_state.h.

◆ curr_b

BLOB_CHOICE* tesseract::ViterbiStateEntry::curr_b

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

Definition at line 158 of file lm_state.h.

◆ dawg_info

LanguageModelDawgInfo* tesseract::ViterbiStateEntry::dawg_info

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

Definition at line 180 of file lm_state.h.

◆ debug_str

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 189 of file lm_state.h.

◆ length

int tesseract::ViterbiStateEntry::length

Definition at line 169 of file lm_state.h.

◆ min_certainty

float tesseract::ViterbiStateEntry::min_certainty

Definition at line 167 of file lm_state.h.

◆ ngram_info

LanguageModelNgramInfo* tesseract::ViterbiStateEntry::ngram_info

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

Definition at line 184 of file lm_state.h.

◆ outline_length

float tesseract::ViterbiStateEntry::outline_length

Definition at line 170 of file lm_state.h.

◆ parent_vse

ViterbiStateEntry* tesseract::ViterbiStateEntry::parent_vse

Definition at line 159 of file lm_state.h.

◆ ratings_sum

float tesseract::ViterbiStateEntry::ratings_sum

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

Definition at line 166 of file lm_state.h.

◆ top_choice_flags

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 176 of file lm_state.h.

◆ updated

bool tesseract::ViterbiStateEntry::updated

Definition at line 186 of file lm_state.h.


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