添加实体统一功能(完结)

v_0.0.2
xueqingkun 3 months ago
parent fe38922324
commit 4793061893

@ -45,6 +45,8 @@ public class DataCompareRetriever implements Retriever {
log.warn("查询内容为空,无法执行数据对比检索"); log.warn("查询内容为空,无法执行数据对比检索");
return new ArrayList<>(); return new ArrayList<>();
} }
query = this.rewriteQuery(query);
log.info("retrieval: 重写查询内容为:{}", query);
// 对问题进行分词 // 对问题进行分词
CypherSchemaDTO schemaDTO = tripleToCypherExecutor.queryRelationSchema(query); CypherSchemaDTO schemaDTO = tripleToCypherExecutor.queryRelationSchema(query);
log.info("retrieval: 查询到的关系图谱schema 节点个数:{} ,关系结束{} ", schemaDTO.getNodes().size(), schemaDTO.getRelations().size()); log.info("retrieval: 查询到的关系图谱schema 节点个数:{} ,关系结束{} ", schemaDTO.getNodes().size(), schemaDTO.getRelations().size());

@ -328,6 +328,9 @@ public class KnowledgeGraphServiceImpl implements KnowledgeGraphService {
timer.start("generateGraph"); timer.start("generateGraph");
generateGraphSimple(eredtos); generateGraphSimple(eredtos);
log.info("生成知识图谱完成,耗时:{}秒", timer.intervalSecond("generateGraph")); log.info("生成知识图谱完成,耗时:{}秒", timer.intervalSecond("generateGraph"));
log.info("刷新图谱schema向量...");
tripleToCypherExecutor.refreshSchemaSegmentVector();
log.info("刷新图谱schema向量完成");
} }
@Override @Override

@ -597,6 +597,7 @@ public class TripleConversionPipelineImpl implements TripleConversionPipeline {
.peek(ere->{ .peek(ere->{
// 对实体名称进行同义词转换 // 对实体名称进行同义词转换
List<EntityExtractionDTO> entities = ere.getEntities(); List<EntityExtractionDTO> entities = ere.getEntities();
List<RelationExtractionDTO> relations = ere.getRelations();
for (EntityExtractionDTO entity : entities) { for (EntityExtractionDTO entity : entities) {
String name = entity.getName(); String name = entity.getName();
String standardTerm = keywordSynonymService.getStandardTerm(name, synonymDTOS); String standardTerm = keywordSynonymService.getStandardTerm(name, synonymDTOS);
@ -604,6 +605,18 @@ public class TripleConversionPipelineImpl implements TripleConversionPipeline {
entity.setName(standardTerm); entity.setName(standardTerm);
} }
} }
for (RelationExtractionDTO relation : relations) {
String sourceName = relation.getSource();
String targetName = relation.getTarget();
String sourceStandardTerm = keywordSynonymService.getStandardTerm(sourceName, synonymDTOS);
String targetStandardTerm = keywordSynonymService.getStandardTerm(targetName, synonymDTOS);
if (StrUtil.isNotEmpty(sourceStandardTerm)) {
relation.setSource(sourceStandardTerm);
}
if (StrUtil.isNotEmpty(targetStandardTerm)) {
relation.setTarget(targetStandardTerm);
}
}
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<String, EntityExtractionDTO> entityMap = new HashMap<>(); Map<String, EntityExtractionDTO> entityMap = new HashMap<>();

@ -162,6 +162,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
)); ));
attributes.put("truncationId", entity.getTruncationId()); attributes.put("truncationId", entity.getTruncationId());
attributes.put("name", entity.getName()); attributes.put("name", entity.getName());
attributes.remove("名称");
log.info("保存节点{},属性:{}", entity.getEntityEn(),JSONUtil.toJsonStr(entity.getAttributes())); log.info("保存节点{},属性:{}", entity.getEntityEn(),JSONUtil.toJsonStr(entity.getAttributes()));
List<Long> nodeIds = neo4jRepository.saveOrUpdateEntityNode(entity.getEntityEn(), "name", attributes); List<Long> nodeIds = neo4jRepository.saveOrUpdateEntityNode(entity.getEntityEn(), "name", attributes);
nodeCache.put(StrUtil.join("_", entity.getEntity(), entity.getName()), nodeIds); nodeCache.put(StrUtil.join("_", entity.getEntity(), entity.getName()), nodeIds);

@ -364,4 +364,9 @@ class PdfQaServerApplicationTests {
String rewriteQuery = retriever.rewriteQuery(text); String rewriteQuery = retriever.rewriteQuery(text);
log.info("重写前:{} \n 重写后的结果: {}", text, rewriteQuery); log.info("重写前:{} \n 重写后的结果: {}", text, rewriteQuery);
} }
@Test
public void refreshSchemaSegmentVectorTest(){
tripleToCypherExecutor.refreshSchemaSegmentVector();
}
} }

Loading…
Cancel
Save