#3 -- Parse rule for list
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m10s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m10s
This commit is contained in:
parent
8d0b5cef99
commit
78fe8236be
@ -0,0 +1,37 @@
|
|||||||
|
package ru.ulstu.fc.project.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import org.springframework.security.access.annotation.Secured;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import ru.ulstu.fc.project.service.ProjectRulesService;
|
||||||
|
import ru.ulstu.fc.project.service.ProjectService;
|
||||||
|
import ru.ulstu.fc.project.service.ProjectVariableService;
|
||||||
|
import ru.ulstu.fc.user.model.UserRoleConstants;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@Hidden
|
||||||
|
@RequestMapping("runProject")
|
||||||
|
@Secured({UserRoleConstants.ADMIN})
|
||||||
|
public class ProjectRunController {
|
||||||
|
private final ProjectService projectService;
|
||||||
|
private final ProjectRulesService projectRulesService;
|
||||||
|
private final ProjectVariableService projectVariableService;
|
||||||
|
|
||||||
|
public ProjectRunController(ProjectService projectService,
|
||||||
|
ProjectRulesService projectRulesService,
|
||||||
|
ProjectVariableService projectVariableService) {
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.projectRulesService = projectRulesService;
|
||||||
|
this.projectVariableService = projectVariableService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("init/{projectId}")
|
||||||
|
public String getProjects(@PathVariable(value = "projectId") Integer projectId, Model model) {
|
||||||
|
model.addAttribute("project", projectService.getById(projectId));
|
||||||
|
return "project/init";
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RuleParseService {
|
public class FuzzyRuleParseService {
|
||||||
private final static String RU_IF_STATEMENT = "если";
|
private final static String RU_IF_STATEMENT = "если";
|
||||||
private final static String ENG_IF_STATEMENT = "if";
|
private final static String ENG_IF_STATEMENT = "if";
|
||||||
private final static String RU_THEN_STATEMENT = "то";
|
private final static String RU_THEN_STATEMENT = "то";
|
||||||
@ -21,7 +21,7 @@ public class RuleParseService {
|
|||||||
|
|
||||||
private final Engine fuzzyEngine;
|
private final Engine fuzzyEngine;
|
||||||
|
|
||||||
public RuleParseService(Engine fuzzyEngine) {
|
public FuzzyRuleParseService(Engine fuzzyEngine) {
|
||||||
this.fuzzyEngine = fuzzyEngine;
|
this.fuzzyEngine = fuzzyEngine;
|
||||||
}
|
}
|
||||||
|
|
@ -48,39 +48,52 @@
|
|||||||
<div class="row" th:each="r, iter : ${rules}">
|
<div class="row" th:each="r, iter : ${rules}">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<a th:href="@{'/rule/edit/' + ${projectId}+'/'+${r.id}}">
|
<a th:href="@{'/rule/edit/' + ${projectId}+'/'+${r.id}}">
|
||||||
<span class="badge badge-light" th:text="${iter.index+1} + '. ' + ${r.content}"></span>
|
<div class="rule row" th:text="${r.content}"></div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="col col-md-2 offset-md-3">
|
|
||||||
<span class="badge badge-primary">Переменная</span>
|
|
||||||
</div>
|
|
||||||
<div class="col col-md-2">
|
|
||||||
<span class="badge badge-light">есть</span>
|
|
||||||
</div>
|
|
||||||
<div class="col col-md-2">
|
|
||||||
<span class="badge badge-success">значение</span>
|
|
||||||
</div>
|
|
||||||
<div class="col col-md-1">
|
|
||||||
<span class="badge badge-danger">И / ИЛИ</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col col-md-2 offset-md-3">
|
|
||||||
<span class="badge badge-primary">Переменная</span>
|
|
||||||
</div>
|
|
||||||
<div class="col col-md-2">
|
|
||||||
<span class="badge badge-light">есть</span>
|
|
||||||
</div>
|
|
||||||
<div class="col col-md-2">
|
|
||||||
<span class="badge badge-success">значение</span>
|
|
||||||
</div>
|
|
||||||
<div class="col col-md-1">
|
|
||||||
<span class="badge badge-danger">И / ИЛИ</span>
|
|
||||||
</div>-->
|
|
||||||
</div>
|
</div>
|
||||||
<a th:href="@{'/rule/edit/' + ${projectId}+'/0'}" th:if="${not #lists.isEmpty(variables)}"
|
<a th:href="@{'/rule/edit/' + ${projectId}+'/0'}" th:if="${not #lists.isEmpty(variables)}"
|
||||||
class="btn btn-outline-dark">Добавить правило</a>
|
class="btn btn-outline-dark">Добавить правило</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
function getAntecedent(rule) {
|
||||||
|
withoutIf = rule.split('if');
|
||||||
|
return withoutIf[1].trim().split('then')[0].trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAntecedentComponents(antecedent) {
|
||||||
|
return antecedent.split('and').map((i) => i.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVariable(antecedent) {
|
||||||
|
return antecedent.split('is')[0].trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVariableValue(antecedent) {
|
||||||
|
return antecedent.split('is')[1].trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function addRule(index, el, rule) {
|
||||||
|
ruleHtml = "<div class='col col-md-12'><span class='badge badge-light'>"+(index+1) +". Если</span></div>"
|
||||||
|
antecedentComponents = getAntecedentComponents(getAntecedent(rule));
|
||||||
|
for (let i = 0; i < antecedentComponents.length; i++) {
|
||||||
|
a = antecedentComponents[i];
|
||||||
|
if (i > 0) {
|
||||||
|
ruleHtml += "<div class='col col-md-12'><span class='badge badge-danger'>И</span></div>";
|
||||||
|
}
|
||||||
|
ruleHtml += "<div class='col col-md-2 offset-md-1'><span class='badge badge-primary'>"+getVariable(a)+"</span></div>";
|
||||||
|
ruleHtml += "<div class='col col-md-2'><span class='badge badge-light'>есть</span></div>";
|
||||||
|
ruleHtml += "<div class='col col-md-2'><span class='badge badge-success'>"+getVariableValue(a)+"</span></div>";
|
||||||
|
}
|
||||||
|
$(el).html(ruleHtml);
|
||||||
|
}
|
||||||
|
$('.rule').each(function(index ) {
|
||||||
|
addRule(index, $(this), $(this).text());
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -12,9 +12,9 @@
|
|||||||
<input type="hidden" th:field="*{projectId}">
|
<input type="hidden" th:field="*{projectId}">
|
||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="content">Правило</label>
|
<label for="ruleContent">Правило</label>
|
||||||
<input th:field="*{content}"
|
<input th:field="*{content}"
|
||||||
id="content"
|
id="ruleContent"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user