Новый способ выбора юнита, с помощью точного совпадения по фразе
This commit is contained in:
parent
74ef11e253
commit
7bc6923ed4
@ -76,6 +76,13 @@ public class AutoResponder {
|
||||
private Unit nextUnit(@NonNull Set<Unit> nextUnits, String message) {
|
||||
Set<Unit> searchUnit = new HashSet<>();
|
||||
|
||||
nextUnits.stream()
|
||||
.filter(nextUnit -> nextUnit.getPhrase() != null
|
||||
&& !nextUnit.getPhrase().isEmpty()
|
||||
&& nextUnit.getPhrase().equalsIgnoreCase(message)
|
||||
)
|
||||
.forEach(searchUnit::add);
|
||||
|
||||
nextUnits.stream()
|
||||
.filter(nextUnit -> nextUnit.getPattern() != null && patternReg(nextUnit, message))
|
||||
.forEach(searchUnit::add);
|
||||
@ -84,9 +91,11 @@ public class AutoResponder {
|
||||
.filter(nextUnit -> percentageMatch(nextUnit, Parser.parse(message)) >= nextUnit.getMatchThreshold())
|
||||
.forEach(searchUnit::add);
|
||||
|
||||
nextUnits.stream()
|
||||
.filter(nextUnit -> (nextUnit.getPattern() == null && (nextUnit.getKeyWords() == null || nextUnit.getKeyWords().isEmpty())))
|
||||
.forEach(searchUnit::add);
|
||||
if (searchUnit.isEmpty()) {
|
||||
nextUnits.stream()
|
||||
.filter(nextUnit -> (nextUnit.getPattern() == null && (nextUnit.getKeyWords() == null || nextUnit.getKeyWords().isEmpty())))
|
||||
.forEach(searchUnit::add);
|
||||
}
|
||||
|
||||
return searchUnit.stream().max(UNIT_PRIORITY_COMPARATOR).orElseThrow(NotFoundUnitException::new);
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ public abstract class Unit {
|
||||
@Description("Ключевые слова")
|
||||
protected Set<String> keyWords;
|
||||
|
||||
@Description("Точная фраза")
|
||||
protected String phrase;
|
||||
|
||||
@Description("Регулярное выражение")
|
||||
protected Pattern pattern;
|
||||
|
||||
@ -36,8 +39,9 @@ public abstract class Unit {
|
||||
@Description("Множество следующих Unit в сценарии")
|
||||
protected Set<Unit> nextUnits;
|
||||
|
||||
protected Unit(Set<String> keyWords, Pattern pattern, Integer matchThreshold, Integer priority, Set<Unit> nextUnits) {
|
||||
protected Unit(Set<String> keyWords, String phrase, Pattern pattern, Integer matchThreshold, Integer priority, Set<Unit> nextUnits) {
|
||||
this.keyWords = keyWords;
|
||||
this.phrase = phrase;
|
||||
this.pattern = pattern;
|
||||
this.matchThreshold = Optional.ofNullable(matchThreshold).orElse(10);
|
||||
this.priority = Optional.ofNullable(priority).orElse(10);
|
||||
|
@ -18,13 +18,15 @@ public class TestUnit extends Unit {
|
||||
private String message;
|
||||
|
||||
@Builder
|
||||
public TestUnit(@Singular(value = "keyWord") Set<String> keyWords,
|
||||
public TestUnit(@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular(value = "nextUnit") Set<Unit> nextUnits,
|
||||
@Singular Set<Unit> nextUnits,
|
||||
String message) {
|
||||
super(keyWords, pattern, matchThreshold, priority, nextUnits);
|
||||
super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user