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

View File

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

View File

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

View File

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

View File

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