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

#include <tess_lang_mod_edge.h>

Inheritance diagram for tesseract::TessLangModEdge:
tesseract::LangModEdge

Public Member Functions

 TessLangModEdge (CubeRecoContext *cntxt, const Dawg *edge_array, EDGE_REF edge, int class_id)
 
 TessLangModEdge (CubeRecoContext *cntxt, const Dawg *edge_array, EDGE_REF start_edge_idx, EDGE_REF end_edge_idx, int class_id)
 
 TessLangModEdge (CubeRecoContext *cntxt, int class_id)
 
 ~TessLangModEdge ()
 
bool IsRoot () const
 
void SetRoot (bool flag)
 
bool IsOOD () const
 
bool IsNumber () const
 
bool IsEOW () const
 
const DawgGetDawg () const
 
EDGE_REF StartEdge () const
 
EDGE_REF EndEdge () const
 
EDGE_REF EdgeMask () const
 
const char_32EdgeString () const
 
int ClassID () const
 
int PathCost () const
 
void SetEdgeMask (EDGE_REF edge_mask)
 
void SetDawg (Dawg *dawg)
 
void SetStartEdge (EDGE_REF edge_idx)
 
void SetEndEdge (EDGE_REF edge_idx)
 
bool IsTerminal () const
 
int SignalCnt () const
 
double SignalWgt (int signal) const
 
void SetSignalWgt (int signal, double wgt)
 
int Signal (int signal)
 
unsigned int Hash () const
 
char * Description () const
 
bool IsIdentical (LangModEdge *lang_mod_edge) const
 
- Public Member Functions inherited from tesseract::LangModEdge
 LangModEdge ()
 
virtual ~LangModEdge ()
 

Static Public Member Functions

static int CreateChildren (CubeRecoContext *cntxt, const Dawg *edges, NODE_REF edge_reg, LangModEdge **lm_edges)
 

Detailed Description

Definition at line 68 of file tess_lang_mod_edge.h.

Constructor & Destructor Documentation

tesseract::TessLangModEdge::TessLangModEdge ( CubeRecoContext cntxt,
const Dawg dawg,
EDGE_REF  edge_idx,
int  class_id 
)

leading, trailing punc constructor and single byte UTF char

Definition at line 43 of file tess_lang_mod_edge.cpp.

44  {
45  root_ = false;
46  cntxt_ = cntxt;
47  dawg_ = dawg;
48  start_edge_ = edge_idx;
49  end_edge_ = edge_idx;
50  edge_mask_ = 0;
51  class_id_ = class_id;
52  str_ = cntxt_->CharacterSet()->ClassString(class_id);
53  path_cost_ = Cost();
54 }
CharSet * CharacterSet() const
const char_32 * ClassString(int class_id) const
Definition: char_set.h:104
tesseract::TessLangModEdge::TessLangModEdge ( CubeRecoContext cntxt,
const Dawg dawg,
EDGE_REF  start_edge_idx,
EDGE_REF  end_edge_idx,
int  class_id 
)

dict constructor: multi byte UTF char

Definition at line 59 of file tess_lang_mod_edge.cpp.

61  {
62  root_ = false;
63  cntxt_ = cntxt;
64  dawg_ = dawg;
65  start_edge_ = start_edge_idx;
66  end_edge_ = end_edge_idx;
67  edge_mask_ = 0;
68  class_id_ = class_id;
69  str_ = cntxt_->CharacterSet()->ClassString(class_id);
70  path_cost_ = Cost();
71 }
CharSet * CharacterSet() const
const char_32 * ClassString(int class_id) const
Definition: char_set.h:104
tesseract::TessLangModEdge::TessLangModEdge ( CubeRecoContext cntxt,
int  class_id 
)

Definition at line 28 of file tess_lang_mod_edge.cpp.

28  {
29  root_ = false;
30  cntxt_ = cntxt;
31  dawg_ = NULL;
32  start_edge_ = 0;
33  end_edge_ = 0;
34  edge_mask_ = 0;
35  class_id_ = class_id;
36  str_ = cntxt_->CharacterSet()->ClassString(class_id);
37  path_cost_ = Cost();
38 }
CharSet * CharacterSet() const
#define NULL
Definition: host.h:144
const char_32 * ClassString(int class_id) const
Definition: char_set.h:104
tesseract::TessLangModEdge::~TessLangModEdge ( )
inline

Definition at line 77 of file tess_lang_mod_edge.h.

77 {}

Member Function Documentation

int tesseract::TessLangModEdge::ClassID ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 102 of file tess_lang_mod_edge.h.

102 { return class_id_; }
int tesseract::TessLangModEdge::CreateChildren ( CubeRecoContext cntxt,
const Dawg edges,
NODE_REF  edge_reg,
LangModEdge **  lm_edges 
)
static

Definition at line 108 of file tess_lang_mod_edge.cpp.

111  {
112  int edge_cnt = 0;
113  NodeChildVector vec;
114  dawg->unichar_ids_of(parent_node, &vec, false); // find all children
115  for (int i = 0; i < vec.size(); ++i) {
116  const NodeChild &child = vec[i];
117  if (child.unichar_id == INVALID_UNICHAR_ID) continue;
118  edge_array[edge_cnt] =
119  new TessLangModEdge(cntxt, dawg, child.edge_ref, child.unichar_id);
120  if (edge_array[edge_cnt] != NULL) edge_cnt++;
121  }
122  return edge_cnt;
123 }
GenericVector< NodeChild > NodeChildVector
Definition: dawg.h:67
TessLangModEdge(CubeRecoContext *cntxt, const Dawg *edge_array, EDGE_REF edge, int class_id)
#define NULL
Definition: host.h:144
char * tesseract::TessLangModEdge::Description ( ) const
virtual

Implements tesseract::LangModEdge.

Definition at line 73 of file tess_lang_mod_edge.cpp.

73  {
74  char *char_ptr = new char[256];
75  if (!char_ptr) {
76  return NULL;
77  }
78 
79  char dawg_str[256];
80  char edge_str[32];
81  if (dawg_ == (Dawg *)DAWG_OOD) {
82  strcpy(dawg_str, "OOD");
83  } else if (dawg_ == (Dawg *)DAWG_NUMBER) {
84  strcpy(dawg_str, "NUM");
85  } else if (dawg_->permuter() == SYSTEM_DAWG_PERM) {
86  strcpy(dawg_str, "Main");
87  } else if (dawg_->permuter() == USER_DAWG_PERM) {
88  strcpy(dawg_str, "User");
89  } else if (dawg_->permuter() == DOC_DAWG_PERM) {
90  strcpy(dawg_str, "Doc");
91  } else {
92  strcpy(dawg_str, "N/A");
93  }
94 
95  sprintf(edge_str, "%d", static_cast<int>(start_edge_));
96  if (IsLeadingPuncEdge(edge_mask_)) {
97  strcat(edge_str, "-LP");
98  }
99  if (IsTrailingPuncEdge(edge_mask_)) {
100  strcat(edge_str, "-TP");
101  }
102  sprintf(char_ptr, "%s(%s)%s, Wtd Dawg Cost=%d",
103  dawg_str, edge_str, IsEOW() ? "-EOW-" : "", path_cost_);
104 
105  return char_ptr;
106 }
#define IsTrailingPuncEdge(edge_mask)
#define DAWG_NUMBER
#define IsLeadingPuncEdge(edge_mask)
#define NULL
Definition: host.h:144
#define DAWG_OOD
PermuterType permuter() const
Definition: dawg.h:129
EDGE_REF tesseract::TessLangModEdge::EdgeMask ( ) const
inline

Definition at line 100 of file tess_lang_mod_edge.h.

100 { return edge_mask_; }
const char_32* tesseract::TessLangModEdge::EdgeString ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 101 of file tess_lang_mod_edge.h.

101 { return str_; }
EDGE_REF tesseract::TessLangModEdge::EndEdge ( ) const
inline

Definition at line 99 of file tess_lang_mod_edge.h.

99 { return end_edge_; }
const Dawg* tesseract::TessLangModEdge::GetDawg ( ) const
inline

Definition at line 97 of file tess_lang_mod_edge.h.

97 { return dawg_; }
unsigned int tesseract::TessLangModEdge::Hash ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 178 of file tess_lang_mod_edge.h.

178  {
179  return static_cast<unsigned int>(
180  ((start_edge_ | end_edge_) ^ ((reinterpret_cast<uintptr_t>(dawg_)))) ^
181  ((unsigned int)edge_mask_) ^ class_id_);
182  }
bool tesseract::TessLangModEdge::IsEOW ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 93 of file tess_lang_mod_edge.h.

93  {
94  return (IsTerminal() || (dawg_->end_of_word(end_edge_) != 0));
95  }
virtual bool end_of_word(EDGE_REF edge_ref) const =0
bool tesseract::TessLangModEdge::IsIdentical ( LangModEdge lang_mod_edge) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 188 of file tess_lang_mod_edge.h.

188  {
189  return (class_id_ ==
190  reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->class_id_ &&
191  str_ == reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->str_ &&
192  dawg_ == reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->dawg_ &&
193  start_edge_ ==
194  reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->start_edge_ &&
195  end_edge_ ==
196  reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->end_edge_ &&
197  edge_mask_ ==
198  reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->edge_mask_);
199  }
bool tesseract::TessLangModEdge::IsNumber ( ) const
inline

Definition at line 89 of file tess_lang_mod_edge.h.

89  {
90  return (dawg_ == (Dawg *)DAWG_NUMBER);
91  }
#define DAWG_NUMBER
bool tesseract::TessLangModEdge::IsOOD ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 85 of file tess_lang_mod_edge.h.

85  {
86  return (dawg_ == (Dawg *)DAWG_OOD);
87  }
#define DAWG_OOD
bool tesseract::TessLangModEdge::IsRoot ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 80 of file tess_lang_mod_edge.h.

80  {
81  return root_;
82  }
bool tesseract::TessLangModEdge::IsTerminal ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 112 of file tess_lang_mod_edge.h.

112  {
113  return (IsOOD() || IsNumber() || IsTrailingPuncEdge(start_edge_) ||
114  dawg_->next_node(end_edge_) == 0);
115  }
#define IsTrailingPuncEdge(edge_mask)
virtual NODE_REF next_node(EDGE_REF edge_ref) const =0
int tesseract::TessLangModEdge::PathCost ( ) const
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 103 of file tess_lang_mod_edge.h.

103 { return path_cost_; }
void tesseract::TessLangModEdge::SetDawg ( Dawg dawg)
inline

Definition at line 105 of file tess_lang_mod_edge.h.

105 { dawg_ = dawg; }
void tesseract::TessLangModEdge::SetEdgeMask ( EDGE_REF  edge_mask)
inline

Definition at line 104 of file tess_lang_mod_edge.h.

104 { edge_mask_ = edge_mask; }
void tesseract::TessLangModEdge::SetEndEdge ( EDGE_REF  edge_idx)
inline

Definition at line 107 of file tess_lang_mod_edge.h.

107 { end_edge_ = edge_idx; }
void tesseract::TessLangModEdge::SetRoot ( bool  flag)
inlinevirtual

Implements tesseract::LangModEdge.

Definition at line 83 of file tess_lang_mod_edge.h.

83 { root_ = flag; }
void tesseract::TessLangModEdge::SetSignalWgt ( int  signal,
double  wgt 
)
inline

Definition at line 144 of file tess_lang_mod_edge.h.

144  {
145  CubeTuningParams *params =
146  reinterpret_cast<CubeTuningParams *>(cntxt_->Params());
147  if (params != NULL) {
148  switch (signal) {
149  case 0:
150  params->SetOODWgt(wgt);
151  break;
152 
153  case 1:
154  params->SetNumWgt(wgt);
155  break;
156  }
157  }
158  }
TuningParams * Params() const
#define NULL
Definition: host.h:144
void tesseract::TessLangModEdge::SetStartEdge ( EDGE_REF  edge_idx)
inline

Definition at line 106 of file tess_lang_mod_edge.h.

106 { start_edge_ = edge_idx; }
int tesseract::TessLangModEdge::Signal ( int  signal)
inline

Definition at line 161 of file tess_lang_mod_edge.h.

161  {
162  switch (signal) {
163  case 0:
164  return IsOOD() ? MIN_PROB_COST : 0;
165  break;
166 
167  case 1:
168  return IsNumber() ? MIN_PROB_COST : 0;
169  break;
170 
171  default:
172  return 0;
173  }
174  }
#define MIN_PROB_COST
Definition: cube_const.h:26
int tesseract::TessLangModEdge::SignalCnt ( ) const
inline

Definition at line 120 of file tess_lang_mod_edge.h.

120  {
121  return 2;
122  }
double tesseract::TessLangModEdge::SignalWgt ( int  signal) const
inline

Definition at line 125 of file tess_lang_mod_edge.h.

125  {
126  CubeTuningParams *params =
127  reinterpret_cast<CubeTuningParams *>(cntxt_->Params());
128  if (params != NULL) {
129  switch (signal) {
130  case 0:
131  return params->OODWgt();
132  break;
133 
134  case 1:
135  return params->NumWgt();
136  break;
137  }
138  }
139 
140  return 0.0;
141  }
TuningParams * Params() const
#define NULL
Definition: host.h:144
EDGE_REF tesseract::TessLangModEdge::StartEdge ( ) const
inline

Definition at line 98 of file tess_lang_mod_edge.h.

98 { return start_edge_; }

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