// file: $isip/class/stat/NGramModel/ngrm_03.cc // version: $Id: ngrm_03.cc 8501 2002-07-30 05:03:25Z zheng $ // // isip include files // #include "NGramModel.h" #include // method: read // // arguments: // Sof& sof: (input) sof file object // const int32 tag: (input) sof object instance tag // const String& name: (input) sof object instance name // // return: a bool8 value indicating status // // this method has the object read itself from an Sof file // bool8 NGramModel::read(Sof& sof_a, const int32 tag_a, const String& name_a) { // get the instance of the object from the Sof file // if (!sof_a.find(name_a, tag_a)) { return false; } // read the actual data from the sof file // if (!readData(sof_a)) { return false; } // exit gracefully // return true; } // method: readData // // arguments: // Sof& sof: (input) sof file object // const String& pname: (input) parameter name // int32 size: (input) number of bytes in file // bool8 param: (input) is the parameter specified? // bool8 nested: (input) is this nested? // // return: a bool8 value indicating status // // this method has the object read itself from an Sof file. it assumes // that the Sof file is already positioned correctly. // bool8 NGramModel::readData(Sof& sof_a, const String& pname_a, int32 size_a, bool8 param_a, bool8 nested_a) { // if ascii, parse the start bracket // SofParser parser; nested_a = true; if (nested_a) { parser.setNest(); } // set the debug level // parser.setDebug(debug_level_d); if (nested_a) { parser.setNest(); } // load the parse // if (!parser.load(sof_a, size_a)) { // return a warning message // return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } // read the data // if (parser.isPresent(sof_a, PARAM_ORDER)) { if (!order_d.readData(sof_a, PARAM_ORDER, parser.getEntry(sof_a, PARAM_ORDER))) { return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } } else { order_d.assign(DEF_ORDER); } // read the keys associated with the hash table // Vector keys; if (parser.isPresent(sof_a, PARAM_KEYS)) { if (!keys.readData(sof_a, PARAM_KEYS, parser.getEntry(sof_a, PARAM_KEYS), false, false)) { // return a warning message // return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } } // read the values associated with the hash table // Vector values; if (parser.isPresent(sof_a, PARAM_VALUES)) { if (!values.readData(sof_a, PARAM_VALUES, parser.getEntry(sof_a, PARAM_VALUES), false, false)) { // return a warning message // return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } } // write hash table // gram_hash_d.clear(Integral::RESET); if (keys.length() > 0 && values.length() > 0) { int32 len = keys.length(); for (int32 i=0; i < len; i++) { gram_hash_d.insert(keys(i), &values(i)); } } // make sure all coefficients have been accessed // if (!parser.checkParams(sof_a)) { return Error::handle(name(), L"readData", Error::IO, __FILE__, __LINE__, Error::WARNING); } // exit gracefully // return true; }