Compare commits
No commits in common. "4ab033d5a2281040240165f272e40de0eefa1211" and "38642e593e7c5e56f678d4fd1ef7e1950a6a0ab6" have entirely different histories.
4ab033d5a2
...
38642e593e
@ -13,11 +13,6 @@ public class ProjectDto {
|
|||||||
public ProjectDto() {
|
public ProjectDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectDto(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ProjectDto(Project project) {
|
public ProjectDto(Project project) {
|
||||||
this.id = project.getId();
|
this.id = project.getId();
|
||||||
this.name = project.getName();
|
this.name = project.getName();
|
||||||
|
@ -5,7 +5,6 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.fc.project.service.ProjectRulesService;
|
import ru.ulstu.fc.project.service.ProjectRulesService;
|
||||||
@ -60,7 +59,7 @@ public class FuzzyRuleRestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("generate-rules/{projectId}")
|
@PostMapping("generate-rules/{projectId}")
|
||||||
public void generateRules(@PathVariable("projectId") Integer projectId, @RequestBody FuzzyRuleDataDto fuzzyRuleDataDto) {
|
public void generateRules(@PathVariable("projectId") Integer projectId, FuzzyRuleDataDto fuzzyRuleDataDto) {
|
||||||
fuzzyRuleParseService.generateRules(projectId, fuzzyRuleDataDto);
|
fuzzyRuleParseService.generateRules(projectId, fuzzyRuleDataDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import ru.ulstu.fc.rule.model.InferenceData;
|
import ru.ulstu.fc.rule.model.InferenceData;
|
||||||
import ru.ulstu.fc.rule.model.OutputValue;
|
import ru.ulstu.fc.rule.model.OutputValue;
|
||||||
import ru.ulstu.fc.rule.model.ProjectInferenceData;
|
import ru.ulstu.fc.rule.model.ProjectInferenceData;
|
||||||
import ru.ulstu.fc.rule.model.dto.FuzzyRuleDataDto;
|
|
||||||
import ru.ulstu.fc.rule.service.FuzzyInferenceService;
|
import ru.ulstu.fc.rule.service.FuzzyInferenceService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -29,13 +28,8 @@ public class InferenceRestController {
|
|||||||
inferenceData.getOutputVariables());
|
inferenceData.getOutputVariables());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "get-project-inference", method = RequestMethod.POST)
|
@RequestMapping(value = "getProjectInference", method = RequestMethod.POST)
|
||||||
public List<OutputValue> getProjectInference(@RequestBody ProjectInferenceData projectInferenceData) {
|
public List<OutputValue> getProjectInference(@RequestBody ProjectInferenceData projectInferenceData) {
|
||||||
return fuzzyInferenceService.getProjectFuzzyInference(projectInferenceData);
|
return fuzzyInferenceService.getProjectFuzzyInference(projectInferenceData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "get-inference-by-generated-rules", method = RequestMethod.POST)
|
|
||||||
public List<OutputValue> getInferenceByGenerateRules(@RequestBody FuzzyRuleDataDto fuzzyRuleDataDto) {
|
|
||||||
return fuzzyInferenceService.getProjectFuzzyInferenceByGeneratedRules(fuzzyRuleDataDto);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,4 @@ public interface VariableRepository extends JpaRepository<Variable, Integer> {
|
|||||||
@Query("DELETE FROM Variable v WHERE v.project.id = :projectId")
|
@Query("DELETE FROM Variable v WHERE v.project.id = :projectId")
|
||||||
@Modifying
|
@Modifying
|
||||||
void deleteAllByProjectId(@Param("projectId") Integer projectId);
|
void deleteAllByProjectId(@Param("projectId") Integer projectId);
|
||||||
|
|
||||||
@Query("SELECT v FROM Variable v WHERE v.project = :project AND v.input = true AND v.name = :name")
|
|
||||||
Variable getByProjectAndName(@Param("project") Project project, @Param("name") String name);
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,9 @@ import com.fuzzylite.rule.RuleBlock;
|
|||||||
import com.fuzzylite.term.Triangle;
|
import com.fuzzylite.term.Triangle;
|
||||||
import com.fuzzylite.variable.InputVariable;
|
import com.fuzzylite.variable.InputVariable;
|
||||||
import com.fuzzylite.variable.OutputVariable;
|
import com.fuzzylite.variable.OutputVariable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.fc.project.model.ProjectDto;
|
|
||||||
import ru.ulstu.fc.project.service.ProjectRulesService;
|
import ru.ulstu.fc.project.service.ProjectRulesService;
|
||||||
import ru.ulstu.fc.project.service.ProjectService;
|
import ru.ulstu.fc.project.service.ProjectService;
|
||||||
import ru.ulstu.fc.project.service.ProjectVariableService;
|
import ru.ulstu.fc.project.service.ProjectVariableService;
|
||||||
@ -21,20 +22,17 @@ import ru.ulstu.fc.rule.model.FuzzyTerm;
|
|||||||
import ru.ulstu.fc.rule.model.OutputValue;
|
import ru.ulstu.fc.rule.model.OutputValue;
|
||||||
import ru.ulstu.fc.rule.model.ProjectInferenceData;
|
import ru.ulstu.fc.rule.model.ProjectInferenceData;
|
||||||
import ru.ulstu.fc.rule.model.Variable;
|
import ru.ulstu.fc.rule.model.Variable;
|
||||||
import ru.ulstu.fc.rule.model.dto.FuzzyRuleDataDto;
|
|
||||||
import ru.ulstu.fc.rule.model.dto.VariableValueDto;
|
import ru.ulstu.fc.rule.model.dto.VariableValueDto;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FuzzyInferenceService {
|
public class FuzzyInferenceService {
|
||||||
|
private final static Logger LOG = LoggerFactory.getLogger(FuzzyInferenceService.class);
|
||||||
private final static String OUTPUT_VARIABLE_NAME = "кредит";
|
private final static String OUTPUT_VARIABLE_NAME = "кредит";
|
||||||
private final static String RULE_TEMPLATE = "if %s is %s and %s is %s then "
|
private final static String RULE_TEMPLATE = "if %s is %s and %s is %s then "
|
||||||
+ OUTPUT_VARIABLE_NAME
|
+ OUTPUT_VARIABLE_NAME
|
||||||
@ -42,21 +40,14 @@ public class FuzzyInferenceService {
|
|||||||
private final static String NO_RESULT = "Нет результата";
|
private final static String NO_RESULT = "Нет результата";
|
||||||
private final Engine fuzzyEngine;
|
private final Engine fuzzyEngine;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
private final VariableService variableService;
|
private final FuzzyRuleService fuzzyRuleService;
|
||||||
private final FuzzyRuleParseService fuzzyRuleParseService;
|
|
||||||
private final ProjectRulesService projectRulesService;
|
private final ProjectRulesService projectRulesService;
|
||||||
private final ProjectVariableService projectVariableService;
|
private final ProjectVariableService projectVariableService;
|
||||||
|
|
||||||
public FuzzyInferenceService(Engine fuzzyEngine,
|
public FuzzyInferenceService(Engine fuzzyEngine, ProjectService projectService, FuzzyRuleService fuzzyRuleService, ProjectRulesService projectRulesService, ProjectVariableService projectVariableService) {
|
||||||
ProjectService projectService,
|
|
||||||
VariableService variableService,
|
|
||||||
FuzzyRuleParseService fuzzyRuleParseService,
|
|
||||||
ProjectRulesService projectRulesService,
|
|
||||||
ProjectVariableService projectVariableService) {
|
|
||||||
this.fuzzyEngine = fuzzyEngine;
|
this.fuzzyEngine = fuzzyEngine;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
this.variableService = variableService;
|
this.fuzzyRuleService = fuzzyRuleService;
|
||||||
this.fuzzyRuleParseService = fuzzyRuleParseService;
|
|
||||||
this.projectRulesService = projectRulesService;
|
this.projectRulesService = projectRulesService;
|
||||||
this.projectVariableService = projectVariableService;
|
this.projectVariableService = projectVariableService;
|
||||||
}
|
}
|
||||||
@ -211,24 +202,4 @@ public class FuzzyInferenceService {
|
|||||||
inputVariables,
|
inputVariables,
|
||||||
outputVariables);
|
outputVariables);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public List<OutputValue> getProjectFuzzyInferenceByGeneratedRules(FuzzyRuleDataDto fuzzyRuleDataDto) {
|
|
||||||
ProjectDto projectDto = projectService.save(new ProjectDto(new Date().toString()));
|
|
||||||
fuzzyRuleParseService.generateRules(projectDto.getId(), fuzzyRuleDataDto);
|
|
||||||
Map<String, Double> variableValues = new HashMap<>();
|
|
||||||
List<String> labels = new LinkedList<>(Arrays.asList(fuzzyRuleDataDto.getFuzzyTerms()));
|
|
||||||
while (labels.size() > fuzzyRuleDataDto.getWindow()) {
|
|
||||||
labels.removeFirst();
|
|
||||||
}
|
|
||||||
for (int i = 0; i < labels.size(); i++) {
|
|
||||||
String label = labels.get(i);
|
|
||||||
variableValues.put("fuzzyLevel" + i,
|
|
||||||
variableService.getByProjectAndName(projectDto.getId(), "fuzzyLevel" + i)
|
|
||||||
.getFuzzyTerms()
|
|
||||||
.stream()
|
|
||||||
.filter(ft -> ft.getDescription().equals(label))
|
|
||||||
.mapToDouble(FuzzyTerm::getCrispValue).findAny().getAsDouble());
|
|
||||||
}
|
|
||||||
return getProjectFuzzyInference(projectDto.getId(), variableValues);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -89,8 +89,4 @@ public class VariableService {
|
|||||||
public void clearVariables(Integer projectId) {
|
public void clearVariables(Integer projectId) {
|
||||||
variableRepository.deleteAllByProjectId(projectId);
|
variableRepository.deleteAllByProjectId(projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Variable getByProjectAndName(Integer projectId, String name) {
|
|
||||||
return variableRepository.getByProjectAndName(projectService.getById(projectId), name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user