mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(improvement)(chat) Fix the issue where the query gets stuck when two terms appear simultaneously. (#1581)
This commit is contained in:
@@ -95,43 +95,41 @@ public abstract class BaseMapper implements SchemaMapper {
|
|||||||
|
|
||||||
private static void filterByQueryDataType(ChatQueryContext chatQueryContext,
|
private static void filterByQueryDataType(ChatQueryContext chatQueryContext,
|
||||||
Predicate<SchemaElement> needRemovePredicate) {
|
Predicate<SchemaElement> needRemovePredicate) {
|
||||||
chatQueryContext.getMapInfo().getDataSetElementMatches().values().stream().forEach(
|
chatQueryContext.getMapInfo().getDataSetElementMatches().values().forEach(schemaElementMatches -> {
|
||||||
schemaElementMatches -> schemaElementMatches.removeIf(
|
schemaElementMatches.removeIf(schemaElementMatch -> {
|
||||||
schemaElementMatch -> {
|
SchemaElement element = schemaElementMatch.getElement();
|
||||||
SchemaElement element = schemaElementMatch.getElement();
|
SchemaElementType type = element.getType();
|
||||||
SchemaElementType type = element.getType();
|
|
||||||
if (SchemaElementType.ENTITY.equals(type) || SchemaElementType.DATASET.equals(type)
|
boolean isEntityOrDatasetOrId = SchemaElementType.ENTITY.equals(type)
|
||||||
|| SchemaElementType.ID.equals(type)) {
|
|| SchemaElementType.DATASET.equals(type)
|
||||||
return false;
|
|| SchemaElementType.ID.equals(type);
|
||||||
}
|
|
||||||
return needRemovePredicate.test(element);
|
return !isEntityOrDatasetOrId && needRemovePredicate.test(element);
|
||||||
}
|
});
|
||||||
));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void doMap(ChatQueryContext chatQueryContext);
|
public abstract void doMap(ChatQueryContext chatQueryContext);
|
||||||
|
|
||||||
public void addToSchemaMap(SchemaMapInfo schemaMap, Long dataSetId, SchemaElementMatch newElementMatch) {
|
public void addToSchemaMap(SchemaMapInfo schemaMap, Long dataSetId, SchemaElementMatch newElementMatch) {
|
||||||
Map<Long, List<SchemaElementMatch>> dataSetElementMatches = schemaMap.getDataSetElementMatches();
|
Map<Long, List<SchemaElementMatch>> dataSetElementMatches = schemaMap.getDataSetElementMatches();
|
||||||
List<SchemaElementMatch> schemaElementMatches = dataSetElementMatches.putIfAbsent(dataSetId, new ArrayList<>());
|
List<SchemaElementMatch> schemaElementMatches = dataSetElementMatches.computeIfAbsent(dataSetId,
|
||||||
if (schemaElementMatches == null) {
|
k -> new ArrayList<>());
|
||||||
schemaElementMatches = dataSetElementMatches.get(dataSetId);
|
|
||||||
}
|
AtomicBoolean shouldAddNew = new AtomicBoolean(true);
|
||||||
//remove duplication
|
|
||||||
AtomicBoolean needAddNew = new AtomicBoolean(true);
|
schemaElementMatches.removeIf(existingElementMatch -> {
|
||||||
schemaElementMatches.removeIf(
|
if (isEquals(existingElementMatch, newElementMatch)) {
|
||||||
existElementMatch -> {
|
if (newElementMatch.getSimilarity() > existingElementMatch.getSimilarity()) {
|
||||||
if (isEquals(existElementMatch, newElementMatch)) {
|
return true;
|
||||||
if (newElementMatch.getSimilarity() > existElementMatch.getSimilarity()) {
|
} else {
|
||||||
return true;
|
shouldAddNew.set(false);
|
||||||
} else {
|
|
||||||
needAddNew.set(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
if (needAddNew.get()) {
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (shouldAddNew.get()) {
|
||||||
schemaElementMatches.add(newElementMatch);
|
schemaElementMatches.add(newElementMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ public class ChatWorkflowEngine {
|
|||||||
parseResult.setState(ParseResp.ParseState.FAILED);
|
parseResult.setState(ParseResp.ParseState.FAILED);
|
||||||
parseResult.setErrorMsg("No semantic entities can be mapped against user question.");
|
parseResult.setErrorMsg("No semantic entities can be mapped against user question.");
|
||||||
queryCtx.setChatWorkflowState(ChatWorkflowState.FINISHED);
|
queryCtx.setChatWorkflowState(ChatWorkflowState.FINISHED);
|
||||||
} else if (queryCtx.getMapInfo().needContinueMap()) {
|
|
||||||
queryCtx.setChatWorkflowState(ChatWorkflowState.MAPPING);
|
|
||||||
} else {
|
} else {
|
||||||
queryCtx.setChatWorkflowState(ChatWorkflowState.PARSING);
|
queryCtx.setChatWorkflowState(ChatWorkflowState.PARSING);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user