55 lines
2.1 KiB
Java
55 lines
2.1 KiB
Java
package ru.ulstu.fc.rule.controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import ru.ulstu.fc.rule.model.Antecedent;
|
|
import ru.ulstu.fc.rule.model.InferenceForm;
|
|
import ru.ulstu.fc.rule.service.FuzzyInferenceService;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
@Controller
|
|
public class InferenceMvcController {
|
|
private final FuzzyInferenceService fuzzyInferenceService;
|
|
|
|
public InferenceMvcController(FuzzyInferenceService fuzzyInferenceService) {
|
|
this.fuzzyInferenceService = fuzzyInferenceService;
|
|
}
|
|
|
|
@GetMapping("/")
|
|
public String initInference(Model model) {
|
|
model.addAttribute("ageAntecedents", getAgeAntecedents());
|
|
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
|
|
model.addAttribute("inferenceForm", new InferenceForm());
|
|
return "index";
|
|
}
|
|
|
|
@RequestMapping(value = "get-inference", method = RequestMethod.POST)
|
|
public String getInference(@ModelAttribute InferenceForm inferenceForm, Model model) {
|
|
model.addAttribute("ageAntecedents", getAgeAntecedents());
|
|
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
|
|
model.addAttribute("inferenceForm", inferenceForm);
|
|
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference());
|
|
return "index";
|
|
}
|
|
|
|
private List<Antecedent> getAgeAntecedents() {
|
|
return Arrays.asList(
|
|
new Antecedent("молодой", "young"),
|
|
new Antecedent("средний", "average"),
|
|
new Antecedent("старый", "old"));
|
|
}
|
|
|
|
private List<Antecedent> getIncomeAntecedents() {
|
|
return Arrays.asList(
|
|
new Antecedent("малый", "small"),
|
|
new Antecedent("средний", "average"),
|
|
new Antecedent("высокий", "high"));
|
|
}
|
|
}
|