This commit is contained in:
Anton Romanov 2023-11-06 14:50:36 +04:00
parent e885a78bff
commit 72df590dae
4 changed files with 23 additions and 11 deletions

View File

@ -12,6 +12,7 @@ import ru.ulstu.fc.rule.service.FuzzyInferenceService;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Controller
public class InferenceMvcController {
@ -34,21 +35,24 @@ public class InferenceMvcController {
model.addAttribute("ageAntecedents", getAgeAntecedents());
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
model.addAttribute("inferenceForm", inferenceForm);
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference());
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference(
Map.of("возраст", Double.valueOf(inferenceForm.getAgeAntecedent()),
"доход", Double.valueOf(inferenceForm.getIncomeAntecedent())
)));
return "index";
}
private List<Antecedent> getAgeAntecedents() {
return Arrays.asList(
new Antecedent("молодой", "young"),
new Antecedent("средний", "average"),
new Antecedent("старый", "old"));
new Antecedent("молодой", "30"),
new Antecedent("средний", "45"),
new Antecedent("старый", "60"));
}
private List<Antecedent> getIncomeAntecedents() {
return Arrays.asList(
new Antecedent("малый", "small"),
new Antecedent("средний", "average"),
new Antecedent("высокий", "high"));
new Antecedent("небольшой", "20000"),
new Antecedent("средний", "90000"),
new Antecedent("высокий", "200000"));
}
}

View File

@ -127,8 +127,8 @@ public class FuzzyInferenceService {
.collect(Collectors.toList());
}
public List<OutputValue> getFuzzyInference() {
return getFuzzyInference(getDemoRules(), Map.of("возраст", 20.0, "доход", 250000.0),
public List<OutputValue> getFuzzyInference(Map<String, Double> vals) {
return getFuzzyInference(getDemoRules(), vals,
List.of(new Variable("возраст", List.of(
new VariableValue("молодой", 35.0),
new VariableValue("средний", 60.0),

View File

@ -22,8 +22,11 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/listRules">Правила</a>
<a class="nav-link" href="/swagger-ui/index.html">API</a>
</li>
<!-- <li class="nav-item">-->
<!-- <a class="nav-link" href="/listRules">Правила</a>-->
<!-- </li>-->
</ul>
</div>
</nav>

View File

@ -50,7 +50,12 @@
</div>
</div>
<input type="submit" class="btn btn-outline-success m-2" value="Получить результат вывода"/>
<div class="row" th:text="${response}"></div>
<div class="row" th:each="out : ${response}">
<div class="col-md-2"> Размер кредита:</div>
<div class="col-md-4" th:text="${out.fuzzyTerm}"></div>
<div class="col-md-3"> Степень принадлежности:</div>
<div class="col-md-1" th:text="${out.degree}"></div>
</div>
</form>
</div>
</html>