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.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
@Controller @Controller
public class InferenceMvcController { public class InferenceMvcController {
@ -34,21 +35,24 @@ public class InferenceMvcController {
model.addAttribute("ageAntecedents", getAgeAntecedents()); model.addAttribute("ageAntecedents", getAgeAntecedents());
model.addAttribute("incomeAntecedents", getIncomeAntecedents()); model.addAttribute("incomeAntecedents", getIncomeAntecedents());
model.addAttribute("inferenceForm", inferenceForm); 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"; return "index";
} }
private List<Antecedent> getAgeAntecedents() { private List<Antecedent> getAgeAntecedents() {
return Arrays.asList( return Arrays.asList(
new Antecedent("молодой", "young"), new Antecedent("молодой", "30"),
new Antecedent("средний", "average"), new Antecedent("средний", "45"),
new Antecedent("старый", "old")); new Antecedent("старый", "60"));
} }
private List<Antecedent> getIncomeAntecedents() { private List<Antecedent> getIncomeAntecedents() {
return Arrays.asList( return Arrays.asList(
new Antecedent("малый", "small"), new Antecedent("небольшой", "20000"),
new Antecedent("средний", "average"), new Antecedent("средний", "90000"),
new Antecedent("высокий", "high")); new Antecedent("высокий", "200000"));
} }
} }

View File

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

View File

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

View File

@ -50,7 +50,12 @@
</div> </div>
</div> </div>
<input type="submit" class="btn btn-outline-success m-2" value="Получить результат вывода"/> <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> </form>
</div> </div>
</html> </html>