|
|
@ -1,13 +1,124 @@
|
|
|
|
package com.supervision.livedigitalavatarmanage;
|
|
|
|
package com.supervision.livedigitalavatarmanage;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
|
|
import com.supervision.livedigitalavatarmanage.domain.ScriptKeypoints;
|
|
|
|
|
|
|
|
import com.supervision.livedigitalavatarmanage.service.ScriptKeypointsService;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@SpringBootTest
|
|
|
|
@SpringBootTest
|
|
|
|
class LiveDigitalAvatarManageApplicationTests {
|
|
|
|
class LiveDigitalAvatarManageApplicationTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ScriptKeypointsService scriptKeypointsService;
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void contextLoads() {
|
|
|
|
void contextLoads() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String path = "C:\\Users\\Administrator\\Desktop\\script.txt";
|
|
|
|
|
|
|
|
List<String> datas = FileUtil.readUtf8Lines(path);
|
|
|
|
|
|
|
|
List<HashMap<String, String>> list = datas.stream().map(i -> StrUtil.split(i, "\t")).map(i -> {
|
|
|
|
|
|
|
|
HashMap<String, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("scriptType", i.get(0));
|
|
|
|
|
|
|
|
map.put("scriptKeyPoint", i.get(1));
|
|
|
|
|
|
|
|
map.put("exampleTemplate", i.get(2));
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
List<String> scriptTypes = List.of("开场信息","场控文案","讲品内容","品牌价值","应用场景","促单信息");
|
|
|
|
|
|
|
|
// 话术类型 话术关键点 示例模板
|
|
|
|
|
|
|
|
Map<String, List<Map<String, String>>> scriptTypeMap = list.stream().collect(Collectors.groupingBy(m -> m.get("scriptType")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List<List<Map<String, String>>>> groupMap = new HashMap<>();
|
|
|
|
|
|
|
|
for (String scriptType : scriptTypes) {
|
|
|
|
|
|
|
|
List<Map<String, String>> maps = scriptTypeMap.get(scriptType);
|
|
|
|
|
|
|
|
if (null == maps) {
|
|
|
|
|
|
|
|
System.out.println("话术类型:" + scriptType + ",无数据");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 随机取五组话术关键点,每组关键点条数小于6条大于两条
|
|
|
|
|
|
|
|
List<List<Integer>> lists = generateIndexCombinations(maps.size());
|
|
|
|
|
|
|
|
List<List<Map<String, String>>> list1 = lists.stream().filter(l -> l.size() <= 6 && l.size() >= 2).map(l -> {
|
|
|
|
|
|
|
|
List<Map<String, String>> group = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Integer index : l) {
|
|
|
|
|
|
|
|
group.add(maps.get(index));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return group;
|
|
|
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
groupMap.put(scriptType, list1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<List<Map<String, String>>> result = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
|
|
|
|
List<Map<String, String>> objects = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String scriptType : scriptTypes) {
|
|
|
|
|
|
|
|
List<List<Map<String, String>>> lists = groupMap.get(scriptType);
|
|
|
|
|
|
|
|
if (null == lists) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int i1 = RandomUtil.randomInt(0, lists.size());
|
|
|
|
|
|
|
|
List<Map<String, String>> maps = lists.get(i1);
|
|
|
|
|
|
|
|
objects.addAll(maps);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result.add(objects);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (List<Map<String, String>> mapList : result) {
|
|
|
|
|
|
|
|
String scriptId = StrUtil.uuid();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
String current = "";
|
|
|
|
|
|
|
|
for (Map<String, String> mao : mapList) {
|
|
|
|
|
|
|
|
String scriptKeyPoint = mao.get("scriptKeyPoint");
|
|
|
|
|
|
|
|
String exampleTemplate = mao.get("exampleTemplate");
|
|
|
|
|
|
|
|
String scriptType = mao.get("scriptType");
|
|
|
|
|
|
|
|
if (StrUtil.equals(scriptKeyPoint, current)){
|
|
|
|
|
|
|
|
index ++;
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
current = scriptKeyPoint;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptKeypoints keypoints = new ScriptKeypoints();
|
|
|
|
|
|
|
|
keypoints.setScriptType(scriptType);
|
|
|
|
|
|
|
|
keypoints.setKeyPoint(scriptKeyPoint);
|
|
|
|
|
|
|
|
keypoints.setScriptId(scriptId);
|
|
|
|
|
|
|
|
keypoints.setScriptTypeOrderNum(i);
|
|
|
|
|
|
|
|
keypoints.setKeyPointOrderNum(index);
|
|
|
|
|
|
|
|
keypoints.setKeyPointExample(exampleTemplate);
|
|
|
|
|
|
|
|
scriptKeypointsService.save(keypoints);
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 生成长度为n的数组的所有索引组合
|
|
|
|
|
|
|
|
* @param n 数组长度
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private List<List<Integer>> generateIndexCombinations(int n) {
|
|
|
|
|
|
|
|
List<List<Integer>> result = new ArrayList<>();
|
|
|
|
|
|
|
|
int total = 1 << n; // 2^n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int mask = 1; mask < total; mask++) { // 从1开始,跳过空集
|
|
|
|
|
|
|
|
List<Integer> current = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
|
|
|
if ((mask & (1 << i)) != 0) { // 检查第i位是否被选中
|
|
|
|
|
|
|
|
current.add(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result.add(current);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|