#5 -- Fix variables
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 57s

This commit is contained in:
Anton Romanov 2025-02-19 17:44:51 +04:00
parent 3723881909
commit fb01034fc8
5 changed files with 28 additions and 28 deletions

View File

@ -8,7 +8,7 @@ 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.InferenceForm;
import ru.ulstu.fc.rule.model.Term;
import ru.ulstu.fc.rule.model.FuzzyTerm;
import ru.ulstu.fc.rule.model.Variable;
import ru.ulstu.fc.rule.service.FuzzyInferenceService;
@ -44,21 +44,21 @@ public class InferenceMvcController {
return "index";
}
private List<Term> getAgeValues() {
private List<FuzzyTerm> getAgeValues() {
Variable var = new Variable("Age");
var.getTerms().addAll(Arrays.asList(
new Term("молодой", 30.0),
new Term("средний", 45.0),
new Term("старый", 60.0)));
new FuzzyTerm("молодой", 30.0),
new FuzzyTerm("средний", 45.0),
new FuzzyTerm("старый", 60.0)));
return var.getTerms();
}
private List<Term> getIncomeValues() {
private List<FuzzyTerm> getIncomeValues() {
Variable var = new Variable("Income");
var.getTerms().addAll(Arrays.asList(
new Term("небольшой", 20000.0),
new Term("средний", 90000.0),
new Term("высокий", 200000.0)));
new FuzzyTerm("небольшой", 20000.0),
new FuzzyTerm("средний", 90000.0),
new FuzzyTerm("высокий", 200000.0)));
return var.getTerms();
}
}

View File

@ -4,14 +4,14 @@ import jakarta.persistence.Entity;
import ru.ulstu.fc.core.model.BaseEntity;
@Entity
public class Term extends BaseEntity {
public class FuzzyTerm extends BaseEntity {
private String description;
private Double value;
public Term() {
public FuzzyTerm() {
}
public Term(String description, Double value) {
public FuzzyTerm(String description, Double value) {
this.description = description;
this.value = value;
}

View File

@ -14,7 +14,7 @@ public class Variable extends BaseEntity {
private Project project;
private boolean isInput;
@OneToMany
private List<Term> terms = new ArrayList<>();
private List<FuzzyTerm> terms = new ArrayList<>();
public Variable() {
}
@ -23,7 +23,7 @@ public class Variable extends BaseEntity {
this.name = name;
}
public Variable(String name, List<Term> terms) {
public Variable(String name, List<FuzzyTerm> terms) {
this.name = name;
this.terms = terms;
}
@ -36,11 +36,11 @@ public class Variable extends BaseEntity {
this.name = name;
}
public List<Term> getTerms() {
public List<FuzzyTerm> getTerms() {
return terms;
}
public void setTerms(List<Term> terms) {
public void setTerms(List<FuzzyTerm> terms) {
this.terms = terms;
}

View File

@ -15,7 +15,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import ru.ulstu.fc.rule.model.OutputValue;
import ru.ulstu.fc.rule.model.Term;
import ru.ulstu.fc.rule.model.FuzzyTerm;
import ru.ulstu.fc.rule.model.Variable;
import java.util.List;
@ -131,20 +131,20 @@ public class FuzzyInferenceService {
public List<OutputValue> getFuzzyInference(Map<String, Double> vals) {
return getFuzzyInference(getDemoRules(), vals,
List.of(new Variable("возраст", List.of(
new Term("молодой", 35.0),
new Term("средний", 60.0),
new Term("старый", 100.0))
new FuzzyTerm("молодой", 35.0),
new FuzzyTerm("средний", 60.0),
new FuzzyTerm("старый", 100.0))
),
new Variable("доход", List.of(
new Term("небольшой", 35000.0),
new Term("средний", 100000.0),
new Term("высокий", 500000.0))
new FuzzyTerm("небольшой", 35000.0),
new FuzzyTerm("средний", 100000.0),
new FuzzyTerm("высокий", 500000.0))
)
),
new Variable("кредит", List.of(
new Term("небольшой", 20000.0),
new Term("средний", 100000.0),
new Term("большой", 1000000.0)))
new FuzzyTerm("небольшой", 20000.0),
new FuzzyTerm("средний", 100000.0),
new FuzzyTerm("большой", 1000000.0)))
);
}

View File

@ -29,7 +29,7 @@
data-width="90%">
<option th:each="ageValue : ${ageValues}"
th:value="${ageValue.value}"
th:utext="${ageValue.fuzzyTerm}">
th:utext="${ageValue.description}">
</option>
</select>
</div>
@ -44,7 +44,7 @@
data-width="90%">
<option th:each="incomeValue : ${incomeValues}"
th:value="${incomeValue.value}"
th:utext="${incomeValue.fuzzyTerm}">
th:utext="${incomeValue.description}">
</option>
</select>
</div>