// file: $isip/class/pr/LanguageModelJSGF/lmjsgf_08.cc // // isip include files // #include "LanguageModelJSGF.h" #include // method: getRuleModel // // arguments: // none // // return: a RuleModel corresponding to the XML grammar in memory // // this method initiates ABNF->BNF conversion // RuleModel LanguageModelJSGF::getRuleModel() { abnf_model_d.assign(getABNFRuleModel()); // now we have an all ABNF RuleModel. here's the // tricky part: we instantiate a LanguageModelABNF // object to perform the rest of the conversion to // BNF // LanguageModelABNF lm_abnf; lm_abnf.setABNFRuleModel(abnf_model_d); return lm_abnf.getRuleModel(); } // method: getRuleModel // // arguments: // // return: // RuleModel LanguageModelJSGF::getABNFRuleModel() { RuleModel rm; Vector > abnf_grammars; // loop over levels // for (int32 i = 0; i < grammars_d.length(); i++) { Vector abnf_grammar; // loop over all graphs at this level // for (int32 j = 0; j < grammars_d(i).length(); j++) { abnf_grammar.concat(convertJSGFtoABNF(grammars_d(i)(j))); } abnf_grammars.concat(abnf_grammar); } rm.assign(abnf_grammars, hg_d); return rm; } // method: setRuleModel // // arguments: // RuleModel rm_a: a RuleModel corresponding to the BNF graph // // return: bool8 // // this method initiates BNF->JSGF conversion // bool8 LanguageModelJSGF::setRuleModel(const RuleModel& rm_a) { rm_d.assign(rm_a); grammars_d.clear(); Vector< Vector > bnf_rules(rm_d.first()); // loop over levels // for (int32 i = 0; i < bnf_rules.length(); i++) { Vector< Vector > graphs; // loop over graphs // for (int32 j = 0; j < bnf_rules(i).length(); j++) { graphs.concat(convertBNFtoJSGF(bnf_rules(i)(j))); } grammars_d.concat(graphs); } return true; }