Skip to content

Commit

Permalink
[improvement](chat) Use the word-based approach for comparing Schema …
Browse files Browse the repository at this point in the history
…Mapping rules and fix the issue where the results were not being modified. (#1650)
  • Loading branch information
lexluo09 authored Sep 10, 2024
1 parent 879696e commit fb96ce5
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public static void filterByQueryDataType(
public static void filterByRules(ChatQueryContext chatQueryContext) {
Map<Long, List<SchemaElementMatch>> dataSetElementMatches =
chatQueryContext.getMapInfo().getDataSetElementMatches();

for (Map.Entry<Long, List<SchemaElementMatch>> entry : dataSetElementMatches.entrySet()) {
List<SchemaElementMatch> elementMatches = entry.getValue();
filterByExactMatch(elementMatches);
filterInExactMatch(elementMatches);
filterByExactMatch(entry.getValue());
filterInExactMatch(entry.getValue());
}
}

public static List<SchemaElementMatch> filterByExactMatch(List<SchemaElementMatch> matches) {
public static void filterByExactMatch(List<SchemaElementMatch> matches) {
// Group by detectWord
Map<String, List<SchemaElementMatch>> groupedByDetectWord =
matches.stream().collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord));
Expand Down Expand Up @@ -139,14 +139,15 @@ public static List<SchemaElementMatch> filterByExactMatch(List<SchemaElementMatc
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 =
matches.stream()
.filter(schemaElementMatch -> schemaElementMatch.isFullMatched())
.collect(Collectors.groupingBy(SchemaElementMatch::getDetectWord));
.collect(Collectors.groupingBy(SchemaElementMatch::getWord));
Set<String> keys = new HashSet<>(fullMatches.keySet());
for (String key1 : keys) {
for (String key2 : keys) {
Expand All @@ -163,6 +164,7 @@ public static List<SchemaElementMatch> filterInExactMatch(List<SchemaElementMatc
List<SchemaElementMatch> mergedMatches = new ArrayList<>();
fullMatches.values().forEach(mergedMatches::addAll);
mergedMatches.addAll(notFullMatches);
return mergedMatches;
matches.clear();
matches.addAll(mergedMatches);
}
}

0 comments on commit fb96ce5

Please sign in to comment.