// file: dec_clean_0.cc
//

// isip include files
//
#include "decoder.h"
#include "decoder_constants.h"
 
// method: constructor
//
// arguments: none
//
// return:  a logical_1 indicating status
//
// this method initializes decoder parameters for decoding a list of
// utterances
//
logical_1 Decoder::init_cc() {

  // reset the number of decoded utterances
  //
  num_utt_d = (int_4)0;
  
  // allocate count of trace generation
  //
  num_traces_total_d = new int_4[num_levels_d];
  num_traces_gen_d = new int_4[num_levels_d];
  num_traces_del_d = new int_4[num_levels_d];
  total_gen_d = new int_4[num_levels_d];
  total_del_d = new int_4[num_levels_d];

  // allocate the score and beam threshold arrays
  //
  max_score_d = new float_4[num_levels_d];
  beam_thresh_d = new float_4[num_levels_d];
  
  // initialize the nbest array
  //
  nbest_d = new Trace*[num_nbest_d];

  // find the special model values
  //
  find_sp_cc();
  find_sil_cc();

  // initialize feature vector
  //
  features_d = new float_4[num_feat_d];

  // allocate a list of active phones and an array of link lists of
  // traces for each phone
  //
  num_active_models_d = (int_4)0;
  active_models_d = new int_4[num_cd_d];
  model_trlist_d = new Link_list*[num_cd_d];

  // allocate a list of active words and create an array of link lists
  // of traces for each word
  //
  num_active_words_d = (int_4)0;
  active_words_d = new int_4[num_words_d];
  word_trlist_d = new Link_list*[num_words_d];
  word_scores_d = new float_4[num_words_d];
  
  // if this requires decoding an n-gram LM
  //
  if ((function_mode_d == DEC_NGRAM_DECODE_FUNCTION) ||
      (function_mode_d == DEC_LATTICE_GENERATE_FUNCTION)) {
    
    // create a list to store the active lexical trees
    //
    lextree_list_d = new Link_list();

    // set up the ngram lexical tree
    //
    proto_tree_d = new Lex_tree();
    proto_tree_d->build_tree_cc(ngram_d, lexicon_d);
    
    // get a list of sentence start words
    //
    Word* word = (Word*)((lexicon_d->hash_lookup_cc(WRD_SENT_START))->
			 get_item_cc());
    Ngram_node* ngnode = ngram_d->get_unigram_cc(word);

    // set up the sentence start tree to be used only at the beginning
    // of each utterance
    //
    Lex_tree* tree = new Lex_tree();
    tree->build_tree_cc((int_4)1, &ngnode);
    lextree_list_d->insert_cc(tree);
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
