Tesseract
3.02
|
#include <tess_lang_mod_edge.h>
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 Dawg * | GetDawg () const |
EDGE_REF | StartEdge () const |
EDGE_REF | EndEdge () const |
EDGE_REF | EdgeMask () const |
const char_32 * | EdgeString () 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 |
Static Public Member Functions | |
static int | CreateChildren (CubeRecoContext *cntxt, const Dawg *edges, NODE_REF edge_reg, LangModEdge **lm_edges) |
Definition at line 68 of file tess_lang_mod_edge.h.
tesseract::TessLangModEdge::TessLangModEdge | ( | CubeRecoContext * | cntxt, |
const Dawg * | edge_array, | ||
EDGE_REF | edge, | ||
int | class_id | ||
) |
Definition at line 41 of file tess_lang_mod_edge.cpp.
{
root_ = false;
cntxt_ = cntxt;
dawg_ = dawg;
start_edge_ = edge_idx;
end_edge_ = edge_idx;
edge_mask_ = 0;
class_id_ = class_id;
str_ = cntxt_->CharacterSet()->ClassString(class_id);
path_cost_ = Cost();
}
tesseract::TessLangModEdge::TessLangModEdge | ( | CubeRecoContext * | cntxt, |
const Dawg * | edge_array, | ||
EDGE_REF | start_edge_idx, | ||
EDGE_REF | end_edge_idx, | ||
int | class_id | ||
) |
Definition at line 55 of file tess_lang_mod_edge.cpp.
{
root_ = false;
cntxt_ = cntxt;
dawg_ = dawg;
start_edge_ = start_edge_idx;
end_edge_ = end_edge_idx;
edge_mask_ = 0;
class_id_ = class_id;
str_ = cntxt_->CharacterSet()->ClassString(class_id);
path_cost_ = Cost();
}
tesseract::TessLangModEdge::TessLangModEdge | ( | CubeRecoContext * | cntxt, |
int | class_id | ||
) |
Definition at line 28 of file tess_lang_mod_edge.cpp.
{ root_ = false; cntxt_ = cntxt; dawg_ = NULL; start_edge_ = 0; end_edge_ = 0; edge_mask_ = 0; class_id_ = class_id; str_ = cntxt_->CharacterSet()->ClassString(class_id); path_cost_ = Cost(); }
tesseract::TessLangModEdge::~TessLangModEdge | ( | ) | [inline] |
Definition at line 77 of file tess_lang_mod_edge.h.
{}
int tesseract::TessLangModEdge::ClassID | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 102 of file tess_lang_mod_edge.h.
{ return class_id_; }
int tesseract::TessLangModEdge::CreateChildren | ( | CubeRecoContext * | cntxt, |
const Dawg * | edges, | ||
NODE_REF | edge_reg, | ||
LangModEdge ** | lm_edges | ||
) | [static] |
Definition at line 104 of file tess_lang_mod_edge.cpp.
{ int edge_cnt = 0; NodeChildVector vec; dawg->unichar_ids_of(parent_node, &vec); // find all children of the parent for (int i = 0; i < vec.size(); ++i) { const NodeChild &child = vec[i]; if (child.unichar_id == INVALID_UNICHAR_ID) continue; edge_array[edge_cnt] = new TessLangModEdge(cntxt, dawg, child.edge_ref, child.unichar_id); if (edge_array[edge_cnt] != NULL) edge_cnt++; } return edge_cnt; }
char * tesseract::TessLangModEdge::Description | ( | ) | const [virtual] |
Implements tesseract::LangModEdge.
Definition at line 69 of file tess_lang_mod_edge.cpp.
{ char *char_ptr = new char[256]; if (!char_ptr) { return NULL; } char dawg_str[256]; char edge_str[32]; if (dawg_ == (Dawg *)DAWG_OOD) { strcpy(dawg_str, "OOD"); } else if (dawg_ == (Dawg *)DAWG_NUMBER) { strcpy(dawg_str, "NUM"); } else if (dawg_->permuter() == SYSTEM_DAWG_PERM) { strcpy(dawg_str, "Main"); } else if (dawg_->permuter() == USER_DAWG_PERM) { strcpy(dawg_str, "User"); } else if (dawg_->permuter() == DOC_DAWG_PERM) { strcpy(dawg_str, "Doc"); } else { strcpy(dawg_str, "N/A"); } sprintf(edge_str, "%d", static_cast<int>(start_edge_)); if (IsLeadingPuncEdge(edge_mask_)) { strcat(edge_str, "-LP"); } if (IsTrailingPuncEdge(edge_mask_)) { strcat(edge_str, "-TP"); } sprintf(char_ptr, "%s(%s)%s, Wtd Dawg Cost=%d", dawg_str, edge_str, IsEOW() ? "-EOW-" : "", path_cost_); return char_ptr; }
EDGE_REF tesseract::TessLangModEdge::EdgeMask | ( | ) | const [inline] |
Definition at line 100 of file tess_lang_mod_edge.h.
{ return edge_mask_; }
const char_32* tesseract::TessLangModEdge::EdgeString | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 101 of file tess_lang_mod_edge.h.
{ return str_; }
EDGE_REF tesseract::TessLangModEdge::EndEdge | ( | ) | const [inline] |
Definition at line 99 of file tess_lang_mod_edge.h.
{ return end_edge_; }
const Dawg* tesseract::TessLangModEdge::GetDawg | ( | ) | const [inline] |
Definition at line 97 of file tess_lang_mod_edge.h.
{ return dawg_; }
unsigned int tesseract::TessLangModEdge::Hash | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 178 of file tess_lang_mod_edge.h.
{ return static_cast<unsigned int>(((start_edge_ | end_edge_) ^ ((reinterpret_cast<unsigned long int>(dawg_)))) ^ ((unsigned int)edge_mask_) ^ class_id_); }
bool tesseract::TessLangModEdge::IsEOW | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 93 of file tess_lang_mod_edge.h.
{ return (IsTerminal() || (dawg_->end_of_word(end_edge_) != 0)); }
bool tesseract::TessLangModEdge::IsIdentical | ( | LangModEdge * | lang_mod_edge | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 189 of file tess_lang_mod_edge.h.
{
return (class_id_ ==
reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->class_id_ &&
str_ == reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->str_ &&
dawg_ == reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->dawg_ &&
start_edge_ ==
reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->start_edge_ &&
end_edge_ ==
reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->end_edge_ &&
edge_mask_ ==
reinterpret_cast<TessLangModEdge *>(lang_mod_edge)->edge_mask_);
}
bool tesseract::TessLangModEdge::IsNumber | ( | ) | const [inline] |
Definition at line 89 of file tess_lang_mod_edge.h.
{ return (dawg_ == (Dawg *)DAWG_NUMBER); }
bool tesseract::TessLangModEdge::IsOOD | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 85 of file tess_lang_mod_edge.h.
{ return (dawg_ == (Dawg *)DAWG_OOD); }
bool tesseract::TessLangModEdge::IsRoot | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 80 of file tess_lang_mod_edge.h.
{
return root_;
}
bool tesseract::TessLangModEdge::IsTerminal | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 112 of file tess_lang_mod_edge.h.
{ return (IsOOD() || IsNumber() || IsTrailingPuncEdge(start_edge_) || dawg_->next_node(end_edge_) == 0); }
int tesseract::TessLangModEdge::PathCost | ( | ) | const [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 103 of file tess_lang_mod_edge.h.
{ return path_cost_; }
void tesseract::TessLangModEdge::SetDawg | ( | Dawg * | dawg | ) | [inline] |
Definition at line 105 of file tess_lang_mod_edge.h.
{ dawg_ = dawg; }
void tesseract::TessLangModEdge::SetEdgeMask | ( | EDGE_REF | edge_mask | ) | [inline] |
Definition at line 104 of file tess_lang_mod_edge.h.
{ edge_mask_ = edge_mask; }
void tesseract::TessLangModEdge::SetEndEdge | ( | EDGE_REF | edge_idx | ) | [inline] |
Definition at line 107 of file tess_lang_mod_edge.h.
{ end_edge_ = edge_idx; }
void tesseract::TessLangModEdge::SetRoot | ( | bool | flag | ) | [inline, virtual] |
Implements tesseract::LangModEdge.
Definition at line 83 of file tess_lang_mod_edge.h.
{ root_ = flag; }
void tesseract::TessLangModEdge::SetSignalWgt | ( | int | signal, |
double | wgt | ||
) | [inline] |
Definition at line 144 of file tess_lang_mod_edge.h.
{ CubeTuningParams *params = reinterpret_cast<CubeTuningParams *>(cntxt_->Params()); if (params != NULL) { switch (signal) { case 0: params->SetOODWgt(wgt); break; case 1: params->SetNumWgt(wgt); break; } } }
void tesseract::TessLangModEdge::SetStartEdge | ( | EDGE_REF | edge_idx | ) | [inline] |
Definition at line 106 of file tess_lang_mod_edge.h.
{ start_edge_ = edge_idx; }
int tesseract::TessLangModEdge::Signal | ( | int | signal | ) | [inline] |
Definition at line 161 of file tess_lang_mod_edge.h.
{ switch (signal) { case 0: return IsOOD() ? MIN_PROB_COST : 0; break; case 1: return IsNumber() ? MIN_PROB_COST : 0; break; default: return 0; } }
int tesseract::TessLangModEdge::SignalCnt | ( | ) | const [inline] |
Definition at line 120 of file tess_lang_mod_edge.h.
{
return 2;
}
double tesseract::TessLangModEdge::SignalWgt | ( | int | signal | ) | const [inline] |
Definition at line 125 of file tess_lang_mod_edge.h.
{ CubeTuningParams *params = reinterpret_cast<CubeTuningParams *>(cntxt_->Params()); if (params != NULL) { switch (signal) { case 0: return params->OODWgt(); break; case 1: return params->NumWgt(); break; } } return 0.0; }
EDGE_REF tesseract::TessLangModEdge::StartEdge | ( | ) | const [inline] |
Definition at line 98 of file tess_lang_mod_edge.h.
{ return start_edge_; }