WIP: страницы для правил #62
@ -11,12 +11,9 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
|
||||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
@ApiIgnore
|
@ApiIgnore
|
||||||
class GlobalDefaultExceptionHandler {
|
class GlobalDefaultExceptionHandler {
|
||||||
@ -24,15 +21,15 @@ class GlobalDefaultExceptionHandler {
|
|||||||
public static final String DEFAULT_ERROR_VIEW = "error";
|
public static final String DEFAULT_ERROR_VIEW = "error";
|
||||||
|
|
||||||
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
// @ExceptionHandler(value = Exception.class)
|
||||||
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) {
|
// public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) {
|
||||||
LOG.warn(e.getMessage());
|
// LOG.warn(e.getMessage());
|
||||||
ModelAndView mav = new ModelAndView();
|
// ModelAndView mav = new ModelAndView();
|
||||||
mav.addObject("exception", e);
|
// mav.addObject("exception", e);
|
||||||
mav.addObject("url", req.getRequestURL());
|
// mav.addObject("url", req.getRequestURL());
|
||||||
mav.setViewName(DEFAULT_ERROR_VIEW);
|
// mav.setViewName(DEFAULT_ERROR_VIEW);
|
||||||
return mav;
|
// return mav;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@ExceptionHandler(NoHandlerFoundException.class)
|
@ExceptionHandler(NoHandlerFoundException.class)
|
||||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||||
|
@ -2,6 +2,9 @@ package ru.ulstu.extractor.rule.service;
|
|||||||
|
|
||||||
import com.fuzzylite.Engine;
|
import com.fuzzylite.Engine;
|
||||||
import com.fuzzylite.activation.Highest;
|
import com.fuzzylite.activation.Highest;
|
||||||
|
import com.fuzzylite.defuzzifier.Centroid;
|
||||||
|
import com.fuzzylite.norm.s.BoundedSum;
|
||||||
|
import com.fuzzylite.norm.s.Maximum;
|
||||||
import com.fuzzylite.norm.t.AlgebraicProduct;
|
import com.fuzzylite.norm.t.AlgebraicProduct;
|
||||||
import com.fuzzylite.rule.Rule;
|
import com.fuzzylite.rule.Rule;
|
||||||
import com.fuzzylite.rule.RuleBlock;
|
import com.fuzzylite.rule.RuleBlock;
|
||||||
@ -52,10 +55,10 @@ public class FuzzyInferenceService {
|
|||||||
input.setName(key);
|
input.setName(key);
|
||||||
input.setDescription("");
|
input.setDescription("");
|
||||||
input.setEnabled(true);
|
input.setEnabled(true);
|
||||||
input.setRange(0.000, antecedentValues.size() + 1);
|
input.setRange(-0.1, antecedentValues.size() + 1.1);
|
||||||
input.setLockValueInRange(false);
|
input.setLockValueInRange(false);
|
||||||
for (int i = 0; i < antecedentValues.size(); i++) {
|
for (int i = 0; i < antecedentValues.size(); i++) {
|
||||||
input.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2));
|
input.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i - 0.1, i + 2.1));
|
||||||
}
|
}
|
||||||
engine.addInputVariable(input);
|
engine.addInputVariable(input);
|
||||||
});
|
});
|
||||||
@ -64,10 +67,13 @@ public class FuzzyInferenceService {
|
|||||||
output.setName(OUTPUT_VARIABLE_NAME);
|
output.setName(OUTPUT_VARIABLE_NAME);
|
||||||
output.setDescription("");
|
output.setDescription("");
|
||||||
output.setEnabled(true);
|
output.setEnabled(true);
|
||||||
output.setRange(0.000, antecedentValues.size() + 1);
|
output.setRange(-0.1, antecedentValues.size() + 0.1);
|
||||||
|
output.setAggregation(new Maximum());
|
||||||
|
output.setDefuzzifier(new Centroid(100));
|
||||||
|
output.setDefaultValue(Double.NaN);
|
||||||
output.setLockValueInRange(false);
|
output.setLockValueInRange(false);
|
||||||
for (int i = 0; i < antecedentValues.size(); i++) {
|
for (int i = 0; i < antecedentValues.size(); i++) {
|
||||||
output.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2));
|
output.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i - 0.1, i + 2.1));
|
||||||
}
|
}
|
||||||
engine.addOutputVariable(output);
|
engine.addOutputVariable(output);
|
||||||
|
|
||||||
@ -75,8 +81,8 @@ public class FuzzyInferenceService {
|
|||||||
mamdani.setName("mamdani");
|
mamdani.setName("mamdani");
|
||||||
mamdani.setDescription("");
|
mamdani.setDescription("");
|
||||||
mamdani.setEnabled(true);
|
mamdani.setEnabled(true);
|
||||||
mamdani.setConjunction(null);
|
mamdani.setConjunction(new AlgebraicProduct());
|
||||||
mamdani.setDisjunction(null);
|
mamdani.setDisjunction(new BoundedSum());
|
||||||
mamdani.setImplication(new AlgebraicProduct());
|
mamdani.setImplication(new AlgebraicProduct());
|
||||||
mamdani.setActivation(new Highest());
|
mamdani.setActivation(new Highest());
|
||||||
getRulesFromDb().forEach(r -> mamdani.addRule(Rule.parse(r, engine)));
|
getRulesFromDb().forEach(r -> mamdani.addRule(Rule.parse(r, engine)));
|
||||||
@ -94,8 +100,8 @@ public class FuzzyInferenceService {
|
|||||||
Engine engine = getFuzzyEngine();
|
Engine engine = getFuzzyEngine();
|
||||||
List<AntecedentValue> antecedentValues = antecedentValueService.getList();
|
List<AntecedentValue> antecedentValues = antecedentValueService.getList();
|
||||||
Map<String, Double> variableValues = new HashMap<>();
|
Map<String, Double> variableValues = new HashMap<>();
|
||||||
variableValues.put("COMMITS", 10.0);
|
variableValues.put("COMMITS", 0.0);
|
||||||
variableValues.put("AUTHORS", 10.0);
|
variableValues.put("AUTHORS", 0.0);
|
||||||
engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues));
|
engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues));
|
||||||
return getConsequent(engine, variableValues);
|
return getConsequent(engine, variableValues);
|
||||||
}
|
}
|
||||||
@ -107,6 +113,10 @@ public class FuzzyInferenceService {
|
|||||||
inputVariable.setValue(variableValue.getValue());
|
inputVariable.setValue(variableValue.getValue());
|
||||||
}
|
}
|
||||||
engine.process();
|
engine.process();
|
||||||
return outputVariable == null ? "" : outputVariable.fuzzyOutputValue();
|
if (outputVariable != null) {
|
||||||
|
outputVariable.defuzzify();
|
||||||
|
}
|
||||||
|
return outputVariable == null ? "" : outputVariable.highestMembership(outputVariable.getValue()).getSecond().getName();
|
||||||
|
//return outputVariable == null ? "" : outputVariable.fuzzyOutputValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user