void FllImporter::processRuleBlock(const std::string& block, Engine* engine) const { std::istringstream reader(block); std::string line; RuleBlock* ruleBlock = new RuleBlock; engine->addRuleBlock(ruleBlock); while (std::getline(reader, line)) { std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':'); if ("RuleBlock" == keyValue.first) { ruleBlock->setName(keyValue.second); } else if ("enabled" == keyValue.first) { ruleBlock->setEnabled(parseBoolean(keyValue.second)); } else if ("conjunction" == keyValue.first) { ruleBlock->setConjunction(parseTNorm(keyValue.second)); } else if ("disjunction" == keyValue.first) { ruleBlock->setDisjunction(parseSNorm(keyValue.second)); } else if ("activation" == keyValue.first) { ruleBlock->setActivation(parseTNorm(keyValue.second)); } else if ("rule" == keyValue.first) { ruleBlock->addRule(fl::Rule::parse(keyValue.second, engine)); } else { throw fl::Exception("[import error] key <" + keyValue.first + "> not " "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT); } } }
void FllImporter::processRuleBlock(const std::string& block, Engine* engine) const { std::istringstream reader(block); std::string line; FL_unique_ptr<RuleBlock> ruleBlock(new RuleBlock); while (std::getline(reader, line)) { std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':'); if ("RuleBlock" == keyValue.first) { ruleBlock->setName(keyValue.second); } else if ("enabled" == keyValue.first) { ruleBlock->setEnabled(parseBoolean(keyValue.second)); } else if ("conjunction" == keyValue.first) { ruleBlock->setConjunction(parseTNorm(keyValue.second)); } else if ("disjunction" == keyValue.first) { ruleBlock->setDisjunction(parseSNorm(keyValue.second)); } else if ("implication" == keyValue.first) { ruleBlock->setImplication(parseTNorm(keyValue.second)); } else if ("activation" == keyValue.first) { TNormFactory* tnorm = FactoryManager::instance()->tnorm(); //@todo remove backwards compatibility in version 7.0 if (tnorm->hasConstructor(keyValue.second)) { ruleBlock->setImplication(parseTNorm(keyValue.second)); FL_LOG("[warning] obsolete usage of identifier <activation: TNorm> " "in RuleBlock"); FL_LOG("[information] from version 6.0, the identifiers are " "<activation: Activation> for Activation methods " "and <implication: TNorm> for T-Norms"); FL_LOG("[backward compatibility] assumed " "<implication: " << keyValue.second << "> " "instead of <activation: " << keyValue.second << ">"); } else { ruleBlock->setActivation(parseActivation(keyValue.second)); } } else if ("rule" == keyValue.first) { Rule* rule = new Rule; rule->setText(keyValue.second); try { rule->load(engine); } catch (std::exception& ex) { FL_LOG(ex.what()); } ruleBlock->addRule(rule); } else { throw Exception("[import error] key <" + keyValue.first + "> not " "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT); } } engine->addRuleBlock(ruleBlock.release()); }