3-parse-rule #10

Open
romanov73 wants to merge 9 commits from 3-parse-rule into master
2 changed files with 24 additions and 10 deletions
Showing only changes of commit 1c8eabfc08 - Show all commits

View File

@ -0,0 +1,16 @@
package ru.ulstu.fc.config;
import com.fuzzylite.Engine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FuzzyEngine {
@Bean
public Engine getFuzzyEngine() {
Engine engine = new Engine();
engine.setName("Fuzzy rules");
engine.setDescription("");
return engine;
}
}

View File

@ -30,6 +30,7 @@ public class FuzzyInferenceService {
+ OUTPUT_VARIABLE_NAME + OUTPUT_VARIABLE_NAME
+ " is %s"; + " is %s";
private final static String NO_RESULT = "Нет результата"; private final static String NO_RESULT = "Нет результата";
private final Engine fuzzyEngine;
private Map<String, List<Entry<String, Integer>>> inputFuzzyTerms = Map.of( private Map<String, List<Entry<String, Integer>>> inputFuzzyTerms = Map.of(
"возраст", "возраст",
@ -48,6 +49,10 @@ public class FuzzyInferenceService {
new AbstractMap.SimpleEntry("средний", 100000), new AbstractMap.SimpleEntry("средний", 100000),
new AbstractMap.SimpleEntry("большой", 1000000))); new AbstractMap.SimpleEntry("большой", 1000000)));
public FuzzyInferenceService(Engine fuzzyEngine) {
this.fuzzyEngine = fuzzyEngine;
}
private List<String> getDemoRules() { private List<String> getDemoRules() {
return List.of( return List.of(
String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "высокий", "большой"), String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "высокий", "большой"),
@ -112,13 +117,6 @@ public class FuzzyInferenceService {
return mamdani; return mamdani;
} }
private Engine getFuzzyEngine() {
Engine engine = new Engine();
engine.setName("Fuzzy rules");
engine.setDescription("");
return engine;
}
private Map<String, Double> getConsequent(Engine engine, Map<String, Double> variableValues) { private Map<String, Double> getConsequent(Engine engine, Map<String, Double> variableValues) {
OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME); OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME);
for (Map.Entry<String, Double> variableValue : variableValues.entrySet()) { for (Map.Entry<String, Double> variableValue : variableValues.entrySet()) {
@ -135,9 +133,9 @@ public class FuzzyInferenceService {
} }
public Map<String, Double> getFuzzyInference() { public Map<String, Double> getFuzzyInference() {
Engine engine = getFuzzyEngine(); fuzzyEngine.getRuleBlocks().clear();
engine.addRuleBlock(getRuleBlock(engine, getDemoRules())); fuzzyEngine.addRuleBlock(getRuleBlock(fuzzyEngine, getDemoRules()));
return getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0)); return getConsequent(fuzzyEngine, Map.of("возраст", 20.0, "доход", 250000.0));
} }
} }