#13 -- Fix rule models
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m19s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m19s
This commit is contained in:
parent
ef9b78251c
commit
9666419ed2
@ -9,6 +9,8 @@ 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.model.Variable;
|
||||
import ru.ulstu.fc.rule.model.VariableValue;
|
||||
import ru.ulstu.fc.rule.service.FuzzyInferenceService;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -26,35 +28,38 @@ public class InferenceMvcController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String initInference(Model model) {
|
||||
model.addAttribute("ageAntecedents", getAgeAntecedents());
|
||||
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
|
||||
model.addAttribute("ageValues", getAgeValues());
|
||||
model.addAttribute("incomeValues", getIncomeValues());
|
||||
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("ageValues", getAgeValues());
|
||||
model.addAttribute("incomeValues", getIncomeValues());
|
||||
model.addAttribute("inferenceForm", inferenceForm);
|
||||
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference(
|
||||
Map.of("возраст", Double.valueOf(inferenceForm.getAgeAntecedent()),
|
||||
"доход", Double.valueOf(inferenceForm.getIncomeAntecedent())
|
||||
)));
|
||||
Map.of("возраст", Double.valueOf(inferenceForm.getAgeValue()),
|
||||
"доход", Double.valueOf(inferenceForm.getIncomeValue()))));
|
||||
return "index";
|
||||
}
|
||||
|
||||
private List<Antecedent> getAgeAntecedents() {
|
||||
return Arrays.asList(
|
||||
new Antecedent("молодой", "30"),
|
||||
new Antecedent("средний", "45"),
|
||||
new Antecedent("старый", "60"));
|
||||
private List<VariableValue> getAgeValues() {
|
||||
Variable var = new Variable("Age");
|
||||
var.getValues().addAll(Arrays.asList(
|
||||
new VariableValue("молодой", 30.0),
|
||||
new VariableValue("средний", 45.0),
|
||||
new VariableValue("старый", 60.0)));
|
||||
return var.getValues();
|
||||
}
|
||||
|
||||
private List<Antecedent> getIncomeAntecedents() {
|
||||
return Arrays.asList(
|
||||
new Antecedent("небольшой", "20000"),
|
||||
new Antecedent("средний", "90000"),
|
||||
new Antecedent("высокий", "200000"));
|
||||
private List<VariableValue> getIncomeValues() {
|
||||
Variable var = new Variable("Income");
|
||||
var.getValues().addAll(Arrays.asList(
|
||||
new VariableValue("небольшой", 20000.0),
|
||||
new VariableValue("средний", 90000.0),
|
||||
new VariableValue("высокий", 200000.0)));
|
||||
return var.getValues();
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,29 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
public class Antecedent {
|
||||
private String value;
|
||||
private String description;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import ru.ulstu.fc.core.model.BaseEntity;
|
||||
|
||||
public Antecedent(String description, String value) {
|
||||
this.description = description;
|
||||
this.value = value;
|
||||
@Entity
|
||||
public class Antecedent extends BaseEntity {
|
||||
@ManyToOne
|
||||
private Variable variable;
|
||||
private String value;
|
||||
|
||||
public Variable getVariable() {
|
||||
return variable;
|
||||
}
|
||||
|
||||
public void setVariable(Variable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
29
src/main/java/ru/ulstu/fc/rule/model/Consequent.java
Normal file
29
src/main/java/ru/ulstu/fc/rule/model/Consequent.java
Normal file
@ -0,0 +1,29 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import ru.ulstu.fc.core.model.BaseEntity;
|
||||
|
||||
@Entity
|
||||
public class Consequent extends BaseEntity {
|
||||
@ManyToOne
|
||||
private Variable variable;
|
||||
private String value;
|
||||
|
||||
public Variable getVariable() {
|
||||
return variable;
|
||||
}
|
||||
|
||||
public void setVariable(Variable variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
public class InferenceForm {
|
||||
private String ageAntecedent;
|
||||
private String incomeAntecedent;
|
||||
private String ageValue;
|
||||
private String incomeValue;
|
||||
|
||||
public String getAgeAntecedent() {
|
||||
return ageAntecedent;
|
||||
public String getAgeValue() {
|
||||
return ageValue;
|
||||
}
|
||||
|
||||
public void setAgeAntecedent(String ageAntecedent) {
|
||||
this.ageAntecedent = ageAntecedent;
|
||||
public void setAgeValue(String ageAntecedent) {
|
||||
this.ageValue = ageAntecedent;
|
||||
}
|
||||
|
||||
public String getIncomeAntecedent() {
|
||||
return incomeAntecedent;
|
||||
public String getIncomeValue() {
|
||||
return incomeValue;
|
||||
}
|
||||
|
||||
public void setIncomeAntecedent(String incomeAntecedent) {
|
||||
this.incomeAntecedent = incomeAntecedent;
|
||||
public void setIncomeValue(String incomeAntecedent) {
|
||||
this.incomeValue = incomeAntecedent;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import ru.ulstu.fc.core.model.BaseEntity;
|
||||
import ru.ulstu.fc.project.model.Project;
|
||||
|
||||
@ -9,6 +12,10 @@ import ru.ulstu.fc.project.model.Project;
|
||||
public class Rule extends BaseEntity {
|
||||
@ManyToOne
|
||||
private Project project;
|
||||
@OneToMany
|
||||
private List<Antecedent> antecedents; //TODO: AND / OR?
|
||||
@ManyToOne
|
||||
private Consequent consequent;
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
@ -16,5 +23,22 @@ public class Rule extends BaseEntity {
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Antecedent> getAntecedents() {
|
||||
return antecedents;
|
||||
}
|
||||
|
||||
public void setAntecedents(List<Antecedent> antecedents) {
|
||||
this.antecedents = antecedents;
|
||||
}
|
||||
|
||||
public Consequent getConsequent() {
|
||||
return consequent;
|
||||
}
|
||||
|
||||
public void setConsequent(Consequent consequent) {
|
||||
this.consequent = consequent;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Variable {
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import ru.ulstu.fc.core.model.BaseEntity;
|
||||
|
||||
@Entity
|
||||
public class Variable extends BaseEntity {
|
||||
private String name;
|
||||
private List<VariableValue> values;
|
||||
@OneToMany
|
||||
private List<VariableValue> values = new ArrayList<>();
|
||||
|
||||
public Variable() {
|
||||
}
|
||||
@ -14,6 +21,10 @@ public class Variable {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Variable(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
public class VariableValue {
|
||||
import jakarta.persistence.Entity;
|
||||
import ru.ulstu.fc.core.model.BaseEntity;
|
||||
|
||||
@Entity
|
||||
public class VariableValue extends BaseEntity {
|
||||
private String fuzzyTerm;
|
||||
private Double value;
|
||||
|
||||
|
@ -25,11 +25,11 @@
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<select id="select-age-antecedent" class="selectpicker m-2" data-live-search="true"
|
||||
th:field="*{ageAntecedent}"
|
||||
th:field="*{ageValue}"
|
||||
data-width="90%">
|
||||
<option th:each="ageAntecedent : ${ageAntecedents}"
|
||||
th:value="${ageAntecedent.value}"
|
||||
th:utext="${ageAntecedent.description}">
|
||||
<option th:each="ageValue : ${ageValues}"
|
||||
th:value="${ageValue.value}"
|
||||
th:utext="${ageValue.fuzzyTerm}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
@ -40,11 +40,11 @@
|
||||
</div>
|
||||
<div class="col-md-6 col-sm-12">
|
||||
<select id="select-income-antecedent" class="selectpicker m-2" data-live-search="true"
|
||||
th:field="*{incomeAntecedent}"
|
||||
th:field="*{incomeValue}"
|
||||
data-width="90%">
|
||||
<option th:each="incomeAntecedent : ${incomeAntecedents}"
|
||||
th:value="${incomeAntecedent.value}"
|
||||
th:utext="${incomeAntecedent.description}">
|
||||
<option th:each="incomeValue : ${incomeValues}"
|
||||
th:value="${incomeValue.value}"
|
||||
th:utext="${incomeValue.fuzzyTerm}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user