|
|
|
@ -56,6 +56,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
|
|
|
|
|
log.info("没有找到匹配的意图,query: {}", query);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
log.info("找到匹配的意图,query: {}, relations: {}", query, relations.stream().map(Intention::getDigest).collect(Collectors.joining(",")));
|
|
|
|
|
List<DomainMetadataDTO> domainMetadataDTOS = domainMetadataService.listByIntentionIds(relations.stream().map(Intention::getId).toList());
|
|
|
|
|
CypherSchemaDTO schemaDTO = this.queryRelationSchema(domainMetadataDTOS);
|
|
|
|
|
if (CollUtil.isEmpty(schemaDTO.getRelations()) && CollUtil.isEmpty(schemaDTO.getNodes())) {
|
|
|
|
@ -64,6 +65,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
|
|
|
|
|
}
|
|
|
|
|
String prompt = promptMap.get(TEXT_TO_CYPHER_2);
|
|
|
|
|
String format = StrUtil.format(prompt, Map.of("question", query, "schema", schemaDTO.format()));
|
|
|
|
|
log.info("生成Cypher脚本,query: {}, format: {}", query, format);
|
|
|
|
|
String call = aiCallService.call(format);
|
|
|
|
|
if (StrUtil.contains(call,"I could not generate a Cypher script; the required information is not part of the Neo4j schema.")){
|
|
|
|
|
log.info("大模型没能生成cypher,query: {}", query);
|
|
|
|
@ -209,19 +211,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
|
|
|
|
|
if (null == rel){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<RelationExtractionDTO> relSourceType = cypherSchemaDTO.getRelations(sourceType);
|
|
|
|
|
List<RelationExtractionDTO> relTargetType = cypherSchemaDTO.getRelations(targetType);
|
|
|
|
|
|
|
|
|
|
relSourceType.add(rel);
|
|
|
|
|
relSourceType.addAll(relTargetType);
|
|
|
|
|
for (RelationExtractionDTO relationExtractionDTO : relSourceType) {
|
|
|
|
|
boolean none = merged.stream().noneMatch(i -> StrUtil.equals(i.getRelation(), relationExtractionDTO.getRelation()) &&
|
|
|
|
|
StrUtil.equals(i.getSourceType(), relationExtractionDTO.getSourceType()) &&
|
|
|
|
|
StrUtil.equals(i.getTargetType(), relationExtractionDTO.getTargetType()));
|
|
|
|
|
if (none){
|
|
|
|
|
merged.add(relationExtractionDTO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
merged.add(rel);
|
|
|
|
|
}
|
|
|
|
|
List<EntityExtractionDTO> entityExtractionDTOS = new ArrayList<>();
|
|
|
|
|
for (RelationExtractionDTO relationExtractionDTO : merged) {
|
|
|
|
@ -248,7 +238,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
|
|
|
|
|
String prompt = promptMap.get(CLASSIFY_QUERY_INTENT);
|
|
|
|
|
List<Intention> result = new ArrayList<>();
|
|
|
|
|
log.info("开始分类意图,query: {}, intentions size: {}", query, intentions.size());
|
|
|
|
|
List<List<Intention>> intentionSplit = CollUtil.split(intentions, 200);
|
|
|
|
|
List<List<Intention>> intentionSplit = CollUtil.split(intentions, 300);
|
|
|
|
|
for (List<Intention> intentionList : intentionSplit) {
|
|
|
|
|
log.info("分类意图,query: {}, intentions size: {}", query, intentionList.size());
|
|
|
|
|
List<String> intents = intentionList.stream().map(Intention::getDigest).toList();
|
|
|
|
@ -256,7 +246,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
|
|
|
|
|
"intents", JSONUtil.toJsonStr(intents));
|
|
|
|
|
String format = StrUtil.format(prompt, params);
|
|
|
|
|
String call = aiCallService.call(format);
|
|
|
|
|
|
|
|
|
|
log.info("classifyIntents:分类意图结果,query: {}, call: {}", query, call);
|
|
|
|
|
if (StrUtil.isEmpty(call)) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|