From f391f37f13a1c9e0ff2d1207d84c513574803ef7 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 21 Jan 2019 10:06:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Теперь юнит выводится только если процентное соотношение слов на которые он должен сработать в тексте больше или равно заданого значения в юните --- pom.xml | 2 +- .../org/sadtech/autoresponder/Autoresponder.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 46e6368..3ff1b92 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.autoresponder core - 1.1.0-RELEASE + 1.1.1-SNAPSHOT diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 46171e9..a3154f5 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -1,5 +1,6 @@ package org.sadtech.autoresponder; +import lombok.extern.log4j.Log4j; import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.entity.compare.UnitPriorityComparator; @@ -7,9 +8,11 @@ import org.sadtech.autoresponder.service.PersonService; import org.sadtech.autoresponder.service.UnitService; import org.sadtech.autoresponder.submodule.parser.Parser; -import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; +@Log4j public class Autoresponder { private UnitService unitService; @@ -48,10 +51,17 @@ public class Autoresponder { Parser parser = new Parser(); parser.setText(message); parser.parse(); - return nextUnits.stream().filter(nextUnit -> !Collections.disjoint(nextUnit.getKeyWords(), parser.getWords())).max(new UnitPriorityComparator()).get(); + return nextUnits.stream().filter(nextUnit -> textPercentageMatch(nextUnit, parser.getWords()) >= nextUnit.getMatchThreshold()).max(new UnitPriorityComparator()).get(); } else { return null; } } + private Double textPercentageMatch(Unit unit, Set words) { + Set temp = new HashSet<>(unit.getKeyWords()); + temp.retainAll(words); + log.info((temp.size() / unit.getKeyWords().size()) * 100); + return (double) (temp.size() / unit.getKeyWords().size()) * 100; + } + }