{
if (!lang_mod)
if (!lang_mod) {
fprintf(stderr, "Cube ERROR (BeamSearch::Search): could not construct "
"LangModel\n");
}
Cleanup();
seg_pt_cnt_ = srch_obj->SegPtCnt();
if (seg_pt_cnt_ < 0) {
}
col_cnt_ = seg_pt_cnt_ + 1;
if (seg_pt_cnt_ > 128) {
fprintf(stderr, "Cube ERROR (BeamSearch::Search): segment point count is "
"suspiciously high; bailing out\n");
}
col_ = new SearchColumn *[col_cnt_];
if (!col_) {
fprintf(stderr, "Cube ERROR (BeamSearch::Search): could not construct "
"SearchColumn array\n");
}
memset(col_, 0, col_cnt_ * sizeof(*col_));
for (int end_seg = 1; end_seg <= (seg_pt_cnt_ + 1); end_seg++) {
col_[end_seg - 1] = new SearchColumn(end_seg - 1,
if (!col_[end_seg - 1]) {
fprintf(stderr, "Cube ERROR (BeamSearch::Search): could not construct "
"SearchColumn for column %d\n", end_seg - 1);
}
for (int strt_seg = init_seg; strt_seg < end_seg; strt_seg++) {
int parent_nodes_cnt;
SearchNode **parent_nodes;
if (strt_seg == 0) {
parent_nodes_cnt = 1;
} else {
parent_nodes_cnt = col_[strt_seg - 1]->
NodeCount();
parent_nodes = col_[strt_seg - 1]->
Nodes();
}
CharAltList *char_alt_list = srch_obj->RecognizeSegment(strt_seg - 1,
end_seg - 1);
for (int parent_idx = 0; parent_idx < parent_nodes_cnt; parent_idx++) {
SearchNode *parent_node = !parent_nodes ?
NULL
: parent_nodes[parent_idx];
LangModEdge *lm_parent_edge = !parent_node ? lang_mod->Root()
: parent_node->LangModelEdge();
int contig_cost = srch_obj->NoSpaceCost(strt_seg - 1, end_seg - 1);
int no_space_cost = 0;
if (!word_mode_ && strt_seg > 0) {
no_space_cost = srch_obj->NoSpaceCost(strt_seg - 1);
}
CreateChildren(col_[end_seg - 1], lang_mod, parent_node,
lm_parent_edge, char_alt_list,
contig_cost + no_space_cost);
}
if (!word_mode_ && strt_seg > 0) {
if (parent_node->LangModelEdge()->IsEOW()) {
int space_cost = srch_obj->SpaceCost(strt_seg - 1);
CreateChildren(col_[end_seg - 1], lang_mod, parent_node,
NULL,
char_alt_list, contig_cost + space_cost);
}
}
}
}
}
col_[end_seg - 1]->
Prune();
}
WordAltList *alt_list = CreateWordAltList(srch_obj);
return alt_list;
}