mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:38:13 +00:00
(improvement)(chat) support add model aliasList to dict and update domainName to modelName (#71)
This commit is contained in:
@@ -1,32 +1,43 @@
|
||||
package com.tencent.supersonic.knowledge.dictionary.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
||||
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
||||
import com.tencent.supersonic.common.pojo.enums.DictWordType;
|
||||
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* domain word nature
|
||||
* model word nature
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DomainWordBuilder extends BaseWordBuilder {
|
||||
public class ModelWordBuilder extends BaseWordBuilder {
|
||||
|
||||
@Override
|
||||
public List<DictWord> doGet(String word, SchemaElement schemaElement) {
|
||||
List<DictWord> result = Lists.newArrayList();
|
||||
DictWord dictWord = new DictWord();
|
||||
dictWord.setWord(word);
|
||||
Long modelId = schemaElement.getModel();
|
||||
String nature = DictWordType.NATURE_SPILT + modelId;
|
||||
dictWord.setNatureWithFrequency(String.format("%s " + DEFAULT_FREQUENCY, nature));
|
||||
//modelName
|
||||
DictWord dictWord = buildDictWord(word, schemaElement.getModel());
|
||||
result.add(dictWord);
|
||||
//alias
|
||||
List<String> aliasList = schemaElement.getAlias();
|
||||
if (CollectionUtils.isNotEmpty(aliasList)) {
|
||||
for (String alias : aliasList) {
|
||||
result.add(buildDictWord(alias, schemaElement.getModel()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private DictWord buildDictWord(String word, Long modelId) {
|
||||
DictWord dictWord = new DictWord();
|
||||
dictWord.setWord(word);
|
||||
String nature = DictWordType.NATURE_SPILT + modelId;
|
||||
dictWord.setNatureWithFrequency(String.format("%s " + DEFAULT_FREQUENCY, nature));
|
||||
return dictWord;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class WordBuilderFactory {
|
||||
static {
|
||||
wordNatures.put(DictWordType.DIMENSION, new DimensionWordBuilder());
|
||||
wordNatures.put(DictWordType.METRIC, new MetricWordBuilder());
|
||||
wordNatures.put(DictWordType.DOMAIN, new DomainWordBuilder());
|
||||
wordNatures.put(DictWordType.DOMAIN, new ModelWordBuilder());
|
||||
wordNatures.put(DictWordType.ENTITY, new EntityWordBuilder());
|
||||
wordNatures.put(DictWordType.VALUE, new ValueWordBuilder());
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.tencent.supersonic.semantic.api.model.pojo.Entity;
|
||||
import com.tencent.supersonic.semantic.api.model.response.DimSchemaResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.MetricSchemaResp;
|
||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -26,26 +27,23 @@ public class ModelSchemaBuilder {
|
||||
|
||||
private static String aliasSplit = ",";
|
||||
|
||||
|
||||
public static ModelSchema build(ModelSchemaResp resp) {
|
||||
ModelSchema domainSchema = new ModelSchema();
|
||||
|
||||
SchemaElement domain = SchemaElement.builder()
|
||||
.model(resp.getId())
|
||||
.id(resp.getId())
|
||||
.name(resp.getName())
|
||||
.bizName(resp.getBizName())
|
||||
.type(SchemaElementType.MODEL)
|
||||
.alias(getAliasList(resp.getAlias()))
|
||||
.build();
|
||||
domainSchema.setModel(domain);
|
||||
|
||||
Set<SchemaElement> metrics = new HashSet<>();
|
||||
for (MetricSchemaResp metric : resp.getMetrics()) {
|
||||
|
||||
List<String> alias = new ArrayList<>();
|
||||
String aliasStr = metric.getAlias();
|
||||
if (Strings.isNotEmpty(aliasStr)) {
|
||||
alias = Arrays.asList(aliasStr.split(aliasSplit));
|
||||
}
|
||||
List<String> alias = getAliasList(metric.getAlias());
|
||||
|
||||
SchemaElement metricToAdd = SchemaElement.builder()
|
||||
.model(resp.getId())
|
||||
@@ -65,11 +63,7 @@ public class ModelSchemaBuilder {
|
||||
Set<SchemaElement> dimensionValues = new HashSet<>();
|
||||
for (DimSchemaResp dim : resp.getDimensions()) {
|
||||
|
||||
List<String> alias = new ArrayList<>();
|
||||
String aliasStr = dim.getAlias();
|
||||
if (Strings.isNotEmpty(aliasStr)) {
|
||||
alias = Arrays.asList(aliasStr.split(aliasSplit));
|
||||
}
|
||||
List<String> alias = getAliasList(dim.getAlias());
|
||||
Set<String> dimValueAlias = new HashSet<>();
|
||||
List<DimValueMap> dimValueMaps = dim.getDimValueMaps();
|
||||
List<SchemaValueMap> schemaValueMaps = new ArrayList<>();
|
||||
@@ -133,4 +127,12 @@ public class ModelSchemaBuilder {
|
||||
|
||||
return domainSchema;
|
||||
}
|
||||
|
||||
private static List<String> getAliasList(String alias) {
|
||||
if (StringUtils.isEmpty(alias)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Arrays.asList(alias.split(aliasSplit));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user