diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 6c081cf..80b104f 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -40,9 +40,6 @@ public class Autoresponder { this.defaultUnit = defaultUnit; } - /* - Возвращает unit на основании сообщения пользователя - */ public Unit answer(Integer personId, String message) { UnitPointer unitPointer = checkAndAddPerson(personId); Unit unit; diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index 4efc004..3880082 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -17,11 +17,11 @@ public abstract class Unit { private Integer priority = 10; private Set nextUnits; - public void setKeyWord(String... keyWords) { + public void setKeyWord(String... keyWord) { if (this.keyWords == null) { this.keyWords = new HashSet<>(); } - this.keyWords.addAll(Arrays.asList(keyWords)); + this.keyWords.addAll(Arrays.asList(keyWord)); } public void setKeyWords(Set keyWords) { @@ -35,11 +35,11 @@ public abstract class Unit { return keyWords; } - public void setNextUnit(Unit... units) { + public void setNextUnit(Unit... unit) { if (nextUnits == null) { nextUnits = new HashSet<>(); } - nextUnits.addAll(Arrays.asList(units)); + nextUnits.addAll(Arrays.asList(unit)); } public void setNextUnits(Set nextUnits) { @@ -80,7 +80,7 @@ public abstract class Unit { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof Unit)) return false; Unit unit = (Unit) o; return Objects.equals(keyWords, unit.keyWords) && Objects.equals(pattern, unit.pattern) && diff --git a/src/main/java/org/sadtech/autoresponder/entity/UnitPointer.java b/src/main/java/org/sadtech/autoresponder/entity/UnitPointer.java index 84eb190..271c5c4 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/UnitPointer.java +++ b/src/main/java/org/sadtech/autoresponder/entity/UnitPointer.java @@ -48,4 +48,12 @@ public class UnitPointer { public int hashCode() { return Objects.hash(entityId, unit); } + + @Override + public String toString() { + return "UnitPointer{" + + "entityId=" + entityId + + ", unit=" + unit + + '}'; + } } diff --git a/src/main/java/org/sadtech/autoresponder/util/Parser.java b/src/main/java/org/sadtech/autoresponder/util/Parser.java index 9fc5d54..4466194 100644 --- a/src/main/java/org/sadtech/autoresponder/util/Parser.java +++ b/src/main/java/org/sadtech/autoresponder/util/Parser.java @@ -4,12 +4,19 @@ import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; /* Возвращает Set слов из текста */ public class Parser { + private static final Set pretexts = Stream + .of("в", "без", "до", "из", "к", "на", "по", "о", "от", "перед", "при", "с", "у", "за", "над", "об", + "под", "про", "для") + .collect(Collectors.toSet()); + private Parser() { throw new IllegalStateException("Utility Class"); } @@ -21,6 +28,7 @@ public class Parser { while (m.find()) { words.add(m.group().toLowerCase()); } + words.removeAll(pretexts); return words; }