// file: $isip/class/pr/LanguageModelJSGF/LanguageModelJSGF.h // // make sure definitions are only made once // #ifndef ISIP_LANGUAGE_MODEL_JSGF #define ISIP_LANGUAGE_MODEL_JSGF #ifndef ISIP_LANGUAGE_MODEL_BASE #include #endif #ifndef ISIP_JSGF_PARSER #include #endif // forward class definitions // // LanguageModelJSGF: Used for language models in JSGF (JAVA Speech Grammar Format) Format. // class LanguageModelJSGF : public LanguageModelBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //-------------------------------------------------------------- // // other important constants // //-------------------------------------------------------------- static const SearchSymbol START_SYMBOL; static const SearchSymbol TERM_SYMBOL; static const int32 DEF_LEVEL = -1; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_GRAMMARS; static const String TOP_GRAMMAR_NAME; // jsgf comments // static const String COMMENT_GRAMMAR_NAME; static const String COMMENT_TERM_SYMBOL; static const String COMMENT_START_SYMBOL; static const String COMMENT_RESERVED_GRAMMAR; static const String COMMENT_SYMBOLS; static const String COMMENT_RULES; static const String COMMENT_CONTEXT_RULE; // other JSGF standard syntax constants // static const String PARAM_JSGF_START_SYMBOL; static const String PARAM_JSGF_TERM_SYMBOL; static const String START_SYMBOL_REFERENCE; static const String TERM_SYMBOL_REFERENCE; static const String OPERATOR_OPENPARENS; static const String OPERATOR_CLOSEPARENS; static const String OPERATOR_OPENANGLEBRACKET; static const String OPERATOR_CLOSEANGLEBRACKET; static const String OPERATOR_FWDSLASH; static const String OPERATOR_EQUALS; static const String OPERATOR_ALTERNATION; static const String OPERATOR_SEMICOLON; // open/close operator constants // static const int32 OPERATOR_OPEN_POS; static const int32 OPERATOR_CLOSE_POS; // other i/o constants // static const String KEYWORD_PUBLIC; static const String KEYWORD_GRAMMAR; static const String GRAMMAR_DEF_BASE; static const String PARAM_UNDERSCORE; static const String PARAM_JSGF_VERSION; static const String CONTEXT_LABEL_PREFIX; static const String RULE_NAME_BASE; //---------------------------------------- // // default values and arguments // //---------------------------------------- //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 100102; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // debug level // // debug_level_d inherited from LanguageModelBase // hierarchical digraph to store symbol table and symbol types // HierarchicalDigraph hg_d; // abnf rule model object // RuleModel abnf_model_d; // vector to store grammars // Vector< Vector < Vector > > grammars_d; // memory manager // static MemoryManager mgr_d; // isip standard jsgf start symbol // SearchSymbol start_symbol_d; // isip standard jsgf term symbol // SearchSymbol term_symbol_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // method: diagnose // static bool8 diagnose(Integral::DEBUG debug_level); // debug methods // bool8 debug(const unichar* msg) const; // method: destructor // ~LanguageModelJSGF() { } // method: default constructor // LanguageModelJSGF() { } // method: copy constructor // LanguageModelJSGF(const LanguageModelJSGF& arg) { assign(arg); } // assign methods // bool8 assign(const LanguageModelJSGF& arg) { return rm_d.assign(arg.rm_d); } // i/o methods // // method: sofSize // int32 sofSize() const { return rm_d.sofSize(); } // method: read // bool8 read(Sof& sof, 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, const String& pname = DEF_PARAM) const; // other memory managements methods // bool8 clear(Integral::CMODE cmode = Integral::DEF_CMODE) { return rm_d.clear(); } // equality methods // bool8 eq(const LanguageModelJSGF& arg) const { return rm_d.eq(arg.rm_d); } //--------------------------------------------------------------------------- // // class-specific public methods required by interface contract // defined in LanguageModelBase.h // //--------------------------------------------------------------------------- // LanguageModelBase required methods // bool8 assign(const LanguageModelBase& arg); bool8 eq(const LanguageModelBase& arg) const; //-------------------------------------------------------- // // load and store methods // //-------------------------------------------------------- //-------------------------------------------------------- // // other methods // //-------------------------------------------------------- // method: className // const String& className() const { return CLASS_NAME; } // method: getRuleModel // RuleModel getRuleModel(); // method: getRuleModel // RuleModel getABNFRuleModel(); // method: setRuleModel // bool8 setRuleModel(const RuleModel& rm_a); // method: setABNFRuleModel // bool8 setABNFRuleModel(const RuleModel& rm_a) { return rm_d.assign(rm_a); } // method: getJSGFGrammars // Vector< Vector < Vector > > getJSGFGrammars() { return grammars_d; } // method: setJSGF Grammars // bool8 setJSGFGrammars(Vector< Vector < Vector > > grammars_a) { return grammars_d.assign(grammars_a); } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // method: writeGrammars // bool8 writeGrammars(Sof& sof, int32 level, HierarchicalDigraph& h_digraph) const; // method: writeSymbolType // bool8 writeSymbolType(Sof& sof, int32 level, const String& pname, Vector symbol_list) const; // method: writeContextMapping // bool8 writeContextMapping(Sof& sof, int32 level, HierarchicalDigraph& h_digraph) const; // method: digraphToJSGF // String digraphToJSGF(DiGraph& graph, SearchSymbol grammar_name) const; // method: readSymbolTypes // bool8 readSymbolType(Sof& sof, int32 level, const String& pname, Vector& symbol_list_a, SofParser& parser); // method: readGrammars // bool8 readGrammars(Sof& sof, const String& pname, int32 level, bool8 use_context, Vector* symbol_table, SofParser& parser); // method: readJSGF // bool8 readJSGF(Sof& sof, String grammar, Vector& sub_symbol_list, DiGraph& sub_graph, String& sub_graph_name, Vector& jsgf_graph); // method: readContextMapping // bool8 readContextMapping(Sof& sof, const String& pname, int32 level, SofParser&parser); // method: alignGraphs // bool8 alignGraphs(Vector >& token_vector, Vector& symbol_table, Vector& graph_name_list); // method: convertGraph // bool8 convertGraph(DiGraph& symbol_graph, DiGraph& node_graph, int32& num_symbols, int32 level); // method: convertJSGFtoABNF // ProductionRuleSet convertJSGFtoABNF(Vector grammar); // method: convertBNFtoJSFF // Vector convertBNFtoJSGF(ProductionRuleSet rules); // method: findRule // ProductionRule findRule(String ruleref, ProductionRuleSet rules); // method: convertTokensToString // bool8 convertTokensToString(Vector token_grammar, String& string_grammar) const; }; // end of include file // #endif