// file: $isip/class/search/SymbolGraph/SymbolGraph.h // version: $Id: SymbolGraph.h 9374 2003-12-22 22:45:48Z alphonso $ // // make sure definitions are only made once // #ifndef ISIP_SYMBOL_GRAPH #define ISIP_SYMBOL_GRAPH // isip include files // #ifndef ISIP_STRING #include #endif #ifndef ISIP_FILENAME #include #endif #ifndef ISIP_LONG #include #endif #ifndef ISIP_FLOAT #include #endif #ifndef ISIP_VECTOR #include #endif #ifndef ISIP_PAIR #include #endif #ifndef ISIP_TRIPLE #include #endif #ifndef ISIP_HASH_TABLE #include #endif #ifndef ISIP_HASH_KEY #include #endif #ifndef ISIP_DIGRAPH #include #endif #ifndef ISIP_SEARCH_LEVEL #include #endif #ifndef ISIP_SINGLE_LINKED_LIST #include #endif #ifndef ISIP_SYMBOL_GRAPH_NODE #include #endif // SymbolGraph: a class to hold a symbol representing some part of the search // class SymbolGraph { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String DEF_SYMBOL; static const String DEF_FORMAT; static const String PARAM_FORMAT; static const String PARAM_VERSION; static const String PARAM_SCALE; static const String PARAM_PENALTY; static const String DEF_START_SYMBOL; static const String DEF_TERM_SYMBOL; //---------------------------------------- // // default values and arguments // //---------------------------------------- // default values // static const float32 DEF_SCALE = 1.0; static const float32 DEF_PENALTY = 0.0; static const float32 DEF_FRAME_DURATION = 0.01; static const int32 DEF_ORDER = 1; static const int32 DEF_NUM_NODES = 0; static const int32 DEF_NUM_ARCS = 0; //--------------------------------------- // // error codes // //--------------------------------------- //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // define the format // String format_d; // define the language model scale factor // Float scale_d; // define the symbol insertion penalty // Float penalty_d; // define the n-symbol order // Long order_d; // define the number of nodes in the graph // Long num_nodes_d; // define the number of arcs in the graph // Long num_arcs_d; // define the linked list of nodes corresponding to this graph // SingleLinkedList nodes_d; // define the start node and term nodes // SymbolGraphNode start_node_d; SymbolGraphNode term_node_d; // define a static memory manager // static MemoryManager mgr_d; // define a static debug level // static Integral::DEBUG debug_level_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; } // method: destructor // ~SymbolGraph() { clear(); } // default constructor // SymbolGraph(); // method: copy constructor // SymbolGraph(const SymbolGraph& copy_grp) { assign(copy_grp); } // method: assign // bool8 assign(const SymbolGraph& copy_grp) { return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } // method: operator= // SymbolGraph& operator=(const SymbolGraph& arg) { assign(arg); return *this; } // i/o methods // int32 sofSize() const; // read methods // bool8 read(Sof& sof, int32 tag, const String& cname = CLASS_NAME); bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 readDataText(Sof& sof_a, const String& pname, int32 size, bool8 param, bool8 nested); bool8 readDataBinary(Sof& sof); // write methods // bool8 write(Sof& sof, int32 tag, const String& cname = CLASS_NAME) const; bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; bool8 writeTextData(Sof& sof, const String& pname, Vector& nodes, Vector >& symbols, Vector, Float, Float> >& arcs) const; bool8 writeBinaryData(Sof& sof, const String& pname, Vector& nodes, Vector >& symbols, Vector, Float, Float> >& arcs) const; // equality method // bool8 eq(const SymbolGraph& compare_graph) 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); } // clear method // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods // //--------------------------------------------------------------------------- // method: getFormat // bool8 getFormat(String& arg) { return arg.assign(format_d); } // method: setFormat // bool8 setFormat(const String& arg) { return format_d.assign(arg); } // method: getScale // float32 getScale() const { return scale_d; } // method: setScale // bool8 setScale(const float32 arg) { return (scale_d = arg); } // method: getPenalty // float32 getPenalty() const { return penalty_d; } // method: setPenalty // bool8 setPenalty(const float32 arg) { return (penalty_d = arg); } // method: getOrder // int32 getOrder() const { return order_d; } // method: setOrder // bool8 setOrder(const int32 arg) { return (order_d = arg); } // method: getNodes // SingleLinkedList& getNodes() { return nodes_d; } // method: getNumNodes // int32 getNumNodes() const { return num_nodes_d; } // method: setNumNodes // bool8 setNumNodes(const int32 arg) { return (num_nodes_d = arg); } // method: getNumArcs // int32 getNumArcs() const { return num_arcs_d; } // method: setNumArcs // bool8 setNumArcs(const int32 arg) { return (num_arcs_d = arg); } // method: getStart // SymbolGraphNode* getStart() { return (SymbolGraphNode*)&start_node_d; } // method: getTerm // SymbolGraphNode* getTerm() { return (SymbolGraphNode*)&term_node_d; } // method: incrementNodes // bool8 incrementNodes() { num_nodes_d++; return true; } // method: decrementNodes // bool8 decrementNodes() { num_nodes_d--; return true; } // method: incrementArcs // bool8 incrementArcs() { num_arcs_d++; return true; } // method: decrementArcs // bool8 decrementArcs() { num_arcs_d--; return true; } // method: find // bool8 find(const SymbolGraphNode* obj) { return nodes_d.find(obj); } // method: contains // bool8 contains(const SymbolGraphNode* obj) { return nodes_d.find(obj); } // insert/remove methods // SymbolGraphNode* insertNode(int32 frame, const String& str = DEF_SYMBOL); bool8 removeNode(SymbolGraphNode* obj); // graph reduction methods // bool8 prune(); bool8 compact(SymbolGraph& graph); // method to convert the symbol grapph into a digraph representation // bool8 convert(SearchLevel& level, DiGraph& digraph); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // methods to get and set the graph internal structure // bool8 get(Vector& nodes, Vector >& symbols, Vector, Float, Float> >& arcs); bool8 set(Vector& nodes, Vector >& symbols, Vector, Float, Float> >& arcs); // method to read the lattice format // bool8 readLatticeFormat(Sof& sof, const String& pname, int32 size, bool8 param, bool8 nested); }; // end of include file // #endif