// file: trace_projector.h
//
// definitions file for the trace projection utility that uses the decoder
// and its associated classes
//

// make sure definitions are made only once
//
#ifndef __ISIP_TRACE_PROJECTOR
#define __ISIP_TRACE_PROJECTOR

// isip include files
//
#ifndef __ISIP_INTEGRAL
#include <integral.h>
#endif

// forward declaration of classes
//
#ifndef __ISIP_DECODER
#include <decoder.h>
#endif

// Decoder: the main decoder class that implements a lexical-tree
// based Viterbi search
//
class Trace_projector {

  //---------------------------------------------------------------------------
  //
  // public data
  //
  //---------------------------------------------------------------------------
public:

  // decoder
  //
  Decoder* decoder_d;

  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // variables to hold commandline parameters
  //
  logical_1 demo_flag_d;

  // variables to hold data in parameters file
  //
  char_1* monophones_file_d;
  char_1* transitions_file_d;
  char_1* states_file_d;
  char_1* models_file_d;
  char_1* phones_file_d;
  
  char_1* lexicon_file_d;
  char_1* lm_file_d;
  char_1* gram_list_file_d;

  char_1* forcealign_file_d;
  char_1* lattice_file_d;
  char_1* outlat_file_d;
  char_1* latwer_file_d;

  char_1* input_file_d;
  char_1* output_file_d;
  char_1* outnbest_file_d;
  char_1* model_segment_file_d;
  
  int_4 ngram_size_d;
  int_4 num_nbest_d;
  int_4 num_hist_d;

  // language model
  //
  float_4 word_penalty_d;
  float_4 lm_scale_d;
  
  // default function is cross-word lattice rescoring mode with word
  // alignments and binary mfcc input
  //
  int_4 function_mode_d;
  int_4 context_mode_d;
  int_4 align_mode_d;
  int_4 input_format_d;
  int_4 input_feature_format_d;
  int_4 delta_win_d;
  logical_1 delta_d;
  logical_1 acc_d;
  int_4 context_size_d;
  
  // pruning thresholds and parameters
  //
  int_4 mapmi_limit_d;
  int_4 num_wdcut_d;
  int_4 num_levels_d;
  float_4* beam_width_d;

  // nbest pruning parameters
  //
  int_4 nbest_max_paths_d;
  int_4 nbest_beam_d;
  
  // frontend parameter file
  //
  char_1* frontend_params_d;

  // determine if decoder outputs compacted lattice
  //
  logical_1 compact_lattice_d;

  // communicator flag
  //
  logical_1 isCommunicator_d;

  // segment level mode
  //
  int_4 segment_mode_d;
  
  //---------------------------------------------------------------------------
  //
  // public methods
  //
  //---------------------------------------------------------------------------
public:
 
  // destructors/constructors
  //
  ~Trace_projector();
  Trace_projector();
  Trace_projector(char_1*& param_file, logical_1& demo_flag);

  // functions to read the parameters file
  //
  logical_1 read_params_cc(FILE*& fp);

  // functions to configure the docoder according to parameter file
  //
  logical_1 config_decoder_cc(logical_1 demo_flag = ISIP_FALSE,
			      logical_1 isCommunicator = ISIP_FALSE);

  // core computational method
  //
  logical_1 compute_cc();
  logical_1 get_hypo_cc(char_1*& hypo, char_1*& align);
  
  // get methods
  //
  char_1* get_frontend_params();

  // initialize before decoding
  //
  logical_1 init_cc();

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

  // functions to load acoustic model data into the decoder
  //
  logical_1 load_ac_models_cc();

  // function to handle file i/o
  //
  logical_1 open_file_cc(FILE*& fp, char_1* file_name, char_1* mode);

  // load models especially for communicator
  //
  logical_1 load_models_cc();    
};
  
  // end of file
  //
#endif
