// file: $isip/class/mmedia/TranscriptionDatabase/TranscriptionDatabase.h // version: $Id: TranscriptionDatabase.h 9421 2004-03-10 20:11:33Z parihar $ // // make sure definitions are only made once // #ifndef ISIP_TRANSCRIPTION_DATABASE #define ISIP_TRANSCRIPTION_DATABASE #ifndef ISIP_STRING #include #endif #ifndef ISIP_VECTOR #include #endif #ifndef ISIP_ANNOTATION_GRAPH #include #endif #ifndef ISIP_SDB #include #endif #ifndef ISIP_VECTOR_FLOAT #include #endif // TranscriptionDatabase: a class that facilitates the interface // between the transcription database and another applications or // classes // class TranscriptionDatabase { //-------------------------------------------------------------------------- // // public constants // //-------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; // i/o related constants // static const String DEF_PARAM; static const String PARAM_KEYS; static const String PARAM_NAME; static const String PARAM_VALUES; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 50500; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // define the database name // String name_d; // define the container object // HashTable hash_d; HashTable hash_index_d; // define the database file pointer // Sof database_sof_d; // declare a static debug level for all class instantiations // static Integral::DEBUG debug_level_d; // a static memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } static bool8 diagnose(Integral::DEBUG debug_level); // debug methods // bool8 debug(const unichar* msg) const; // method: setDebug // static bool8 setDebug(Integral::DEBUG arg) { debug_level_d = arg; return true; } // method: destructor // ~TranscriptionDatabase() { clear(); } // method: default constructor // TranscriptionDatabase(); // method: copy constructor // TranscriptionDatabase(const TranscriptionDatabase& arg) { assign(arg); } // method: assign // bool8 assign(const TranscriptionDatabase& arg); // method: sofSize // int32 sofSize() const; // method: read // bool8 read(Sof& sof, int32 tag) { return read(sof, tag, name()); } bool8 read(Sof& sof, int32 tag, const String& name); bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); // method: write // bool8 write(Sof& sof, int32 tag) const { return write(sof, tag, name()); } bool8 write(Sof& sof, int32 tag, const String& name) const; bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; // method: eq // bool8 eq(const TranscriptionDatabase& arg) const; // method: new // static void* operator new(size_t arg) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t arg) { return mgr_d.getBlock(arg); } // method: delete // static void operator delete(void* arg) { mgr_d.release(arg); } // method: delete[] // static void operator delete[](void* arg) { mgr_d.releaseBlock(arg); } // method: setGrowSize // static bool8 setGrowSize(int32 arg) { return mgr_d.setGrow(arg); } // method: clear // bool8 clear(Integral::CMODE cmode = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods // //--------------------------------------------------------------------------- // method: getDataBaseName // String& getDataBaseName() { return name_d; } // method: setDataBaseName // bool8 setDataBaseName(String& arg) { return name_d.assign(arg); } // method: getAnnotationGraphTable // HashTable& getAnnotationGraphTable() { return hash_d; } // method: getSymbolTable // HashTable& getSymbolTable() { return hash_index_d; } // method: removeRecord // bool8 removeRecord(String& identifier) { return hash_d.remove(identifier); } // method to insert a record into the database // bool8 insertRecord(String& identifier, AnnotationGraph& graph); // method to retrieve the records form the database // bool8 getRecord(String& identifier, AnnotationGraph& graph); bool8 getRecord(String& identifier, String& feature, String& value, Vector& annotations, VectorFloat& start_times, VectorFloat& end_times); bool8 getRecord(String& identifier, String& feature, String& value, String& type, Vector& annotations, VectorFloat& start_times, VectorFloat& end_times); bool8 getRecord(String& identifier, String& feature, String& value, DoubleLinkedList& records); bool8 getRecord(String& identifier, String& feature, String& value, DoubleLinkedList& records); bool8 getRecord(String& identifier, String& feature, Vector& values, String& record); // database open and close method // bool8 open(const Filename& filename); bool8 close(); // method to load a file to transcription database // bool8 load(Filename& trans_file, String& name, String& level); bool8 load(Sdb& sdb, Filename& trans_file); bool8 load(Sdb& sdb, Filename& trans_file, Filename& lexicon_file, bool8 flag = true); bool8 load(Sdb& sdb, Filename& trans_file, Filename& lexicon_file, Filename& systactic_file); // method to store a database to a file // bool8 store(Sof& db_sof, int32 tag); // method to store one transcription to a file // bool8 storePartial(String& trans, String& name, String& level, int32 num, Sof& db_sof, int32 tag); // method to sequencially read and store the transcriptions // bool8 store(Filename& trans_file, String& name, String& level, Sof& db_sof, int32 tag); // method to store the database header to file // bool8 storePartial(Sof& sof, int32 tag, Vector& keys); bool8 storePartial(Sof& sof, int32 tag, AnnotationGraph& graph); // method to retrieve the hypotheses in NIST_TRN format from the // database // bool8 getHypothesesNistTrn(Sdb& ident_list_sdb, Sdb& exlude_symbols_sdb, String& feature, Vector& nist_hypotheses); // method to retrieve the alignments in HYP_ALIGN format from the // database // bool8 getAlignmentsHypAlign(Sdb& ident_list_sdb, String& levels, Vector& alignments); // method to get all the identifiers in the database // bool8 getIdentifiers(Vector& identifiers); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // method to parse the input string of level(s) // bool8 parseLevels(const String& input, Vector& levels); }; //end of include file // #endif