From 301a32d610e79f84cff2fff1d55c22558d51bb0d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 21 Oct 2022 23:02:27 +0400 Subject: [PATCH] #74 -- partially add middle logic --- .../extractor/GitExtractorApplication.java | 3 -- ...erence.java => FuzzyInferenceService.java} | 51 ++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) rename src/main/java/ru/ulstu/extractor/rule/service/{FuzzyInference.java => FuzzyInferenceService.java} (69%) diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 85d9a30..f9a272d 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -3,14 +3,11 @@ package ru.ulstu.extractor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; -import ru.ulstu.extractor.rule.service.FuzzyInference; @SpringBootApplication @EnableScheduling public class GitExtractorApplication { public static void main(String[] args) { - - new FuzzyInference().run(); SpringApplication.run(GitExtractorApplication.class, args); } } diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java similarity index 69% rename from src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java rename to src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 0bd0ef2..862166c 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInference.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -10,12 +10,61 @@ import net.sourceforge.jFuzzyLogic.rule.LinguisticTerm; import net.sourceforge.jFuzzyLogic.rule.Variable; import net.sourceforge.jFuzzyLogic.ruleConnection.RuleConnectionMethodAndMin; import net.sourceforge.jFuzzyLogic.ruleImplication.RuleImplicationMethodMin; +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.rule.model.AntecedentValue; +import ru.ulstu.extractor.rule.model.Rule; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; +import java.util.List; + +@Service +public class FuzzyInferenceService { + private final RuleService ruleService; + private final AntecedentValueService antecedentValueService; + + public FuzzyInferenceService(RuleService ruleService, + AntecedentValueService antecedentValueService) { + this.ruleService = ruleService; + this.antecedentValueService = antecedentValueService; + } + + private List getFuzzyRulesFromDb() { + List fuzzyRules = new ArrayList<>(); + //List variables = getFuzzyVariables(); + for (Rule dbRule : ruleService.getList()) { + FuzzyRule fuzzyRule = new FuzzyRule(String.format("Fuzzy rule %s", dbRule.getId())); + // fuzzyRule.setAntecedents(expression); + // fuzzyRule.setConsequents(new LinkedList<>(Collections.singleton(new FuzzyRuleTerm(dbRule.getConsequent(), false)))); + fuzzyRules.add(fuzzyRule); + } + return fuzzyRules; + } + + private List getFuzzyVariablesWithoutMembership() { + List variables = new ArrayList<>(); + List antecedentValues = antecedentValueService.getList(); + for (AntecedentValue antecedentValue : antecedentValues) { + variables.add(new Variable(antecedentValue.getAntecedentValue())); + } + return variables; + } + +// private FuzzyRuleExpression getFuzzyRulesAntecedents(TimeSeriesType timeSeriesType1, TimeSeriesType timeSeriesType2) { +// return new FuzzyRuleExpression(getFuzzyRuleTerm(), getFuzzyRuleTerm(), new RuleConnectionMethodAndMin()); +// } + + private FuzzyRuleExpression getFuzzyRuleExpression(FuzzyRuleTerm term1, FuzzyRuleTerm term2) { + return new FuzzyRuleExpression(term1, term2, new RuleConnectionMethodAndMin()); + } + + private FuzzyRuleTerm getFuzzyRuleTerm(Variable variable, String term) { + return new FuzzyRuleTerm(variable, term, false); + } + -public class FuzzyInference { public void run() { FuzzyRule fuzzyRule1 = new FuzzyRule("rule 1"); FuzzyRule fuzzyRule2 = new FuzzyRule("rule 2");