tesseract  4.00.00dev
lm_state.cpp
Go to the documentation of this file.
1 // File: lm_state.cpp
3 // Description: Structures and functionality for capturing the state of
4 // segmentation search guided by the language model.
5 // Author: Rika Antonova
6 // Created: Mon Jun 20 11:26:43 PST 2012
7 //
8 // (C) Copyright 2012, Google Inc.
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
20 
21 #include "lm_state.h"
22 
23 namespace tesseract {
24 
25 ELISTIZE(ViterbiStateEntry);
26 
27 void ViterbiStateEntry::Print(const char *msg) const {
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 }
61 
64  viterbi_state_entries.clear();
65  viterbi_state_entries_prunable_length = 0;
66  viterbi_state_entries_prunable_max_cost = MAX_FLOAT32;
67  viterbi_state_entries_length = 0;
68 }
69 
70 void LanguageModelState::Print(const char *msg) {
71  tprintf("%s VSEs (max_cost=%g prn_len=%d tot_len=%d):\n",
72  msg, viterbi_state_entries_prunable_max_cost,
73  viterbi_state_entries_prunable_length, viterbi_state_entries_length);
74  ViterbiStateEntry_IT vit(&viterbi_state_entries);
75  for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
76  vit.data()->Print("");
77  }
78 }
79 
80 
81 } // namespace tesseract
LMConsistencyInfo consistency_info
Definition: lm_state.h:169
void Print(const char *msg)
Definition: lm_state.cpp:70
#define tprintf(...)
Definition: tprintf.h:31
const char * string() const
Definition: strngs.cpp:198
float ngram_and_classifier_cost
-[ ln(P_classifier(path)) + scale_factor * ln(P_ngram_model(path)) ]
Definition: lm_state.h:86
void Print(const char *msg) const
Definition: lm_state.cpp:27
XHeightConsistencyEnum xht_decision
#define MAX_FLOAT32
Definition: host.h:66
LanguageModelNgramInfo * ngram_info
Definition: lm_state.h:182
void Clear()
Clears the viterbi search state back to its initial conditions.
Definition: lm_state.cpp:63
LanguageModelFlagsType top_choice_flags
Definition: lm_state.h:174
LanguageModelDawgInfo * dawg_info
Definition: lm_state.h:178
ELISTIZE(AmbigSpec)
AssociateStats associate_stats
Definition: lm_state.h:170