[improvement](chat) Use the word-based approach for comparing Schema Mapping rules and fix the issue where the results were not being modified. (#1650)

This commit is contained in:
lexluo09
2024-09-10 23:21:12 +08:00
committed by GitHub
parent 879696e493
commit fb96ce5843

View File

@@ -98,14 +98,14 @@ public class MapFilter {
public static void filterByRules(ChatQueryContext chatQueryContext) { public static void filterByRules(ChatQueryContext chatQueryContext) {
Map<Long, List<SchemaElementMatch>> dataSetElementMatches = Map<Long, List<SchemaElementMatch>> dataSetElementMatches =
chatQueryContext.getMapInfo().getDataSetElementMatches(); chatQueryContext.getMapInfo().getDataSetElementMatches();
for (Map.Entry<Long, List<SchemaElementMatch>> entry : dataSetElementMatches.entrySet()) { for (Map.Entry<Long, List<SchemaElementMatch>> entry : dataSetElementMatches.entrySet()) {
List<SchemaElementMatch> elementMatches = entry.getValue(); filterByExactMatch(entry.getValue());
filterByExactMatch(elementMatches); filterInExactMatch(entry.getValue());
filterInExactMatch(elementMatches);
} }
} }
public static List<SchemaElementMatch> filterByExactMatch(List<SchemaElementMatch> matches) { public static void filterByExactMatch(List<SchemaElementMatch> matches) {
// Group by detectWord // Group by detectWord
Map<String, List<SchemaElementMatch>> groupedByDetectWord = Map<String, List<SchemaElementMatch>> groupedByDetectWord =
matches.stream().collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord)); matches.stream().collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord));
@@ -139,14 +139,15 @@ public class MapFilter {
result.addAll(group); result.addAll(group);
} }
} }
return result; matches.clear();
matches.addAll(result);
} }
public static List<SchemaElementMatch> filterInExactMatch(List<SchemaElementMatch> matches) { public static void filterInExactMatch(List<SchemaElementMatch> matches) {
Map<String, List<SchemaElementMatch>> fullMatches = Map<String, List<SchemaElementMatch>> fullMatches =
matches.stream() matches.stream()
.filter(schemaElementMatch -> schemaElementMatch.isFullMatched()) .filter(schemaElementMatch -> schemaElementMatch.isFullMatched())
.collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord)); .collect(Collectors.groupingBy(SchemaElementMatch::getWord));
Set<String> keys = new HashSet<>(fullMatches.keySet()); Set<String> keys = new HashSet<>(fullMatches.keySet());
for (String key1 : keys) { for (String key1 : keys) {
for (String key2 : keys) { for (String key2 : keys) {
@@ -163,6 +164,7 @@ public class MapFilter {
List<SchemaElementMatch> mergedMatches = new ArrayList<>(); List<SchemaElementMatch> mergedMatches = new ArrayList<>();
fullMatches.values().forEach(mergedMatches::addAll); fullMatches.values().forEach(mergedMatches::addAll);
mergedMatches.addAll(notFullMatches); mergedMatches.addAll(notFullMatches);
return mergedMatches; matches.clear();
matches.addAll(mergedMatches);
} }
} }