#2 -- Add inference dtos #22
@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import ru.ulstu.fc.rule.model.FuzzyRuleForm;
|
import ru.ulstu.fc.rule.model.FuzzyRuleForm;
|
||||||
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
||||||
import ru.ulstu.fc.rule.model.Variable;
|
import ru.ulstu.fc.rule.model.dto.VariableDto;
|
||||||
import ru.ulstu.fc.rule.service.FuzzyRuleService;
|
import ru.ulstu.fc.rule.service.FuzzyRuleService;
|
||||||
import ru.ulstu.fc.rule.service.FuzzyTermService;
|
import ru.ulstu.fc.rule.service.FuzzyTermService;
|
||||||
import ru.ulstu.fc.rule.service.VariableService;
|
import ru.ulstu.fc.rule.service.VariableService;
|
||||||
@ -65,11 +65,10 @@ public class FuzzyRuleController {
|
|||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@GetMapping("/getVariables/{projectId}")
|
@GetMapping("/getVariables/{projectId}")
|
||||||
public List<Variable> getVariables(@PathVariable("projectId") Integer projectId,
|
public List<VariableDto> getVariables(@PathVariable("projectId") Integer projectId,
|
||||||
final HttpServletResponse response) {
|
final HttpServletResponse response) {
|
||||||
response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform");
|
response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform");
|
||||||
//TODO: return DTO without terms
|
return variableService.getAllDtoByProject(projectId);
|
||||||
return variableService.getAllByProject(projectId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -1,9 +1,21 @@
|
|||||||
package ru.ulstu.fc.rule.model.dto;
|
package ru.ulstu.fc.rule.model.dto;
|
||||||
|
|
||||||
|
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
||||||
|
|
||||||
public class FuzzyTermDto {
|
public class FuzzyTermDto {
|
||||||
|
private Integer id;
|
||||||
private String description;
|
private String description;
|
||||||
private Double crispValue;
|
private Double crispValue;
|
||||||
|
|
||||||
|
public FuzzyTermDto() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FuzzyTermDto(FuzzyTerm fuzzyTerm) {
|
||||||
|
this.description = fuzzyTerm.getDescription();
|
||||||
|
this.crispValue = fuzzyTerm.getCrispValue();
|
||||||
|
this.id = fuzzyTerm.getId();
|
||||||
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
@ -19,4 +31,12 @@ public class FuzzyTermDto {
|
|||||||
public void setCrispValue(Double crispValue) {
|
public void setCrispValue(Double crispValue) {
|
||||||
this.crispValue = crispValue;
|
this.crispValue = crispValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,23 @@
|
|||||||
package ru.ulstu.fc.rule.model.dto;
|
package ru.ulstu.fc.rule.model.dto;
|
||||||
|
|
||||||
|
import ru.ulstu.fc.rule.model.Variable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class VariableDto {
|
public class VariableDto {
|
||||||
|
private Integer id;
|
||||||
private String name;
|
private String name;
|
||||||
private List<FuzzyTermDto> terms;
|
private List<FuzzyTermDto> terms = new ArrayList<>();
|
||||||
|
|
||||||
|
public VariableDto() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public VariableDto(Variable variable) {
|
||||||
|
this.id = variable.getId();
|
||||||
|
this.name = variable.getName();
|
||||||
|
this.terms = variable.getFuzzyTerms().stream().map(FuzzyTermDto::new).toList();
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -21,4 +34,12 @@ public class VariableDto {
|
|||||||
public void setTerms(List<FuzzyTermDto> terms) {
|
public void setTerms(List<FuzzyTermDto> terms) {
|
||||||
this.terms = terms;
|
this.terms = terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import ru.ulstu.fc.project.service.ProjectService;
|
|||||||
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
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.model.VariableForm;
|
import ru.ulstu.fc.rule.model.VariableForm;
|
||||||
|
import ru.ulstu.fc.rule.model.dto.VariableDto;
|
||||||
import ru.ulstu.fc.rule.repository.VariableRepository;
|
import ru.ulstu.fc.rule.repository.VariableRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -69,6 +70,13 @@ public class VariableService {
|
|||||||
return variableRepository.getByProject(projectService.getById(projectId));
|
return variableRepository.getByProject(projectService.getById(projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<VariableDto> getAllDtoByProject(Integer projectId) {
|
||||||
|
return variableRepository.getByProject(projectService.getById(projectId))
|
||||||
|
.stream()
|
||||||
|
.map(VariableDto::new)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
public void checkIsCurrentUserVariableWithThrow(Variable variable) {
|
public void checkIsCurrentUserVariableWithThrow(Variable variable) {
|
||||||
projectService.checkIsCurrentUserProjectWithThrow(variable.getProject());
|
projectService.checkIsCurrentUserProjectWithThrow(variable.getProject());
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@ function getAntecedent(rule) {
|
|||||||
return withoutIf[1].trim().split('then')[0].trim();
|
return withoutIf[1].trim().split('then')[0].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove duplicate
|
function getRuleComponents(antecedent) {
|
||||||
function getAntecedentComponents(antecedent) {
|
|
||||||
return antecedent.split('and').map((i) => i.trim());
|
return antecedent.split('and').map((i) => i.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,11 +15,6 @@ function getConsequent(rule) {
|
|||||||
return withoutIf[1].trim().split('then')[1].trim();
|
return withoutIf[1].trim().split('then')[1].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove duplicate
|
|
||||||
function getConsequentComponents(consequent) {
|
|
||||||
return consequent.split('and').map((i) => i.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
// common
|
// common
|
||||||
function getVariable(variableComponents) {
|
function getVariable(variableComponents) {
|
||||||
return variableComponents.split('is')[0].trim();
|
return variableComponents.split('is')[0].trim();
|
||||||
@ -56,8 +50,6 @@ function showFeedbackMessage(message, type) {
|
|||||||
/* exported errorHandler */
|
/* exported errorHandler */
|
||||||
function errorHandler(response, callBack, errorCallBack) {
|
function errorHandler(response, callBack, errorCallBack) {
|
||||||
if (!isEmpty(response.error)) {
|
if (!isEmpty(response.error)) {
|
||||||
// TODO: add l10n
|
|
||||||
// showFeedbackMessage(response.error.code + ": " + response.error.message, MessageTypesEnum.DANGER);
|
|
||||||
if (!isEmpty(errorCallBack)) {
|
if (!isEmpty(errorCallBack)) {
|
||||||
errorCallBack(response.data);
|
errorCallBack(response.data);
|
||||||
}
|
}
|
||||||
@ -237,7 +229,7 @@ function addConsequent(parentElement, projectId, variableVal, termVal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addAntecedentFromRule(parentElement, projectId, ruleContent) {
|
function addAntecedentFromRule(parentElement, projectId, ruleContent) {
|
||||||
let antecedentComponents = getAntecedentComponents(getAntecedent(ruleContent));
|
let antecedentComponents = getRuleComponents(getAntecedent(ruleContent));
|
||||||
for (let i = 0; i < antecedentComponents.length; i++) {
|
for (let i = 0; i < antecedentComponents.length; i++) {
|
||||||
let a = antecedentComponents[i];
|
let a = antecedentComponents[i];
|
||||||
addAntecedent(parentElement, projectId, getVariable(a), getVariableValue(a));
|
addAntecedent(parentElement, projectId, getVariable(a), getVariableValue(a));
|
||||||
@ -245,7 +237,7 @@ function addAntecedentFromRule(parentElement, projectId, ruleContent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addConsequentFromRule(parentElement, projectId, ruleContent) {
|
function addConsequentFromRule(parentElement, projectId, ruleContent) {
|
||||||
let consequentComponents = getConsequentComponents(getConsequent(ruleContent));
|
let consequentComponents = getRuleComponents(getConsequent(ruleContent));
|
||||||
for (let i = 0; i < consequentComponents.length; i++) {
|
for (let i = 0; i < consequentComponents.length; i++) {
|
||||||
let c = consequentComponents[i];
|
let c = consequentComponents[i];
|
||||||
addConsequent(parentElement, projectId, getVariable(c), getVariableValue(c));
|
addConsequent(parentElement, projectId, getVariable(c), getVariableValue(c));
|
||||||
|
@ -61,8 +61,8 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function addRule(index, el, rule) {
|
function addRule(index, el, rule) {
|
||||||
let ruleHtml = "<div class='col col-md-12'><span class='badge badge-light'>" + (index + 1) + ". Если</span></div>"
|
let ruleHtml = "<div class='col col-md-12'><span class='badge badge-light'>" + (index + 1) + ". Если</span></div>"
|
||||||
let antecedentComponents = getAntecedentComponents(getAntecedent(rule));
|
let antecedentComponents = getRuleComponents(getAntecedent(rule));
|
||||||
let consequentComponents = getConsequentComponents(getConsequent(rule));
|
let consequentComponents = getRuleComponents(getConsequent(rule));
|
||||||
for (let i = 0; i < antecedentComponents.length; i++) {
|
for (let i = 0; i < antecedentComponents.length; i++) {
|
||||||
let a = antecedentComponents[i];
|
let a = antecedentComponents[i];
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user