// file: $isip/class/pr/LanguageModelABNF/LanguageModelABNF.h // version: $Id: LanguageModelABNF.h 10511 2006-03-17 17:01:48Z may $ // // make sure definitions are only made once // #ifndef ISIP_LANGUAGEMODELABNF #define ISIP_LANGUAGEMODELABNF // isip include files // #ifndef ISIP_DIGRAPH #include #endif #ifndef ISIP_LANGUAGE_MODEL_BASE #include #endif #ifndef ISIP_STRING #include #endif #ifndef ISIP_DOUBLE_LINKED_LIST #include #endif #ifndef ISIP_LONG #include #endif #ifndef ISIP_FLOAT #include #endif #ifndef ISIP_VECTOR #include #endif #ifndef ISIP_PRODUCTIONRULE #include #endif #ifndef ISIP_PRODUCTIONRULETOKENTYPE #include #endif #ifndef ISIP_FILENAME #include #endif #ifndef ISIP_FILE #include #endif #ifndef ISIP_DEBUGLEVEL #include #endif #ifndef ISIP_TRIPLE #include #endif #ifndef ISIP_SOF #include #endif typedef Vector > WeightedSymbols; // LanguageModelABNF: a class used for converting ABNF productions into a set // of BNF Productions. This class reads in ABNF productions from // LanguageModelXML. The weights that are passed from the LanguageModelXML // are preserved even after conversion. A Vector>> is passed to LanguageModelABNF, // which takes one production at a time and removes the meta symbols. // class LanguageModelABNF : public LanguageModelBase { //----------------------------------- // // public constants // //----------------------------------- public: // define the class name // static const String CLASS_NAME; //------------------------------------ // // i/o related constants // //------------------------------------ static const String DEF_PARAM; static const int32 DEF_LEVEL; static const String PARAM_ABNF; static const int32 DEF_TAG; //------------------------------------- // // default values and arguments // //------------------------------------- // define the default attribute values // static const float32 DEF_WEIGHT; //------------------------------------- // // error codes // //------------------------------------- static const int32 ERR = 100800; static const int32 ERR_CTXT_INV_SYM = 100801; static const int32 ERR_RULE_EMPTY = 100802; //-------------------------------------- // // protected data // //-------------------------------------- protected: // search direction // enum DIRECTION {RIGHT=0, LEFT}; // rulemodel name // RuleModel abnf_model_d; // holds count for non-conflicting variable names // int32 count_d; //-------------------------------------- // // required public methods // //-------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // method: diagnose // static bool8 diagnose(Integral::DEBUG level); // method: debug // bool8 debug(const unichar* msg) const; // method: destructor // // ~LanguageModelABNF() { } // method: default constructor // LanguageModelABNF(); // method: read // bool8 read(Sof& sof, int32 tag, const String& cname = CLASS_NAME); // method: readData // 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 String& cname = CLASS_NAME) const; // method: writeData // bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; // method: sofSize // int32 sofSize() const { return rm_d.sofSize(); } // method: assign // bool8 assign(const LanguageModelABNF& lmabnf_a); // method: operator= // bool8 operator=(const LanguageModelABNF& lmabnf_a); // method: eq // bool8 eq(const LanguageModelABNF& lmabnf_a) const; // method: operator== // bool8 operator==(const LanguageModelABNF& lmabnf_a) const; // method: clear // bool8 clear(Integral::CMODE ctype); //--------------------------------------------------------------------------- // // 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; // method: className // const String& className() const { return CLASS_NAME; } // method: retrieve equivalent BNF production rules // RuleModel getRuleModel(); // method: pass in equivalent BNF production rules // bool8 setRuleModel(const RuleModel& model_a) { return (rm_d.assign(model_a) && abnf_model_d.assign(model_a)); } // method: retrieve equivalent ABNF production rules // RuleModel getABNFRuleModel() { return abnf_model_d; } // method: pass in equivalent ABNF production rules // bool8 setABNFRuleModel(const RuleModel& model_a) { return abnf_model_d.assign(model_a); } //--------------------------------------------------------------------------- // // class-specific protected methods // //--------------------------------------------------------------------------- protected: //--------------------------------------------------------------------------- // // ABNF to BNF conversion methods // //--------------------------------------------------------------------------- // method: getRightSymbols // WeightedSymbols findRightSymbols(ProductionRuleSet& rules, int32 index, int32 nest_level, int32 position, Float weight); // method: getLeftSymbols // Vector findLeftSymbols(ProductionRuleSet& rules, int32 index, int32 nest_level, int32 position); // method: buildNormBNFRules // bool8 buildNormBNFRules(Vector left_symbols, WeightedSymbols right_symbols, ProductionRuleSet& bnf_rules); // method: findEndOfNestLevel // int32 findEndOfNestLevel(ProductionRule current_rule, int32 index, DIRECTION dir); // method: findToken // int32 findToken(ProductionRule current_rule, int32 index, ProductionRuleTokenType::TYPE token, DIRECTION dir); // method: restoreSymbols // bool8 restoreSymbols(ProductionRuleSet& rules, Vector > chart); // method: createStartRules // bool8 createStartRules(RuleModel abnf_rules, ProductionRuleSet& bnf_rules, int32 level_index, int32 graph_index); }; #endif