|
|
|
@ -0,0 +1,72 @@
|
|
|
|
|
package com.supervision.demo;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.supervision.common.constant.IndexRuleConstants;
|
|
|
|
|
import com.supervision.police.domain.ModelAtomicIndex;
|
|
|
|
|
import com.supervision.police.domain.NotePrompt;
|
|
|
|
|
import com.supervision.police.service.ModelAtomicIndexService;
|
|
|
|
|
import com.supervision.police.service.NotePromptService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@SpringBootTest
|
|
|
|
|
public class IndexTest {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelAtomicIndexService modelAtomicIndexService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NotePromptService notePromptService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图谱生成原子指标历史数据关联提示词
|
|
|
|
|
* 1. 查询出queryLang不为空的数据
|
|
|
|
|
* 2. 查询出type为2的notePrompt数据
|
|
|
|
|
* 3. 遍历queryLang,将中文单词提取出来,拼接成1-3-2的格式
|
|
|
|
|
* 4. 在notePrompt中查找是否有匹配的name
|
|
|
|
|
* 5. 如果有,将promptId更新到modelAtomicIndex中
|
|
|
|
|
* 6. 如果没有,记录下来
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void test() {
|
|
|
|
|
// 查询出queryLang不为空的数据
|
|
|
|
|
List<ModelAtomicIndex> list = modelAtomicIndexService.list(new LambdaQueryWrapper<ModelAtomicIndex>().isNotNull(ModelAtomicIndex::getQueryLang).eq(ModelAtomicIndex::getIndexSource, IndexRuleConstants.OPERAND_TYPE_GRAPH));
|
|
|
|
|
List<NotePrompt> notePrompts = notePromptService.list(new LambdaQueryWrapper<NotePrompt>().isNotNull(NotePrompt::getName).eq(NotePrompt::getType, "2"));
|
|
|
|
|
AtomicInteger count = new AtomicInteger(1);
|
|
|
|
|
List<String> unMatched = new ArrayList<>();
|
|
|
|
|
list.forEach(modelAtomicIndex -> {
|
|
|
|
|
String input = modelAtomicIndex.getQueryLang();
|
|
|
|
|
Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5]+");
|
|
|
|
|
Matcher matcher = pattern.matcher(input);
|
|
|
|
|
List<String> chineseWords = new ArrayList<>();
|
|
|
|
|
while (matcher.find()) {
|
|
|
|
|
chineseWords.add(matcher.group());
|
|
|
|
|
}
|
|
|
|
|
if (chineseWords.size() != 3) {
|
|
|
|
|
throw new IllegalArgumentException("输入字符串中不符合 1-3-2 的中文单词结构要求");
|
|
|
|
|
}
|
|
|
|
|
// 将chineseWords转换为横杠-分隔的字符串
|
|
|
|
|
String chineseWordsStr = chineseWords.get(0) + "-" + chineseWords.get(2) + "-" + chineseWords.get(1);
|
|
|
|
|
log.info("第{}个:{}", count, chineseWordsStr);
|
|
|
|
|
//尝试在notePrompts中查找是否有匹配的name(注意去除换行符)
|
|
|
|
|
NotePrompt notePrompt = notePrompts.stream().filter(note -> note.getName().trim().equals(chineseWordsStr)).findFirst().orElse(null);
|
|
|
|
|
if (notePrompt != null) {
|
|
|
|
|
log.info("找到匹配的name:{}", notePrompt.getName());
|
|
|
|
|
modelAtomicIndex.setPromptId(notePrompt.getId());
|
|
|
|
|
modelAtomicIndexService.updateById(modelAtomicIndex);
|
|
|
|
|
} else {
|
|
|
|
|
unMatched.add(chineseWordsStr);
|
|
|
|
|
}
|
|
|
|
|
count.getAndIncrement();
|
|
|
|
|
});
|
|
|
|
|
log.info("未匹配的:{}。共:{}个", unMatched, unMatched.size());
|
|
|
|
|
}
|
|
|
|
|
}
|