From dd58262b0ab894ab23e2a5a60bd8d78fbd2ca895 Mon Sep 17 00:00:00 2001 From: lexluo09 <39718951+lexluo09@users.noreply.github.com> Date: Tue, 10 Sep 2024 23:16:16 +0800 Subject: [PATCH] [improvement](chat) Use the word-based approach for comparing Schema Mapping rules and fix the issue where the results were not being modified. --- .../headless/chat/mapper/MapFilter.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/mapper/MapFilter.java b/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/mapper/MapFilter.java index 23e986a6e..bec13b67a 100644 --- a/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/mapper/MapFilter.java +++ b/headless/chat/src/main/java/com/tencent/supersonic/headless/chat/mapper/MapFilter.java @@ -98,14 +98,14 @@ public static void filterByQueryDataType( public static void filterByRules(ChatQueryContext chatQueryContext) { Map> dataSetElementMatches = chatQueryContext.getMapInfo().getDataSetElementMatches(); + for (Map.Entry> entry : dataSetElementMatches.entrySet()) { - List elementMatches = entry.getValue(); - filterByExactMatch(elementMatches); - filterInExactMatch(elementMatches); + filterByExactMatch(entry.getValue()); + filterInExactMatch(entry.getValue()); } } - public static List filterByExactMatch(List matches) { + public static void filterByExactMatch(List matches) { // Group by detectWord Map> groupedByDetectWord = matches.stream().collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord)); @@ -139,14 +139,15 @@ public static List filterByExactMatch(List filterInExactMatch(List matches) { + public static void filterInExactMatch(List matches) { Map> fullMatches = matches.stream() .filter(schemaElementMatch -> schemaElementMatch.isFullMatched()) - .collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord)); + .collect(Collectors.groupingBy(SchemaElementMatch::getWord)); Set keys = new HashSet<>(fullMatches.keySet()); for (String key1 : keys) { for (String key2 : keys) { @@ -163,6 +164,7 @@ public static List filterInExactMatch(List mergedMatches = new ArrayList<>(); fullMatches.values().forEach(mergedMatches::addAll); mergedMatches.addAll(notFullMatches); - return mergedMatches; + matches.clear(); + matches.addAll(mergedMatches); } }