mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
[doc][chat]Add javadoc to rule-based semantic parsers
This commit is contained in:
@@ -27,6 +27,12 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AggregateTypeParser extracts aggregation type specified in the user query
|
||||||
|
* based on keyword matching.
|
||||||
|
* Currently, it supports 7 types of aggregation: max, min, sum, avg, topN,
|
||||||
|
* distinct count, count.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AggregateTypeParser implements SemanticParser {
|
public class AggregateTypeParser implements SemanticParser {
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ContextInheritParser tries to inherit certain schema elements from context
|
||||||
|
* so that in multi-turn conversations users don't need to mention some keyword
|
||||||
|
* repeatedly.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ContextInheritParser implements SemanticParser {
|
public class ContextInheritParser implements SemanticParser {
|
||||||
|
|
||||||
|
|||||||
@@ -7,20 +7,21 @@ import com.tencent.supersonic.chat.api.pojo.SchemaMapInfo;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.chat.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
import com.tencent.supersonic.chat.query.rule.RuleSemanticQuery;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QueryModeParser resolves a specific query mode according to co-appearance
|
||||||
|
* of certain schema element types.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class QueryModeParser implements SemanticParser {
|
public class QueryModeParser implements SemanticParser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse(QueryContext queryContext, ChatContext chatContext) {
|
public void parse(QueryContext queryContext, ChatContext chatContext) {
|
||||||
SchemaMapInfo mapInfo = queryContext.getMapInfo();
|
SchemaMapInfo mapInfo = queryContext.getMapInfo();
|
||||||
// iterate all schemaElementMatches to resolve semantic query
|
// iterate all schemaElementMatches to resolve query mode
|
||||||
for (Long modelId : mapInfo.getMatchedModels()) {
|
for (Long modelId : mapInfo.getMatchedModels()) {
|
||||||
List<SchemaElementMatch> elementMatches = mapInfo.getMatchedElements(modelId);
|
List<SchemaElementMatch> elementMatches = mapInfo.getMatchedElements(modelId);
|
||||||
List<RuleSemanticQuery> queries = RuleSemanticQuery.resolve(elementMatches, queryContext);
|
List<RuleSemanticQuery> queries = RuleSemanticQuery.resolve(elementMatches, queryContext);
|
||||||
@@ -29,14 +30,6 @@ public class QueryModeParser implements SemanticParser {
|
|||||||
queryContext.getCandidateQueries().add(query);
|
queryContext.getCandidateQueries().add(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if modelElementMatches id empty,so remove it.
|
|
||||||
Map<Long, List<SchemaElementMatch>> filterModelElementMatches = new HashMap<>();
|
|
||||||
for (Long modelId : queryContext.getMapInfo().getModelElementMatches().keySet()) {
|
|
||||||
if (!CollectionUtils.isEmpty(queryContext.getMapInfo().getModelElementMatches().get(modelId))) {
|
|
||||||
filterModelElementMatches.put(modelId, queryContext.getMapInfo().getModelElementMatches().get(modelId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queryContext.getMapInfo().setModelElementMatches(filterModelElementMatches);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RuleBasedParser acts as a container that incorporates a group of
|
||||||
|
* rule-based semantic parsers.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RuleBasedParser implements SemanticParser {
|
public class RuleBasedParser implements SemanticParser {
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ import com.xkzhangsan.time.nlp.TimeNLPUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TimeRangeParser extracts time range specified in the user query
|
||||||
|
* based on keyword matching.
|
||||||
|
* Currently, it supports two kinds of expression:
|
||||||
|
* 1. Recent unit: 近N天/周/月/年、过去N天/周/月/年
|
||||||
|
* 2. Concrete date: 2023年11月15日、20231115
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TimeRangeParser implements SemanticParser {
|
public class TimeRangeParser implements SemanticParser {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user