mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 05:43:51 +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;
|
package com.tencent.supersonic.knowledge.dictionary.builder;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElement;
|
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.common.pojo.enums.DictWordType;
|
||||||
|
import com.tencent.supersonic.knowledge.dictionary.DictWord;
|
||||||
|
import java.util.List;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* domain word nature
|
* model word nature
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DomainWordBuilder extends BaseWordBuilder {
|
public class ModelWordBuilder extends BaseWordBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<DictWord> doGet(String word, SchemaElement schemaElement) {
|
public List<DictWord> doGet(String word, SchemaElement schemaElement) {
|
||||||
List<DictWord> result = Lists.newArrayList();
|
List<DictWord> result = Lists.newArrayList();
|
||||||
DictWord dictWord = new DictWord();
|
//modelName
|
||||||
dictWord.setWord(word);
|
DictWord dictWord = buildDictWord(word, schemaElement.getModel());
|
||||||
Long modelId = schemaElement.getModel();
|
|
||||||
String nature = DictWordType.NATURE_SPILT + modelId;
|
|
||||||
dictWord.setNatureWithFrequency(String.format("%s " + DEFAULT_FREQUENCY, nature));
|
|
||||||
result.add(dictWord);
|
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;
|
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 {
|
static {
|
||||||
wordNatures.put(DictWordType.DIMENSION, new DimensionWordBuilder());
|
wordNatures.put(DictWordType.DIMENSION, new DimensionWordBuilder());
|
||||||
wordNatures.put(DictWordType.METRIC, new MetricWordBuilder());
|
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.ENTITY, new EntityWordBuilder());
|
||||||
wordNatures.put(DictWordType.VALUE, new ValueWordBuilder());
|
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.DimSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.MetricSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.MetricSchemaResp;
|
||||||
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
import com.tencent.supersonic.semantic.api.model.response.ModelSchemaResp;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@@ -26,26 +27,23 @@ public class ModelSchemaBuilder {
|
|||||||
|
|
||||||
private static String aliasSplit = ",";
|
private static String aliasSplit = ",";
|
||||||
|
|
||||||
|
|
||||||
public static ModelSchema build(ModelSchemaResp resp) {
|
public static ModelSchema build(ModelSchemaResp resp) {
|
||||||
ModelSchema domainSchema = new ModelSchema();
|
ModelSchema domainSchema = new ModelSchema();
|
||||||
|
|
||||||
SchemaElement domain = SchemaElement.builder()
|
SchemaElement domain = SchemaElement.builder()
|
||||||
.model(resp.getId())
|
.model(resp.getId())
|
||||||
.id(resp.getId())
|
.id(resp.getId())
|
||||||
.name(resp.getName())
|
.name(resp.getName())
|
||||||
.bizName(resp.getBizName())
|
.bizName(resp.getBizName())
|
||||||
.type(SchemaElementType.MODEL)
|
.type(SchemaElementType.MODEL)
|
||||||
|
.alias(getAliasList(resp.getAlias()))
|
||||||
.build();
|
.build();
|
||||||
domainSchema.setModel(domain);
|
domainSchema.setModel(domain);
|
||||||
|
|
||||||
Set<SchemaElement> metrics = new HashSet<>();
|
Set<SchemaElement> metrics = new HashSet<>();
|
||||||
for (MetricSchemaResp metric : resp.getMetrics()) {
|
for (MetricSchemaResp metric : resp.getMetrics()) {
|
||||||
|
|
||||||
List<String> alias = new ArrayList<>();
|
List<String> alias = getAliasList(metric.getAlias());
|
||||||
String aliasStr = metric.getAlias();
|
|
||||||
if (Strings.isNotEmpty(aliasStr)) {
|
|
||||||
alias = Arrays.asList(aliasStr.split(aliasSplit));
|
|
||||||
}
|
|
||||||
|
|
||||||
SchemaElement metricToAdd = SchemaElement.builder()
|
SchemaElement metricToAdd = SchemaElement.builder()
|
||||||
.model(resp.getId())
|
.model(resp.getId())
|
||||||
@@ -65,11 +63,7 @@ public class ModelSchemaBuilder {
|
|||||||
Set<SchemaElement> dimensionValues = new HashSet<>();
|
Set<SchemaElement> dimensionValues = new HashSet<>();
|
||||||
for (DimSchemaResp dim : resp.getDimensions()) {
|
for (DimSchemaResp dim : resp.getDimensions()) {
|
||||||
|
|
||||||
List<String> alias = new ArrayList<>();
|
List<String> alias = getAliasList(dim.getAlias());
|
||||||
String aliasStr = dim.getAlias();
|
|
||||||
if (Strings.isNotEmpty(aliasStr)) {
|
|
||||||
alias = Arrays.asList(aliasStr.split(aliasSplit));
|
|
||||||
}
|
|
||||||
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<>();
|
List<SchemaValueMap> schemaValueMaps = new ArrayList<>();
|
||||||
@@ -133,4 +127,12 @@ public class ModelSchemaBuilder {
|
|||||||
|
|
||||||
return domainSchema;
|
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