mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 22:25:19 +00:00
(improvement)(Chat) Simplify processor in Headless and Chat (#822)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -3,7 +3,11 @@ package com.tencent.supersonic.headless.api.pojo.response;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class ParseResp {
|
||||
@@ -20,4 +24,33 @@ public class ParseResp {
|
||||
FAILED
|
||||
}
|
||||
|
||||
public List<SemanticParseInfo> getSelectedParses() {
|
||||
selectedParses = selectedParses.stream()
|
||||
.sorted(Comparator.comparingDouble(SemanticParseInfo::getScore))
|
||||
.collect(Collectors.toList());
|
||||
generateParseInfoId(selectedParses);
|
||||
return selectedParses;
|
||||
}
|
||||
|
||||
public ParseState getState() {
|
||||
if (CollectionUtils.isNotEmpty(selectedParses)) {
|
||||
this.state = ParseResp.ParseState.COMPLETED;
|
||||
} else {
|
||||
this.state = ParseState.FAILED;
|
||||
}
|
||||
return this.state;
|
||||
}
|
||||
|
||||
private void generateParseInfoId(List<SemanticParseInfo> selectedParses) {
|
||||
for (int i = 0; i < selectedParses.size(); i++) {
|
||||
SemanticParseInfo parseInfo = selectedParses.get(i);
|
||||
parseInfo.setId(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public ParseResp(Integer chatId, String queryText) {
|
||||
this.chatId = chatId;
|
||||
this.queryText = queryText;
|
||||
parseTimeCost.setParseStartTime(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user