📄 hsrch_15.cc
字号:
// file: $isip/class/search/HierarchicalSearch/hsrch_14.cc// version: $Id: hsrch_15.cc,v 1.7 2003/04/14 16:12:53 huang Exp $//// isip include files//#include "HierarchicalSearch.h"// method: applyNSymbolScore//// arguments:// Instance* instance_a: (input) current instances// long level_num_a: (input) the search level//// return: logical error status//// this method apply a n-symbol score to current instance//boolean HierarchicalSearch::applyNSymbolScore(Instance*& curr_instance_a, long level_num_a){ // local variable // Context* curr_context = (Context*)NULL; // add the N-symbol score // if ( ! getSearchLevel(level_num_a).useNSymbol() ){ // exit gracefully // return false; } // get current n-symbol // curr_context = curr_instance_a->getSymbol(); if ( curr_context->getCentralVertex() == (GraphVertex<SearchNode>*)NULL ) { // exit gracefully // return false; } else if ( curr_context->getCentralVertex()->isTerm() || curr_context->getCentralVertex()->isStart()){ // exit gracefully // return false; } else if ( curr_context->getCentralVertex()->getItem()->isDummyNode() ){ // exit gracefully // return false; } // can't apply lower level n-symbol probabilities // else if (curr_context->getCentralVertex()->getItem()-> getSearchLevel()->getLevelIndex() > level_num_a) { // exit gracefully // return false; } // apply the n-symbol probability at the same level // the nsymbol probability becomes the fact now. // else if (curr_context->getCentralVertex()->getItem()-> getSearchLevel()->getLevelIndex() == level_num_a) { shiftNSymbol(curr_instance_a, level_num_a, curr_context->getCentralVertex()); float posterior_score = getPosteriorScore(curr_instance_a->getNSymbol(), level_num_a); // add the n-symbol probability // addInstanceScore(curr_instance_a, posterior_score, level_num_a, false); // set previous score at this level to 0 // // curr_instance_a->setPreNSymbolScore(level_num_a, 0 ); } // apply n-symbol probability to a higher level // else if (curr_context->getCentralVertex()->getItem()-> getSearchLevel()->getLevelIndex() < level_num_a) { // for the next step // return false; /* // get the order of language model // lm_order = getSearchLevel(level_num_a).getNSymbolOrder(); // convert the context into symbol indices // for (long i= 1; i < lm_order; i++) { symbol_indices(i-1) = (*tmp_context)(-lm_order + i); } delete tmp_context; // get the n-symbol probability // if (! getMaxium(level_num_a, getSearchLevel(level_num_a).getNSymbolModel(), symbol_indices, curr_context->getCentralVertex(), score, false)) { // don't need to change the n-symbol score return false; } // add the n-symbol probability // addInstanceScore(curr_instance_a, score, level_num_a, false); */ } // exit gracefully // return true;}// method: addInstanceScore//// arguments:// Instance*& instance_a: (input) the endpoint of the new arc// float score_a: (input) the score to be added// long level_num_a: (input) the search level// boolean weight_score_a: (input) this is a weight score or not//// return: logical error status//// add score to a instance, lm_scale and tr_scale will be used here//boolean HierarchicalSearch::addInstanceScore(Instance*& curr_instance_a, float score_a, long level_num_a, boolean weight_score_a) { // local variable // float tr_scale = 1.0; float score = 0.0; // add the score from weight // if (weight_score_a){ // get the score // score = curr_instance_a->getScore(); // add the weight // score += score_a*tr_scale; curr_instance_a->setScore(score); } // add the N-symbol score // else if ( getSearchLevel(level_num_a).useNSymbol() ){ // get the score // score = curr_instance_a->getScore(); score += score_a; // set pre score // curr_instance_a->setScore(score); } return true;}/*codes for next step - spread language model score // method: getMaxScore//// arguments:// long level_num_a: (input) the search level//// return: logical error status//// print an arc created in the hypothesis space//boolean HierarchicalSearch::getMaxScore(long& level_num_a, NGramModel& nsymbol_model_a, VectorLong& symbol_index_a, GraphVertex<SearchNode>*& start_vertex_a, float score_a, boolean recursive_a){ // local variable // float max_score = (float)Integral::MIN_LOG_VALUE; Context* tmp_context = (Context*)NULL; Context* curr_context = (Context*)NULL; VectorLong symbol_indices; GraphVertex<SearchNode> succ_vert = GraphVertex<SearchNode>* NULL; GraphArc<SearchNode> succ_vert = GraphArc<SearchNode>* NULL; // need to avoid search for the same score // if ( (curr_instance_a->getPreNSymbolScore() != 0) && (start_vertex_a->length() <= 1) && !recursive_a ) { score_a = 0; // exit, don't need to change the n-symbol score // return false; } // set the initial value // score_a = max_score; // loop throught all successors // for ( more_arcs = start_vertex_a->gotoFirst(); more_arcs; more_arcs = start_vertex_a->gotoNext() ) { // get current arc // curr_arc = start_vertex_a->getCurr(); // get the successor // succ_vertex = curr_arc->getVertex(); SearchNode* succ_node = (LexicalNode*)succ_vertex->getItem(); // if it is a NULL node // if (succ_node == (LexicalNode*)NULL){ return Error::handle(name(), L"getMaxScore: invalid lexical tree node", Error::NULL_ARG, __FILE__, __LINE__); } else if ( succ_vertex->isStart() || succ_vertex->isTerm() ){ return Error::handle(name(), L"getMaxScore: invalid lexical tree node", Error::NULL_ARG, __FILE__, __LINE__); } // if in the middle of the tree // else if ( succ_node->isDummyNode() || succ_node->getSearchLevel()->getLevelIndex() != level_num_a ){ // call this function recursively // getMaxScore(level_num_a, nsymbol_model_a, symbol_index_a, succ_vertex, score_a, true); } // if we reach the word we needed // else if ( succ_node->getSearchLevel()->getLevelIndex() == level_num_a ){ // get this symbol's Id // long last_index = symbol_indices_a.length() - 1; symbol_indices_a(last_index) = succ_node->getSymbolId(); // get the n-symbol probability // max_score = nsymbol_model_a.getScore(symbol_indices_a); // change the score // score_a = score_a >= max_score ? score_a : max_score; } else { // not implemented yet // return Error::handle(name(), L"getMaxScore: incorrect node", Error::NOT_IMPLEM, __FILE__, __LINE__); } } // exit gracefully // return true; }*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -