103 fprintf(stderr,
"Cube ERROR (BeamSearch::Search): could not construct "
112 seg_pt_cnt_ = srch_obj->SegPtCnt();
113 if (seg_pt_cnt_ < 0) {
116 col_cnt_ = seg_pt_cnt_ + 1;
119 if (seg_pt_cnt_ > 128) {
120 fprintf(stderr,
"Cube ERROR (BeamSearch::Search): segment point count is "
121 "suspiciously high; bailing out\n");
126 col_ =
new SearchColumn *[col_cnt_];
128 fprintf(stderr,
"Cube ERROR (BeamSearch::Search): could not construct "
129 "SearchColumn array\n");
132 memset(col_, 0, col_cnt_ *
sizeof(*col_));
135 for (
int end_seg = 1; end_seg <= (seg_pt_cnt_ + 1); end_seg++) {
137 col_[end_seg - 1] =
new SearchColumn(end_seg - 1,
139 if (!col_[end_seg - 1]) {
140 fprintf(stderr,
"Cube ERROR (BeamSearch::Search): could not construct "
141 "SearchColumn for column %d\n", end_seg - 1);
147 for (
int strt_seg = init_seg; strt_seg < end_seg; strt_seg++) {
148 int parent_nodes_cnt;
149 SearchNode **parent_nodes;
153 parent_nodes_cnt = 1;
157 parent_nodes_cnt = col_[strt_seg - 1]->
NodeCount();
158 parent_nodes = col_[strt_seg - 1]->
Nodes();
162 CharAltList *char_alt_list = srch_obj->RecognizeSegment(strt_seg - 1,
165 for (
int parent_idx = 0; parent_idx < parent_nodes_cnt; parent_idx++) {
167 SearchNode *parent_node = !parent_nodes ?
NULL
168 : parent_nodes[parent_idx];
169 LangModEdge *lm_parent_edge = !parent_node ? lang_mod->Root()
170 : parent_node->LangModelEdge();
173 int contig_cost = srch_obj->NoSpaceCost(strt_seg - 1, end_seg - 1);
177 int no_space_cost = 0;
178 if (!word_mode_ && strt_seg > 0) {
179 no_space_cost = srch_obj->NoSpaceCost(strt_seg - 1);
185 CreateChildren(col_[end_seg - 1], lang_mod, parent_node,
186 lm_parent_edge, char_alt_list,
187 contig_cost + no_space_cost);
191 if (!word_mode_ && strt_seg > 0) {
193 if (parent_node->LangModelEdge()->IsEOW()) {
195 int space_cost = srch_obj->SpaceCost(strt_seg - 1);
200 CreateChildren(col_[end_seg - 1], lang_mod, parent_node,
NULL,
201 char_alt_list, contig_cost + space_cost);
209 col_[end_seg - 1]->
Prune();
215 WordAltList *alt_list = CreateWordAltList(srch_obj);
LangModel * LangMod() const
int MaxSegPerChar() const
TuningParams * Params() const
SearchNode ** Nodes() const