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