/**************************************************************************/ /* File: score_hyp.cc */ /**************************************************************************/ /* Project: Continuous Speech Recognition Search Algorithms */ /* Author: Neeraj Deshmukh, Aravind Ganapathiraju */ /* Class: EE 8993 Spring 1996 Date: March 12, 1996 */ /**************************************************************************/ /*======================================================================== This file defines the hypothesis score class that models the various hypotheses for the EE 8993 speech recognizer ========================================================================*/ /*------------------------------------------------------------------------ system and ISIP include files ------------------------------------------------------------------------*/ #include "score_hyp.h" /*========================================================================== function definitions fror class Score_Hyp =========================================================================*/ /*--------------------------- constructors and destructor ---------------------------*/ // default constructor // Score_Hyp :: Score_Hyp ( HMM_State *curr_state_l, int_2 fr_ind_l) : Linked_List ( curr_state_l ) { word_index_d = 0; frame_index_d = fr_ind_l; total_path_score_d = 0; hyp_back_ptr_d = NULL; } // copy constructor // Score_Hyp :: Score_Hyp (const Score_Hyp &hyp_score_l) { // copy all elements // frame_index_d = hyp_score_l.frame_index_d; word_index_d = hyp_score_l.word_index_d; total_path_score_d = hyp_score_l.total_path_score_d; hyp_back_ptr_d = hyp_score_l.hyp_back_ptr_d; } // destructor // Score_Hyp :: ~Score_Hyp () { // free memory // } /*---------------------- input / output methods ----------------------*/ // set the path score to specified value // void Score_Hyp :: set_path_score_cc (float_4 new_score_l) { total_path_score_d = new_score_l; } // increment the path score with specified amount // void Score_Hyp :: update_path_score_l (float_4 incr_score_l) { total_path_score_d += incr_score_l; } // output the total path score // float_4 Score_Hyp :: get_path_score_cc () const { return (total_path_score_d); } /*------------------------- frame / timestamp/ flag methods -------------------------*/ // check if the timestamp warrants this structure to be set free // BOOL Score_Hyp :: check_timestamp_cc (int_2 fr_ind_l) { // check the timestamp to see if the structure is current // if (frame_index_d >= fr_ind_l + HYP_DEAD_TIME) return (FALSE); return (TRUE); } // set the timestamp to specified value // void Score_Hyp :: set_timestamp_cc (int_2 fr_ind_l) { frame_index_d = fr_ind_l; } // update the time stamp to reflect current frame // void Score_Hyp :: increment_timestamp_cc () { frame_index_d ++; } // output the current timestamp // int_2 Score_Hyp :: get_timestamp_cc () const { return (frame_index_d); } void Score_Hyp :: set_word_index_cc (int_2 word_index_l) { word_index_d = word_index_l; } int_2 Score_Hyp :: get_word_index_cc () { return (word_index_d); } /*------------------------- state and backpointer etc -------------------------*/ // add new score_hyp to the present list // Score_Hyp *Score_Hyp :: add_score_hyp_cc (HMM_State *curr_state_l, Score_Hyp *back_ptr_l, float_4 score_l, int_2 frame_index_l, int_2 word_index_l) { Score_Hyp *new_score_ptr = new Score_Hyp (curr_state_l,frame_index_l); // add this at the head of the list // new_score_ptr->next_link_ptr = next_link_ptr; new_score_ptr->prev_link_ptr = this; if ( next_link_ptr != NULL) ((Score_Hyp *)next_link_ptr)->prev_link_ptr = new_score_ptr; next_link_ptr = new_score_ptr; new_score_ptr->hyp_back_ptr_d = back_ptr_l; new_score_ptr->set_word_index_cc (word_index_l); if ( back_ptr_l != NULL ) { new_score_ptr->total_path_score_d = (back_ptr_l->total_path_score_d + score_l); } else { new_score_ptr->total_path_score_d = 0; } // return the head of the linked list // return (new_score_ptr); } // delete a score_hyp from the linked list of score_hyp's // void Score_Hyp :: remove_score_hyp_cc () { Score_Hyp *prev_ptr = (Score_Hyp *) prev_link_ptr; Score_Hyp *next_ptr = (Score_Hyp *) next_link_ptr; prev_ptr->next_link_ptr = next_ptr; next_ptr->prev_link_ptr = prev_ptr; hyp_back_ptr_d = NULL; delete [] element_ptr; } // find the score hyp with the given state as current state and // given time index // Score_Hyp* Score_Hyp :: find_score_hyp_cc ( HMM_State *state_ptr_l, int_2 frm_ind_l ) { Score_Hyp *temp_hyp; for(temp_hyp = this->get_next_hyp_cc () ; temp_hyp->get_next_hyp_cc () != NULL; temp_hyp = temp_hyp->get_next_hyp_cc ()) { HMM_State *temp_state = (HMM_State *)temp_hyp->get_element_cc (); if ( strcmp(state_ptr_l->get_out_symbol_cc (), temp_state->get_out_symbol_cc ()) == 0 && frm_ind_l == temp_hyp->get_timestamp_cc ()) { return (temp_hyp); } } // else return NULL // return (NULL); } // set the backpointer // void Score_Hyp :: set_back_ptr_cc (Score_Hyp *back_ptr_l) { hyp_back_ptr_d = back_ptr_l; } //get the back pointer // Score_Hyp *Score_Hyp :: get_back_ptr_cc () { return (hyp_back_ptr_d); } // get the next element in the list // Score_Hyp *Score_Hyp::get_next_hyp_cc() { return ((Score_Hyp*)next_link_ptr); } // get the prev element in the list // Score_Hyp *Score_Hyp::get_prev_hyp_cc() { return ((Score_Hyp*)prev_link_ptr); } /*--------------------------- back tracing the hypothesis ---------------------------*/ void Score_Hyp :: hyp_backtrace_cc () { Score_Hyp *temp_hyp; HMM_State *temp; temp_hyp = this; while ( temp_hyp->get_timestamp_cc () != 0 ) { temp = (HMM_State *)temp_hyp->get_element_cc (); fprintf(stdout," %s ", temp->get_out_symbol_cc ()); temp_hyp = temp_hyp->get_back_ptr_cc (); } fprintf (stdout, "\n"); } void Score_Hyp :: word_backtrace_cc (HMM_Model **hmm_model_l, int_2 num_models_l) { Score_Hyp *temp_hyp; int_2 num_str = 0; // count number of strings // temp_hyp = this; while ( temp_hyp->get_timestamp_cc () != 0) { for ( int_2 i = 0; i < num_models_l; i++) { if ((HMM_State *)temp_hyp->get_element_cc () == hmm_model_l [i]->get_stop_state_cc ()) { num_str ++; } } temp_hyp = temp_hyp->get_back_ptr_cc (); } // store strings in array // String *mod_names = new String[num_str]; temp_hyp = this; int_2 ct = num_str; while ( temp_hyp->get_timestamp_cc () != 0) { for ( int_2 i = 0; i < num_models_l; i++) { if ((HMM_State *)temp_hyp->get_element_cc () == hmm_model_l [i]->get_stop_state_cc ()) { ct --; mod_names[ct] = hmm_model_l[temp_hyp->get_word_index_cc ()]->get_model_symbol_cc (); } } temp_hyp = temp_hyp->get_back_ptr_cc (); } for (int j = 0; j < num_str; j++) fprintf (stdout, "%s ", mod_names[j]); fprintf (stdout, "\n"); }