mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
[improvement][chat]Move generation of semantic text info and rewrite of error message to dedicated ResultProcessor.
This commit is contained in:
@@ -12,13 +12,13 @@ import lombok.ToString;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SchemaElementMatch {
|
||||
SchemaElement element;
|
||||
double offset;
|
||||
double similarity;
|
||||
String detectWord;
|
||||
String word;
|
||||
Long frequency;
|
||||
boolean isInherited;
|
||||
private SchemaElement element;
|
||||
private double offset;
|
||||
private double similarity;
|
||||
private String detectWord;
|
||||
private String word;
|
||||
private Long frequency;
|
||||
private boolean isInherited;
|
||||
|
||||
public boolean isFullMatched() {
|
||||
return 1.0 == similarity;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.api.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -9,9 +10,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public class SchemaMapInfo {
|
||||
|
||||
private Map<Long, List<SchemaElementMatch>> dataSetElementMatches = new HashMap<>();
|
||||
private final Map<Long, List<SchemaElementMatch>> dataSetElementMatches = new HashMap<>();
|
||||
|
||||
public Set<Long> getMatchedDataSetInfos() {
|
||||
return dataSetElementMatches.keySet();
|
||||
@@ -21,10 +23,6 @@ public class SchemaMapInfo {
|
||||
return dataSetElementMatches.getOrDefault(dataSet, Lists.newArrayList());
|
||||
}
|
||||
|
||||
public Map<Long, List<SchemaElementMatch>> getDataSetElementMatches() {
|
||||
return dataSetElementMatches;
|
||||
}
|
||||
|
||||
public void setMatchedElements(Long dataSet, List<SchemaElementMatch> elementMatches) {
|
||||
dataSetElementMatches.put(dataSet, elementMatches);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,15 @@ public class QueryNLReq extends SemanticQueryReq {
|
||||
|
||||
@Override
|
||||
public String toCustomizedString() {
|
||||
return "";
|
||||
StringBuilder stringBuilder = new StringBuilder("{");
|
||||
stringBuilder.append("\"queryText\":").append(dataSetId);
|
||||
stringBuilder.append("\"dataSetId\":").append(dataSetId);
|
||||
stringBuilder.append("\"modelIds\":").append(modelIds);
|
||||
stringBuilder.append(",\"params\":").append(params);
|
||||
stringBuilder.append(",\"cacheInfo\":").append(cacheInfo);
|
||||
stringBuilder.append(",\"mapMode\":").append(mapModeEnum);
|
||||
stringBuilder.append(",\"dataType\":").append(queryDataType);
|
||||
stringBuilder.append('}');
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.Objects;
|
||||
public class QuerySqlReq extends SemanticQueryReq {
|
||||
|
||||
private String sql;
|
||||
|
||||
private Integer limit = 1000;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,10 +7,10 @@ import lombok.Data;
|
||||
public class MapResp {
|
||||
|
||||
private final String queryText;
|
||||
private final SchemaMapInfo mapInfo;
|
||||
|
||||
private SchemaMapInfo mapInfo = new SchemaMapInfo();
|
||||
|
||||
public MapResp(String queryText) {
|
||||
public MapResp(String queryText, SchemaMapInfo schemaMapInfo) {
|
||||
this.queryText = queryText;
|
||||
this.mapInfo = schemaMapInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.tencent.supersonic.headless.api.pojo.response;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.common.pojo.Text2SQLExemplar;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -16,6 +17,7 @@ public class ParseResp {
|
||||
private String errorMsg;
|
||||
private List<SemanticParseInfo> selectedParses = Lists.newArrayList();
|
||||
private ParseTimeCostResp parseTimeCost = new ParseTimeCostResp();
|
||||
private List<Text2SQLExemplar> usedExemplars;
|
||||
|
||||
public enum ParseState {
|
||||
COMPLETED, PENDING, FAILED
|
||||
|
||||
@@ -114,8 +114,7 @@ public abstract class BaseMapper implements SchemaMapper {
|
||||
return element.getAlias();
|
||||
}
|
||||
|
||||
public <T> List<T> getMatches(ChatQueryContext chatQueryContext,
|
||||
BaseMatchStrategy matchStrategy) {
|
||||
public <T> List<T> getMatches(ChatQueryContext chatQueryContext, MatchStrategy matchStrategy) {
|
||||
String queryText = chatQueryContext.getRequest().getQueryText();
|
||||
List<S2Term> terms =
|
||||
HanlpHelper.getTerms(queryText, chatQueryContext.getModelIdToDataSetIds());
|
||||
|
||||
@@ -64,11 +64,9 @@ public class S2ChatLayerService implements ChatLayerService {
|
||||
|
||||
@Override
|
||||
public MapResp map(QueryNLReq queryNLReq) {
|
||||
MapResp mapResp = new MapResp(queryNLReq.getQueryText());
|
||||
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
||||
ComponentFactory.getSchemaMappers().forEach(mapper -> mapper.map(queryCtx));
|
||||
mapResp.setMapInfo(queryCtx.getMapInfo());
|
||||
return mapResp;
|
||||
return new MapResp(queryNLReq.getQueryText(), queryCtx.getMapInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user