// file: $isip/class/pr/LanguageModel/LanguageModelBase.h
//

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

// isip include files
//
#ifndef ISIP_SOF
#include <Sof.h>
#endif

#ifndef ISIP_VECTOR
#include <Vector.h>
#endif

#ifndef ISIP_HIERARCHICAL_DIGRAPH
#include <HierarchicalDigraph.h>
#endif

#ifndef ISIP_STRING
#include <String.h>
#endif

#ifndef ISIP_FILENAME
#include <Filename.h>
#endif

#ifndef ISIP_FILE
#include <File.h>
#endif

#ifndef ISIP_PRODUCTIONRULE
#include <ProductionRule.h>
#endif

#ifndef ISIP_DEBUGLEVEL
#include <DebugLevel.h>
#endif

typedef Vector< ProductionRule > ProductionRuleSet;
typedef Pair< Vector< Vector <ProductionRuleSet> >,
	      HierarchicalDigraph> RuleModel;

// LanguageModelBase: defines the minimal interface contract for all
// language model classes
//
class LanguageModelBase {
  
  //---------------------------------------------------------------------------
  //
  // public constants
  //
  //---------------------------------------------------------------------------
public:

  // define the class name
  //
  static const String CLASS_NAME;

  //--------------------------------------------------------------
  //
  // other important constants
  //
  //--------------------------------------------------------------
  
  // default level index
  //
  static const long DEF_LEVEL_INDEX = -1;

  // default statistical model pool file
  //
  static const Filename DEF_SMP;

  //----------------------------------------
  //
  // error codes
  //
  //----------------------------------------  

  static const long ERR = 100100;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
protected:

  // debugging parameters
  //
  DebugLevel debug_level_d;
  
  // RuleModel object
  //
  RuleModel rm_d;

  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:

  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }

  // debug methods
  //
  virtual boolean debug(const unichar* msg) const = 0;

  // method: setDebug
  //
  boolean setDebug(Integral::DEBUG level) {
    debug_level_d = level;
    rm_d.setDebug(level);
    return true;
  }

  // method: getDebug
  //
  DebugLevel getDebug() {
    return debug_level_d;
  }
  
  // method: destructor
  //
  virtual ~LanguageModelBase() { }

  // method: default constructor
  //
  LanguageModelBase() { }

  // assign methods
  //
  virtual boolean assign(const LanguageModelBase& arg) = 0;

  // i/o methods
  //
  virtual long sofSize() const = 0;

  virtual boolean read(Sof& sof, long tag, const String& cname) = 0;

  virtual boolean write(Sof& sof, long tag, const String& cname) const = 0;

  virtual boolean readData(Sof& sof, const String& pname, long size,
			   boolean param, boolean nested) = 0;

  virtual boolean writeData(Sof& sof, const String& pname) const = 0;

  // equality methods
  //
  virtual boolean eq(const LanguageModelBase& arg) const = 0;

  // memory managements methods
  //
  virtual boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE) = 0;
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods: these methods define the
  // interface contract.
  //
  //---------------------------------------------------------------------------

  // method: className
  //
  virtual const String& className() const = 0;

  // method: retrieve equivalent BNF production rules
  //
  virtual RuleModel getRuleModel() = 0;
  
  // method: pass in equivalent BNF production rules
  //
  virtual boolean setRuleModel(const RuleModel& hg) = 0;

  //--------------------------------------------------------
  //
  // load and store methods
  //
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //
  // other methods
  //
  //--------------------------------------------------------
  
  //---------------------------------------------------------------------------
  //
  // protected methods
  //
  //---------------------------------------------------------------------------
protected:
  
};

// end of include file
// 
#endif
