tesseract  5.0.0-alpha-619-ge9db
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 //
7 // (C) Copyright 2012, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 
20 #include "lm_state.h"
21 
22 namespace tesseract {
23 
24 ELISTIZE(ViterbiStateEntry)
25 
26 void ViterbiStateEntry::Print(const char *msg) const {
27  tprintf("%s ViterbiStateEntry", msg);
28  if (updated) tprintf("(NEW)");
29  if (this->debug_str != nullptr) {
30  tprintf(" str=%s", this->debug_str->c_str());
31  }
32  tprintf(" with ratings_sum=%.4f length=%d cost=%.6f",
33  this->ratings_sum, this->length, this->cost);
34  if (this->top_choice_flags) {
35  tprintf(" top_choice_flags=0x%x", this->top_choice_flags);
36  }
37  if (!this->Consistent()) {
38  tprintf(" inconsistent=(punc %d case %d chartype %d script %d font %d)",
39  this->consistency_info.NumInconsistentPunc(),
40  this->consistency_info.NumInconsistentCase(),
41  this->consistency_info.NumInconsistentChartype(),
42  this->consistency_info.inconsistent_script,
43  this->consistency_info.inconsistent_font);
44  }
45  if (this->dawg_info) tprintf(" permuter=%d", this->dawg_info->permuter);
46  if (this->ngram_info) {
47  tprintf(" ngram_cl_cost=%g context=%s ngram pruned=%d",
48  this->ngram_info->ngram_and_classifier_cost,
49  this->ngram_info->context.c_str(),
50  this->ngram_info->pruned);
51  }
52  if (this->associate_stats.shape_cost > 0.0f) {
53  tprintf(" shape_cost=%g", this->associate_stats.shape_cost);
54  }
55  tprintf(" %s",
56  XHeightConsistencyEnumName[this->consistency_info.xht_decision]);
57 
58  tprintf("\n");
59 }
60 
63  viterbi_state_entries.clear();
67 }
68 
69 void LanguageModelState::Print(const char *msg) {
70  tprintf("%s VSEs (max_cost=%g prn_len=%d tot_len=%d):\n",
73  ViterbiStateEntry_IT vit(&viterbi_state_entries);
74  for (vit.mark_cycle_pt(); !vit.cycled_list(); vit.forward()) {
75  vit.data()->Print("");
76  }
77 }
78 
79 
80 } // namespace tesseract
tesseract::ViterbiStateEntry
Definition: lm_state.h:91
tesseract::LanguageModelState::viterbi_state_entries_length
int viterbi_state_entries_length
Total number of entries in viterbi_state_entries.
Definition: lm_state.h:218
tesseract::LanguageModelState::Print
void Print(const char *msg)
Definition: lm_state.cpp:69
tesseract::LanguageModelState::viterbi_state_entries_prunable_max_cost
float viterbi_state_entries_prunable_max_cost
Definition: lm_state.h:216
tesseract
Definition: baseapi.h:65
tesseract::LanguageModelState::viterbi_state_entries
ViterbiStateEntry_LIST viterbi_state_entries
Storage for the Viterbi state.
Definition: lm_state.h:213
tesseract::LanguageModelState::Clear
void Clear()
Clears the viterbi search state back to its initial conditions.
Definition: lm_state.cpp:62
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
ELISTIZE
#define ELISTIZE(CLASSNAME)
Definition: elst.h:919
tesseract::LanguageModelState::viterbi_state_entries_prunable_length
int viterbi_state_entries_prunable_length
Number and max cost of prunable paths in viterbi_state_entries.
Definition: lm_state.h:215
lm_state.h