增加对英文断句的支持
This commit is contained in:
parent
206c638c29
commit
f3d66a7879
@ -28,6 +28,8 @@ public class RedisConstans {
|
||||
|
||||
public static String USER_BOX_INFO = "user_box_info:";
|
||||
|
||||
public static String TONGYI_TALK_CONTENT = "tongyi_talk_content:";
|
||||
|
||||
public static String TY_QUEUE_LIST = "ty_queue_list:"; //通义千问的前缀
|
||||
/**
|
||||
* 阿里语音合成token
|
||||
|
||||
@ -53,7 +53,17 @@ public class StringUtils extends cn.hutool.core.util.StrUtil{
|
||||
int b = old.lastIndexOf("\n");
|
||||
int c = old.lastIndexOf(";");
|
||||
int n = old.lastIndexOf("\\n");
|
||||
int m = Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n);
|
||||
int o = old.lastIndexOf("!");
|
||||
int m = Math.max(Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n), o);
|
||||
if(m < 0){
|
||||
//支持英文
|
||||
d = old.lastIndexOf(",");
|
||||
j = old.lastIndexOf(".");
|
||||
a = old.lastIndexOf(":");
|
||||
c = old.lastIndexOf(";");
|
||||
o = old.lastIndexOf("!");
|
||||
m = Math.max(Math.max(Math.max(Math.max(d, j), a), c), o);
|
||||
}
|
||||
if (m > 0) {
|
||||
//清空
|
||||
m++;
|
||||
|
||||
@ -3,10 +3,16 @@ package com.qiuguo.iot.data.model.system;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Data
|
||||
public class SystemTalkAnswerConfig {
|
||||
ConcurrentHashMap<String, SystemTalkAnswerConfigEntity> exCommand;
|
||||
/**
|
||||
* 名字有长到段的排序
|
||||
*/
|
||||
List<String> keys;//
|
||||
SystemTalkAnswerConfigEntity systemTalkAnswerConfig;
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -86,6 +87,12 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
|
||||
systemTalkAnswerConfig.getExCommand().put(item1.getAskKey(), item1);
|
||||
return item1;
|
||||
}).doFinally(signalType -> {
|
||||
//systemTalkAnswerConfig.getExCommand()
|
||||
systemTalkAnswerConfig.setKeys(
|
||||
systemTalkAnswerConfig.getExCommand().keySet().stream().collect(Collectors.toList()));
|
||||
systemTalkAnswerConfig.getKeys().sort((a, b) ->{
|
||||
return b.length() - a.length();
|
||||
});
|
||||
log.info("配置扩展最多读取{}条,实际读取了:{},id:{}的{}条扩展指令",
|
||||
MAX_COUT,
|
||||
systemTalkAnswerConfig.getSystemTalkAnswerConfig().getAskKey(),
|
||||
|
||||
@ -851,7 +851,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
return entity.getSystemTalkAnswerConfig();
|
||||
}else{
|
||||
//找到扩展指令
|
||||
for (String key1 :entity.getExCommand().keySet()){
|
||||
for (String key1 :entity.getKeys()){
|
||||
if(ask.contains(key1)){
|
||||
return entity.getExCommand().get(key1);
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ import com.qiuguo.iot.data.resp.qg.algorithm.QGResponse;
|
||||
import com.qiuguo.iot.data.request.qwen.TongYiCommunicationRest;
|
||||
import com.qiuguo.iot.data.resp.qg.algorithm.QWenReplyResponse;
|
||||
import com.qiuguo.iot.third.nlp.AliYunQianWen;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ReactiveValueOperations;
|
||||
@ -28,7 +27,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class QWenService implements ITongYi{
|
||||
public class TongYiQianWenService implements ITongYi{
|
||||
|
||||
@Resource
|
||||
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
||||
@ -32,8 +32,6 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class TongYiXinChenService implements ITongYi{
|
||||
|
||||
|
||||
|
||||
protected static ConcurrentHashMap<String, AliYunXingChen> qianwenGroup = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
|
||||
@ -4,26 +4,23 @@ import com.qiuguo.iot.data.request.qwen.TongYiCommunicationRest;
|
||||
import com.qiuguo.iot.data.resp.third.ThirdIpInfoResp;
|
||||
import com.qiuguo.iot.data.resp.third.ThirdRpcResp;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author simon
|
||||
* @date 2023/9/21
|
||||
* @description
|
||||
**/
|
||||
|
||||
@SpringBootTest(classes = {IpService.class,QWenService.class})
|
||||
@SpringBootTest(classes = {IpService.class, TongYiQianWenService.class})
|
||||
class IpServiceTest {
|
||||
@Resource
|
||||
private IpService ipService;
|
||||
@Resource
|
||||
private QWenService qWenService;
|
||||
private TongYiQianWenService qWenService;
|
||||
|
||||
@Test
|
||||
void aa() {
|
||||
|
||||
@ -289,8 +289,8 @@ public class BaseWebSocketService implements IActionSendMessage {
|
||||
* @param baseSession
|
||||
* @param baseMessageResp
|
||||
* @param builder
|
||||
* @param text
|
||||
* @param n
|
||||
* @param text 字符的总长度
|
||||
* @param n 从第几个字符开始
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
@ -390,4 +390,34 @@ public class BaseWebSocketService implements IActionSendMessage {
|
||||
});
|
||||
}
|
||||
|
||||
/*public static void main(String[] args) {
|
||||
String v = "我来讲一个英文故事给你听吧!Once upon a time, there was a little girl named Goldilocks. She went for a walk in the forest. Pretty soon, she came upon a house. She knocked and, when no one answered, she walked right in. At the table in the kitchen, there were three bowls of porridge. Goldilocks was hungry. She tasted the porridge from the first bowl. \"This porridge is too hot!\"she exclaimed. So, she tasted the porridge from the second bowl. \"This porridge is too cold,\"she said. So, she tasted the last bowl of porridge. \"Ahhh, this porridge is just right!\"she exclaimed happily. \"What a lovely house this is!\"she said to herself. She looked into the living room. There were chairs, a couch, and a rocking chair. Goldilocks walked over to the rocking chair. It was too big. Then she saw a chair that looked just right. She sat down in it and it was just right. Next, she saw a bed. The first bed she saw was too hard. The next bed was too soft. But the last bed was just right. Goldilocks lay down and went fast asleep. Suddenly, she heard a great noise downstairs. Someone was coming! She jumped out of bed, ran into the bathroom, and hid behind the door. Three bears entered the house. They came into the kitchen. \"Someone has been eating my porridge,\"said the first bear. \"Someone has been eating my porridge,\"said the second bear. \"Someone has been eating my porridge,\"said the third bear. \"And someone has been sitting in my chair.\"\"And someone has been sitting in my chair.\"\"And someone has been sitting in my chair.\"\"And someone has been sleeping in my bed.\"\"And someone has been sleeping in my bed.\"\"And someone has been sleeping in my bed.\"They followed the trail of footprints upstairs. When they got to the bedroom, Goldilocks heard them say, \"Someone has been sleeping in my bed.\"Goldilocks trembled with fear. She opened the bathroom door very slowly and peeked out. She saw three angry bears looking at her. She closed the door quickly and hid behind it. The bears broke down the door, and Goldilocks ran out of the house as fast as she could. She ran so fast that she fell down and broke all the bones in her body. And that is the end of the story of Goldilocks and the Three Bears.";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
pro(v, 0, v.length(), sb, 50);
|
||||
}
|
||||
|
||||
public static void pro(String text, int n, int length, StringBuilder builder, int ONE_MAX_TEXT){
|
||||
if(n < length){
|
||||
int start = n;
|
||||
n += ONE_MAX_TEXT;
|
||||
if(n > length){
|
||||
n = length;
|
||||
}
|
||||
String message = text.substring(start, n);
|
||||
int status = 0;
|
||||
if(n == length){
|
||||
status = 1;
|
||||
}
|
||||
message = StringUtils.getSendStr(builder, message, status == 1 ? true : false);
|
||||
int m = n;
|
||||
if(StringUtils.isNotEmpty(message)){
|
||||
|
||||
System.out.println(message);
|
||||
pro(text, n, length, builder, ONE_MAX_TEXT);
|
||||
}else if(n < length){
|
||||
pro(text, n, length, builder, ONE_MAX_TEXT);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user