Ejemplo n.º 1
0
 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);
         }
     }
 }
Ejemplo n.º 2
0
 void FllImporter::processOutputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     OutputVariable* outputVariable = new OutputVariable;
     engine->addOutputVariable(outputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("OutputVariable" == keyValue.first) {
             outputVariable->setName(keyValue.second);
         } else if ("enabled" == keyValue.first) {
             outputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             outputVariable->setRange(range.first, range.second);
         } else if ("default" == keyValue.first) {
             outputVariable->setDefaultValue(Op::toScalar(keyValue.second));
         } else if ("lock-valid" == keyValue.first) {
             outputVariable->setLockValidOutput(parseBoolean(keyValue.second));
         } else if ("lock-range" == keyValue.first) {
             outputVariable->setLockOutputRange(parseBoolean(keyValue.second));
         } else if ("defuzzifier" == keyValue.first) {
             outputVariable->setDefuzzifier(parseDefuzzifier(keyValue.second));
         } else if ("accumulation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAccumulation(parseSNorm(keyValue.second));
         } else if ("term" == keyValue.first) {
             outputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw fl::Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
 }
Ejemplo n.º 3
0
 void FllImporter::processOutputVariable(const std::string& block, Engine* engine) const {
     std::istringstream reader(block);
     std::string line;
     FL_unique_ptr<OutputVariable> outputVariable(new OutputVariable);
     while (std::getline(reader, line)) {
         std::pair<std::string, std::string> keyValue = parseKeyValue(line, ':');
         if ("OutputVariable" == keyValue.first) {
             outputVariable->setName(Op::validName(keyValue.second));
         } else if ("enabled" == keyValue.first) {
             outputVariable->setEnabled(parseBoolean(keyValue.second));
         } else if ("range" == keyValue.first) {
             std::pair<scalar, scalar> range = parseRange(keyValue.second);
             outputVariable->setRange(range.first, range.second);
         } else if ("default" == keyValue.first) {
             outputVariable->setDefaultValue(Op::toScalar(keyValue.second));
         } else if ("lock-previous" == keyValue.first or "lock-valid" == keyValue.first) {
             outputVariable->setLockPreviousValue(parseBoolean(keyValue.second));
         } else if ("lock-range" == keyValue.first) {
             outputVariable->setLockValueInRange(parseBoolean(keyValue.second));
         } else if ("defuzzifier" == keyValue.first) {
             outputVariable->setDefuzzifier(parseDefuzzifier(keyValue.second));
         } else if ("aggregation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAggregation(parseSNorm(keyValue.second));
         } else if ("accumulation" == keyValue.first) {
             outputVariable->fuzzyOutput()->setAggregation(parseSNorm(keyValue.second));
             FL_LOG("[warning] obsolete usage of identifier <accumulation: SNorm> in OutputVariable");
             FL_LOG("[information] from version 6.0, the identifier <aggregation: SNorm> should be used");
             FL_LOG("[backward compatibility] assumed "
                     "<aggregation: " << keyValue.second << "> "
                     "instead of <accumulation: " << keyValue.second << ">");
         } else if ("term" == keyValue.first) {
             outputVariable->addTerm(parseTerm(keyValue.second, engine));
         } else {
             throw Exception("[import error] key <" + keyValue.first + "> not "
                     "recognized in pair <" + keyValue.first + ":" + keyValue.second + ">", FL_AT);
         }
     }
     engine->addOutputVariable(outputVariable.release());
 }
Ejemplo n.º 4
0
 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());
 }