// file: $isip/class/asr/SpeechRecognizer/SpeechRecognizer.h
// version: $Id: SpeechRecognizer.h 9834 2004-10-11 18:14:53Z raghavan $
//

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

#ifndef ISIP_HIDDEN_MARKOV_MODEL
#include <HiddenMarkovModel.h>
#endif


// SpeechRecognizer:  a class to set up parameters of the SpeechRecognizer
//                    system and run it
//
class SpeechRecognizer {
  
  //--------------------------------------------------------------------------
  //
  // public constants
  //
  //--------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;

  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  
  static const long ERR = (long)110000;

  // define algorithm types
  //
  enum ALGORITHM { HMM = 0, BN, NN, DEF_ALGORITHM = HMM };

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

  // algorithm type
  //
  ALGORITHM algorithm_d;

  // verification mode flag
  //
  boolean verify_d;
  
  // parameter file
  //
  Filename param_file_name_d;  
  
  // hidden markov model object
  //
  HiddenMarkovModel hmm_d;

  // debug level
  //
  static Integral::DEBUG debug_level_d;

  // verbosity
  //
  static Integral::DEBUG verbosity_d;
  
  // static memory manager
  //
  static MemoryManager mgr_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }

  // other static methods
  //   
  static boolean diagnose(Integral::DEBUG debug_level);

  // method: setDebug
  //
  boolean setDebug(Integral::DEBUG debug_level) {
    debug_level_d = debug_level;
    return true;
  }
  
  // constructor(s)/destructor(s)
  //
  SpeechRecognizer();
  SpeechRecognizer(const SpeechRecognizer& arg);
  ~SpeechRecognizer();

  // assign method
  //
  boolean assign(const SpeechRecognizer& arg); 
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------

  // method: setStream
  //
  boolean setStream(boolean stream){
    return hmm_d.setStream(stream);
  }
  
  // method: setAlgorithm
  //
  boolean setAlgorithm(ALGORITHM algorithm) {
    algorithm_d = algorithm;
    return true;
  }

  // method: setParam
  //
  boolean setParam(String param_file_name);
  
  // method: setVerbosity
  //
  boolean setVerbosity(Integral::DEBUG verbosity) {
    verbosity_d = verbosity;
    return true;
  }
  
  // method: setVerify
  //
  boolean setVerify(boolean verify) {
    verify_d = verify;
    return true;  
  }

  // method: setLanguageModelFile
  //
  boolean setLanguageModelFile(String& lm_file) {
    if (lm_file.length() != 0) {
      return hmm_d.setLanguageModelFile(lm_file);
    }
    return false;  
  }

  // method: setLanguageModelUpdateFile
  //
  boolean setLanguageModelUpdateFile(String& lm_file) {
    if (lm_file.length() != 0) {
      return hmm_d.setLanguageModelUpdateFile(lm_file);
    }
    return false;  
  }  

  // method: setStatisticalModelPoolFile
  //
  boolean setStatisticalModelPoolFile(String& ac_file) {
    if (ac_file.length() != 0) {
      return hmm_d.setStatisticalModelPoolFile(ac_file);
    }
    return false;  
  }

  // method: setStatisticalModelPoolUpdateFile
  //
  boolean setStatisticalModelPoolUpdateFile(String& ac_file) {
    if (ac_file.length() != 0) {
      return hmm_d.setStatisticalModelPoolUpdateFile(ac_file);
    }
    return false;  
  }    
  
  // method: setFunctionMode
  //
  boolean setFunctionMode(String& function_mode) {
    if (function_mode.length() != 0) {
      return hmm_d.setFunctionMode(function_mode);
    }
    return false;  
  }

  // method: setOutputMode
  //
  boolean setOutputMode(String& output_mode) {
    if (output_mode.length() != 0) {
      return hmm_d.setOutputMode(output_mode);
    }
    return false;  
  }  

  // method: setOutputFormat
  //
  boolean setOutputFormat(String& output_format) {
   if (output_format.length() != 0) {
     return hmm_d.setOutputFormat(output_format);
   }
   return false;  
  }

  // method: setAccumulatorFile
  //
  boolean setAccumulatorFile(Filename& accum_file) {
    if (accum_file.length() != 0) {
      return hmm_d.setAccumulatorFile(accum_file);
    }
    return false;  
  }

  // method: setAccumulatorList
  //
  boolean setAccumulatorList(Filename& accum_list) {
    if (accum_list.length() != 0) {
      return hmm_d.setAccumulatorList(accum_list);
    }
    return false;  
  }  
  
  // method setOutputFile
  //
  boolean setOutputFile(Filename& output_file) {
   if (output_file.length() != 0) {
     return hmm_d.setOutputFile(output_file);
   }
   return false;  
  }

  // method: setSplitThreshold
  //
  boolean setSplitThreshold(const String& split_threshold) {
    if (split_threshold.length() != 0 ){
      Float value;
      value.assign(split_threshold);
      hmm_d.setSplitThreshold(value);
      return true;
    }
    return false;
  }

  // method: setMergeThreshold
  //
  boolean setMergeThreshold(const String& merge_threshold) {
    if (merge_threshold.length() != 0 ){
      Float value;
      value.assign(merge_threshold);
      hmm_d.setMergeThreshold(value);
      return true;
    }
    return false;
  }

  // method: setNumOccThreshold
  //
  boolean setNumOccThreshold(const String& num_occ_threshold) {
    if ( num_occ_threshold.length() != 0 ){ 
      Float value;
      value.assign(num_occ_threshold);
      hmm_d.setNumOccThreshold(value);
      return true;
    }
    return false;
  }

  // method: setDecisionTreeFile
  //
  boolean setDecisionTreeFile(const Filename& arg) {
    if ( arg.length() != 0 ){
      return hmm_d.setDecisionTreeFile(arg);
    }
    return false;
  }

  // method: setQuesAnserFile
  //
  boolean setQuesAnswerFile(const Filename& arg) {
    if ( arg.length() != 0){
      return hmm_d.setQuesAnswerFile(arg);
    }
    return false;
  }

  // method: setOutputList
  //
  boolean setOutputList(Filename& output_list) {
   if (output_list.length() != 0) {
     return hmm_d.setOutputList(output_list);
   }
   return false;  
  }

  // method: setOutputLevelString
  //
  boolean setOutputLevelString(String& output_level) {
   if (output_level.length() != 0) {
     return hmm_d.setOutputLevelString(output_level);
   }
   return false;  
  }

  // method: setUpdateLevelString
  //
  boolean setUpdateLevelString(String& update_level) {
   if (update_level.length() != 0) {
     return hmm_d.setUpdateLevelString(update_level);
   }
   return false;  
  }  

  // method: setAccumulatorPath
  //
  boolean setAccumulatorPath(Filename& accumulator_path) {
    if (accumulator_path.length() != 0) {
      return hmm_d.setAccumulatorPath(accumulator_path);
    }
    return false;
  }

  // method: setAccumulatorName
  //
  boolean setAccumulatorName(String& accumulator_name) {
    if (accumulator_name.length() != 0) {
      return hmm_d.setAccumulatorName(accumulator_name);
    }
    return false;
  }
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  get methods
  //
  //---------------------------------------------------------------------------

  // method: getAlgorithm
  //
  ALGORITHM getAlgorithm() const {
    return algorithm_d;
  }  

  //---------------------------------------------------------------------------
  //
  // class-specific public methods:
  //  computational methods
  //
  //---------------------------------------------------------------------------

  // method: run
  //
  boolean run(Sdb& sdb);
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
  private:

};

//end of include file
//
#endif
