From f017148ef7965ead9008e0824b0c1055a9cbd918 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 16 May 2019 00:47:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=83=D1=87=D0=B8=D0=BB=D1=81=D1=8F=20=D1=83=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D1=8F=D1=82=D1=8C=20=D0=BF=D1=80=D0=B5=D0=B4=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=20=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sadtech/autoresponder/Autoresponder.java | 3 --- .../java/org/sadtech/autoresponder/entity/Unit.java | 10 +++++----- .../org/sadtech/autoresponder/entity/UnitPointer.java | 8 ++++++++ .../java/org/sadtech/autoresponder/util/Parser.java | 8 ++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) 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; }