diff --git a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java index 0cad8ff..f9a272d 100644 --- a/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java +++ b/src/main/java/ru/ulstu/extractor/GitExtractorApplication.java @@ -1,17 +1,5 @@ package ru.ulstu.extractor; -import com.fuzzylite.Engine; -import com.fuzzylite.FuzzyLite; -import com.fuzzylite.Op; -import com.fuzzylite.activation.Highest; -import com.fuzzylite.defuzzifier.Centroid; -import com.fuzzylite.norm.s.Maximum; -import com.fuzzylite.norm.t.AlgebraicProduct; -import com.fuzzylite.rule.Rule; -import com.fuzzylite.rule.RuleBlock; -import com.fuzzylite.term.Trapezoid; -import com.fuzzylite.variable.InputVariable; -import com.fuzzylite.variable.OutputVariable; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/src/main/java/ru/ulstu/extractor/core/Route.java b/src/main/java/ru/ulstu/extractor/core/Route.java index 9627848..f6b48d1 100644 --- a/src/main/java/ru/ulstu/extractor/core/Route.java +++ b/src/main/java/ru/ulstu/extractor/core/Route.java @@ -18,6 +18,7 @@ public class Route { public static final String STATISTIC = "statistic"; public static final String LIST_RULE = "listRules"; public static final String ADD_RULE = "addRule"; + public static final String RECOMMENDATIONS = "recommendations"; public static String getLIST_INDEXED_REPOSITORIES() { return LIST_INDEXED_REPOSITORIES; @@ -38,4 +39,8 @@ public class Route { public static String getSTATISTIC() { return STATISTIC; } + + public static String getRECOMMENDATIONS() { + return RECOMMENDATIONS; + } } diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RecommendationController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RecommendationController.java new file mode 100644 index 0000000..1db00c0 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/rule/controller/RecommendationController.java @@ -0,0 +1,25 @@ +package ru.ulstu.extractor.rule.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import ru.ulstu.extractor.rule.service.FuzzyInferenceService; +import springfox.documentation.annotations.ApiIgnore; + +import static ru.ulstu.extractor.core.Route.RECOMMENDATIONS; + +@Controller +@ApiIgnore +public class RecommendationController { + private final FuzzyInferenceService fuzzyInferenceService; + + public RecommendationController(FuzzyInferenceService fuzzyInferenceService) { + this.fuzzyInferenceService = fuzzyInferenceService; + } + + @GetMapping(RECOMMENDATIONS) + public String getRecommendations(Model model) { + model.addAttribute("recommendations", fuzzyInferenceService.run()); + return RECOMMENDATIONS; + } +} diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 4119729..b5c394c 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -19,7 +19,10 @@ import java.util.stream.Collectors; @Service public class FuzzyInferenceService { - private final static String RULE_TEMPLATE = "if %s is %s AND %s is %s then state is %s"; + private final static String OUTPUT_VARIABLE_NAME = "state"; + private final static String RULE_TEMPLATE = "if %s is %s and %s is %s then " + + OUTPUT_VARIABLE_NAME + + " is %s"; private final RuleService ruleService; private final AntecedentValueService antecedentValueService; @@ -49,7 +52,7 @@ public class FuzzyInferenceService { input.setName(key); input.setDescription(""); input.setEnabled(true); - input.setRange(0.000, 1.000); + input.setRange(0.000, antecedentValues.size() + 1); input.setLockValueInRange(false); for (int i = 0; i < antecedentValues.size(); i++) { input.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2)); @@ -57,6 +60,16 @@ public class FuzzyInferenceService { engine.addInputVariable(input); }); + OutputVariable output = new OutputVariable(); + output.setName(OUTPUT_VARIABLE_NAME); + output.setDescription(""); + output.setEnabled(true); + output.setRange(0.000, antecedentValues.size() + 1); + output.setLockValueInRange(false); + for (int i = 0; i < antecedentValues.size(); i++) { + output.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2)); + } + engine.addOutputVariable(output); RuleBlock mamdani = new RuleBlock(); mamdani.setName("mamdani"); @@ -81,17 +94,19 @@ public class FuzzyInferenceService { Engine engine = getFuzzyEngine(); List antecedentValues = antecedentValueService.getList(); Map variableValues = new HashMap<>(); + variableValues.put("COMMITS", 10.0); + variableValues.put("AUTHORS", 10.0); engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues)); return getConsequent(engine, variableValues); } private String getConsequent(Engine engine, Map variableValues) { - OutputVariable outputVariable = engine.getOutputVariable("state"); + OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME); for (Map.Entry variableValue : variableValues.entrySet()) { InputVariable inputVariable = engine.getInputVariable(variableValue.getKey()); inputVariable.setValue(variableValue.getValue()); } engine.process(); - return outputVariable.highestMembership(outputVariable.getValue()).getSecond().getName(); + return outputVariable == null ? "" : outputVariable.fuzzyOutputValue(); } } diff --git a/src/main/resources/templates/recommendations.html b/src/main/resources/templates/recommendations.html index 036dc66..dbcebe5 100644 --- a/src/main/resources/templates/recommendations.html +++ b/src/main/resources/templates/recommendations.html @@ -7,22 +7,6 @@
- - - - - - - - - - - - - - - -
Рекомендации
Увеличить колличество авторов
Оценнить эффективность авторов
- +