mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
(fix)[chat&headless]in mapping phase,DimValuesAlias do not take effect (#2340)
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
package com.tencent.supersonic.headless.chat.mapper;
|
package com.tencent.supersonic.headless.chat.mapper;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElement;
|
import com.tencent.supersonic.headless.api.pojo.*;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementMatch;
|
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaMapInfo;
|
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.S2Term;
|
import com.tencent.supersonic.headless.api.pojo.response.S2Term;
|
||||||
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
||||||
import com.tencent.supersonic.headless.chat.knowledge.DatabaseMapResult;
|
import com.tencent.supersonic.headless.chat.knowledge.DatabaseMapResult;
|
||||||
@@ -54,7 +51,7 @@ public class KeywordMapper extends BaseMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void convertMapResultToMapInfo(List<HanlpMapResult> mapResults,
|
private void convertMapResultToMapInfo(List<HanlpMapResult> mapResults,
|
||||||
ChatQueryContext chatQueryContext, List<S2Term> terms) {
|
ChatQueryContext chatQueryContext, List<S2Term> terms) {
|
||||||
if (CollectionUtils.isEmpty(mapResults)) {
|
if (CollectionUtils.isEmpty(mapResults)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -90,13 +87,14 @@ public class KeywordMapper extends BaseMapper {
|
|||||||
.similarity(hanlpMapResult.getSimilarity())
|
.similarity(hanlpMapResult.getSimilarity())
|
||||||
.detectWord(hanlpMapResult.getDetectWord()).build();
|
.detectWord(hanlpMapResult.getDetectWord()).build();
|
||||||
// doDimValueAliasLogic 将维度值别名进行替换成真实维度值
|
// doDimValueAliasLogic 将维度值别名进行替换成真实维度值
|
||||||
doDimValueAliasLogic(schemaElementMatch);
|
doDimValueAliasLogic(schemaElementMatch,chatQueryContext.getSemanticSchema().getDimensionValues());
|
||||||
addToSchemaMap(chatQueryContext.getMapInfo(), dataSetId, schemaElementMatch);
|
addToSchemaMap(chatQueryContext.getMapInfo(), dataSetId, schemaElementMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doDimValueAliasLogic(SchemaElementMatch schemaElementMatch) {
|
private void doDimValueAliasLogic(SchemaElementMatch schemaElementMatch,
|
||||||
|
List<SchemaElement> dimensionValues) {
|
||||||
SchemaElement element = schemaElementMatch.getElement();
|
SchemaElement element = schemaElementMatch.getElement();
|
||||||
if (SchemaElementType.VALUE.equals(element.getType())) {
|
if (SchemaElementType.VALUE.equals(element.getType())) {
|
||||||
Long dimId = element.getId();
|
Long dimId = element.getId();
|
||||||
@@ -112,11 +110,23 @@ public class KeywordMapper extends BaseMapper {
|
|||||||
schemaElementMatch.setWord(wordTech);
|
schemaElementMatch.setWord(wordTech);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SchemaElement dimensionValue = dimensionValues.stream()
|
||||||
|
.filter(dimValue -> dimId.equals(dimValue.getId())).findFirst().orElse(null);
|
||||||
|
if (dimensionValue != null) {
|
||||||
|
SchemaValueMap dimValue =
|
||||||
|
dimensionValue.getSchemaValueMaps().stream().filter(schemaValueMap -> {
|
||||||
|
return StringUtils.equals(schemaValueMap.getBizName(), word)
|
||||||
|
|| schemaValueMap.getAlias().contains(word);
|
||||||
|
}).findFirst().orElse(null);
|
||||||
|
if (dimValue != null) {
|
||||||
|
schemaElementMatch.setWord(dimValue.getTechName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void convertMapResultToMapInfo(ChatQueryContext chatQueryContext,
|
private void convertMapResultToMapInfo(ChatQueryContext chatQueryContext,
|
||||||
List<DatabaseMapResult> mapResults) {
|
List<DatabaseMapResult> mapResults) {
|
||||||
for (DatabaseMapResult match : mapResults) {
|
for (DatabaseMapResult match : mapResults) {
|
||||||
SchemaElement schemaElement = match.getSchemaElement();
|
SchemaElement schemaElement = match.getSchemaElement();
|
||||||
Set<Long> regElementSet =
|
Set<Long> regElementSet =
|
||||||
@@ -143,8 +153,8 @@ public class KeywordMapper extends BaseMapper {
|
|||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
return elements.stream().filter(
|
return elements.stream().filter(
|
||||||
elementMatch -> SchemaElementType.METRIC.equals(elementMatch.getElement().getType())
|
elementMatch -> SchemaElementType.METRIC.equals(elementMatch.getElement().getType())
|
||||||
|| SchemaElementType.DIMENSION.equals(elementMatch.getElement().getType()))
|
|| SchemaElementType.DIMENSION.equals(elementMatch.getElement().getType()))
|
||||||
.map(elementMatch -> elementMatch.getElement().getId()).collect(Collectors.toSet());
|
.map(elementMatch -> elementMatch.getElement().getId()).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class DataSetSchemaBuilder {
|
|||||||
if (dim.isTimeDimension()) {
|
if (dim.isTimeDimension()) {
|
||||||
String timeFormat =
|
String timeFormat =
|
||||||
String.valueOf(dim.getExt().get(DimensionConstants.DIMENSION_TIME_FORMAT));
|
String.valueOf(dim.getExt().get(DimensionConstants.DIMENSION_TIME_FORMAT));
|
||||||
setDefaultTimeFormat(dimToAdd, dim.getTypeParams(), timeFormat);
|
setDefaultTimeFormat(dimToAdd, timeFormat);
|
||||||
}
|
}
|
||||||
dimensions.add(dimToAdd);
|
dimensions.add(dimToAdd);
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,13 @@ public class DataSetSchemaBuilder {
|
|||||||
for (DimSchemaResp dim : resp.getDimensions()) {
|
for (DimSchemaResp dim : resp.getDimensions()) {
|
||||||
Set<String> dimValueAlias = new HashSet<>();
|
Set<String> dimValueAlias = new HashSet<>();
|
||||||
List<DimValueMap> dimValueMaps = dim.getDimValueMaps();
|
List<DimValueMap> dimValueMaps = dim.getDimValueMaps();
|
||||||
|
List<SchemaValueMap> schemaValueMaps = new ArrayList<>();
|
||||||
if (!CollectionUtils.isEmpty(dimValueMaps)) {
|
if (!CollectionUtils.isEmpty(dimValueMaps)) {
|
||||||
|
for (DimValueMap dimValueMap : dimValueMaps) {
|
||||||
|
SchemaValueMap schemaValueMap = new SchemaValueMap();
|
||||||
|
BeanUtils.copyProperties(dimValueMap, schemaValueMap);
|
||||||
|
schemaValueMaps.add(schemaValueMap);
|
||||||
|
}
|
||||||
for (DimValueMap dimValueMap : dimValueMaps) {
|
for (DimValueMap dimValueMap : dimValueMaps) {
|
||||||
if (StringUtils.isNotEmpty(dimValueMap.getBizName())) {
|
if (StringUtils.isNotEmpty(dimValueMap.getBizName())) {
|
||||||
dimValueAlias.add(dimValueMap.getBizName());
|
dimValueAlias.add(dimValueMap.getBizName());
|
||||||
@@ -138,7 +144,7 @@ public class DataSetSchemaBuilder {
|
|||||||
SchemaElement dimValueToAdd = SchemaElement.builder().dataSetId(resp.getId())
|
SchemaElement dimValueToAdd = SchemaElement.builder().dataSetId(resp.getId())
|
||||||
.dataSetName(resp.getName()).model(dim.getModelId()).id(dim.getId())
|
.dataSetName(resp.getName()).model(dim.getModelId()).id(dim.getId())
|
||||||
.name(dim.getName()).bizName(dim.getBizName()).type(SchemaElementType.VALUE)
|
.name(dim.getName()).bizName(dim.getBizName()).type(SchemaElementType.VALUE)
|
||||||
.useCnt(dim.getUseCnt())
|
.schemaValueMaps(schemaValueMaps).useCnt(dim.getUseCnt())
|
||||||
.alias(new ArrayList<>(Arrays.asList(dimValueAlias.toArray(new String[0]))))
|
.alias(new ArrayList<>(Arrays.asList(dimValueAlias.toArray(new String[0]))))
|
||||||
.isTag(dim.getIsTag()).description(dim.getDescription()).build();
|
.isTag(dim.getIsTag()).description(dim.getDescription()).build();
|
||||||
dimensionValues.add(dimValueToAdd);
|
dimensionValues.add(dimValueToAdd);
|
||||||
@@ -193,7 +199,7 @@ public class DataSetSchemaBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void setDefaultTimeFormat(SchemaElement dimToAdd,
|
private static void setDefaultTimeFormat(SchemaElement dimToAdd,
|
||||||
DimensionTimeTypeParams dimensionTimeTypeParams, String timeFormat) {
|
String timeFormat) {
|
||||||
dimToAdd.getExtInfo().put(DimensionConstants.DIMENSION_TIME_FORMAT, timeFormat);
|
dimToAdd.getExtInfo().put(DimensionConstants.DIMENSION_TIME_FORMAT, timeFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user