// file: $isip/class/stat/NGramModel/NGramModel.h // version: $Id: NGramModel.h 8546 2002-08-08 21:53:44Z zheng $ // // make sure definitions are only made once // #ifndef ISIP_NGRAM_MODEL #define ISIP_NGRAM_MODEL #ifndef ISIP_SOF #include #endif #ifndef ISIP_VECTOR #include #endif #ifndef ISIP_STRING #include #endif #ifndef ISIP_HASH_TABLE #include #endif #ifndef ISIP_NGRAM_NODE #include #endif #ifndef ISIP_NGRAM_PARSER #include #endif // NGram: a class that manages N-gram probabilities, such as bigram, // trigram, etc. This class can be used to load an input N-gram file, // such as NIST_ARPA grammar file, and then store it to HashTable for // lookup. // class NGramModel { //------------------------------------------------------------- // // public constants // //------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String PARAM_ORDER; static const String PARAM_KEYS; static const String PARAM_VALUES; static const String PARAM_GRAM_HASH; //-------------------------------------------------------------- // // other important constants // //-------------------------------------------------------------- // define the default value(s) of the class data // static const String DEF_PARAM; static const Long DEF_ORDER; static const Float DEF_LM_SCORE; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = (int32)60600; //------------------------------------------------------------- // // protected data // //------------------------------------------------------------- protected: // the order of N_gram // Long order_d; // hashtable of symbol indices and ngram nodes for unigram. // here, higher order gram will be expanded from each node. // HashTable gram_hash_d; // symbol table // Vector symbol_table_d; // declare a static debug level for all class instantiations // static Integral::DEBUG debug_level_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 bool8 diagnose(Integral::DEBUG debug_level); // method: setDebug // static bool8 setDebug(Integral::DEBUG debug_level) { debug_level_d = debug_level; return true; } // debug methods: // bool8 debug(const unichar* msg) const; // method: destructor // ~NGramModel() { clear(Integral::FREE); } // method: default constructor // NGramModel(Long order = DEF_ORDER) { order_d = order; } // method: assign // bool8 assign(const NGramModel& arg) { order_d = arg.order_d; gram_hash_d.assign(arg.gram_hash_d); return true; } // method: operator= // NGramModel& operator= (const NGramModel& arg) { assign(arg); return *this; } // i/o methods // // method: sofSize // int32 sofSize() const; // method: read // bool8 read(Sof& sof, const int32 tag, const String& cname = CLASS_NAME); // method: write // bool8 write(Sof& sof, int32 tag, const String& cname = CLASS_NAME) const; // method: readData // bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); // method: writeData // bool8 writeData(Sof& sof_a, const String& pname_a = DEF_PARAM) const; // equality methods // bool8 eq(const NGramModel& arg) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } // method: clear // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // //--------------------------------------------------------------------------- // method: setOrder // bool8 setOrder(int32 order) { order_d = order; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // //--------------------------------------------------------------------------- // method: getOrder // int32 getOrder() const { return order_d; } // method: getGramHash // HashTable* getGramHash() { return &gram_hash_d; } //--------------------------------------------------------------------------- // // class-specific public methods: // operation related methods // //--------------------------------------------------------------------------- // method: load // bool8 load(Sof& sof, const int32& tag, const Vector& symbol_table, const String& name = CLASS_NAME); // method: store // bool8 store(Sof& sof, const int32& tag, const String& name = CLASS_NAME) const; // method: getScore // float32 getScore(const VectorLong& symbol_indices); bool8 getScore(const VectorLong& index_a, float32& score_a); //------------------------------------------------------------- // // private methods // //------------------------------------------------------------- private: }; // end of include file // #endif