33 int char_reco_cost,
LangModEdge *edge,
int col_idx) {
36 lang_mod_edge_ = edge;
38 parent_node_ = parent_node;
39 char_reco_cost_ = char_reco_cost;
42 str_ = (edge == NULL ? NULL : edge->
EdgeString());
45 best_path_reco_cost_ = (parent_node_ == NULL) ? 0 :
49 best_path_len_ = (parent_node_ == NULL) ?
51 if (edge != NULL && edge->
IsRoot() && parent_node_ != NULL) {
56 mean_char_reco_cost_ =
static_cast<int>(
57 (best_path_reco_cost_ + char_reco_cost_) /
58 static_cast<double>(best_path_len_));
61 int lm_cost =
LangModCost(lang_mod_edge_, parent_node_);
65 (best_path_reco_cost_ + char_reco_cost_) /
66 static_cast<double>(best_path_len_)
71 if (lang_mod_edge_ != NULL) {
72 delete lang_mod_edge_;
79 if (lang_mod_edge_ == NULL) {
80 if (new_edge != NULL) {
86 if (new_edge == NULL || !lang_mod_edge_->
IsIdentical(new_edge) ||
93 int new_best_path_reco_cost;
95 int new_best_path_len;
97 new_best_path_reco_cost = (new_parent == NULL) ?
104 int new_lm_cost =
LangModCost(new_edge, new_parent);
107 (new_best_path_reco_cost + new_reco_cost) /
108 static_cast<double>(new_best_path_len)
112 if (best_cost_ > new_cost) {
113 parent_node_ = new_parent;
114 char_reco_cost_ = new_reco_cost;
115 best_path_reco_cost_ = new_best_path_reco_cost;
116 best_path_len_ = new_best_path_len;
117 mean_char_reco_cost_ =
static_cast<int>(
118 (best_path_reco_cost_ + char_reco_cost_) /
119 static_cast<double>(best_path_len_));
121 (best_path_reco_cost_ + char_reco_cost_) /
122 static_cast<double>(best_path_len_)
135 while (node != NULL) {
136 if (node->str_ != NULL) {
146 node = node->parent_node_;
154 char_ptr[ch_idx--] = 0;
156 while (node != NULL) {
158 while (str_len > 0) {
159 char_ptr[ch_idx--] = node->str_[--str_len];
165 char_ptr[ch_idx--] = (
char_32)
' ';
168 node = node->parent_node_;
176 if (node1 != NULL && node2 != NULL &&
177 node1->best_path_len_ != node2->best_path_len_) {
182 while (node1 != NULL && node2 != NULL) {
183 if (node1->str_ != node2->str_) {
192 node1 = node1->parent_node_;
193 node2 = node2->parent_node_;
196 return ((node1 == NULL && node2 == NULL) ||
209 bool is_root = ((current_lm_edge != NULL && current_lm_edge->
IsRoot()) ||
210 parent_node == NULL);
213 lm_cost += (current_lm_edge == NULL ? 0 : current_lm_edge->
PathCost());
217 if (parent_node == NULL) {
227 return static_cast<int>(lm_cost /
static_cast<double>(node_cnt));
bool UpdateParent(SearchNode *new_parent, int new_reco_cost, LangModEdge *new_edge)
static bool IdenticalPath(SearchNode *node1, SearchNode *node2)
SearchNode * ParentNode()
virtual const char_32 * EdgeString() const =0
virtual bool IsIdentical(LangModEdge *edge) const =0
LangModEdge * LangModelEdge()
TuningParams * Params() const
static int StrLen(const char_32 *str)
virtual int PathCost() const =0
virtual bool IsRoot() const =0
SearchNode(CubeRecoContext *cntxt, SearchNode *parent_node, int char_reco_cost, LangModEdge *edge, int col_idx)