|
|
@ -9,6 +9,7 @@ import com.supervision.pdfqaserver.dto.neo4j.NodeData;
|
|
|
|
import com.supervision.pdfqaserver.dto.neo4j.RelationObject;
|
|
|
|
import com.supervision.pdfqaserver.dto.neo4j.RelationObject;
|
|
|
|
import com.supervision.pdfqaserver.dto.neo4j.RelationshipData;
|
|
|
|
import com.supervision.pdfqaserver.dto.neo4j.RelationshipData;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.neo4j.driver.*;
|
|
|
|
import org.neo4j.driver.*;
|
|
|
|
import org.neo4j.driver.Record;
|
|
|
|
import org.neo4j.driver.Record;
|
|
|
|
import org.neo4j.driver.types.Node;
|
|
|
|
import org.neo4j.driver.types.Node;
|
|
|
@ -20,6 +21,7 @@ import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
import static org.neo4j.driver.Values.parameters;
|
|
|
|
import static org.neo4j.driver.Values.parameters;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Repository
|
|
|
|
@Repository
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class Neo4jRepository {
|
|
|
|
public class Neo4jRepository {
|
|
|
@ -153,6 +155,7 @@ public class Neo4jRepository {
|
|
|
|
if (StrUtil.isEmpty(nodeType)){
|
|
|
|
if (StrUtil.isEmpty(nodeType)){
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeType = nodeType.substring(1, nodeType.length()-1).replace("`", "");
|
|
|
|
String propertyName = record.get("propertyName").asString();
|
|
|
|
String propertyName = record.get("propertyName").asString();
|
|
|
|
List<String> propertyTypes = record.get("propertyTypes").asList(Value::asString);
|
|
|
|
List<String> propertyTypes = record.get("propertyTypes").asList(Value::asString);
|
|
|
|
|
|
|
|
|
|
|
@ -160,8 +163,9 @@ public class Neo4jRepository {
|
|
|
|
TruncationERAttributeDTO attributeDTO = new TruncationERAttributeDTO(propertyName, null, CollUtil.getFirst(propertyTypes));
|
|
|
|
TruncationERAttributeDTO attributeDTO = new TruncationERAttributeDTO(propertyName, null, CollUtil.getFirst(propertyTypes));
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已存在该节点类型
|
|
|
|
// 检查是否已存在该节点类型
|
|
|
|
|
|
|
|
final String nodeType_f = nodeType;
|
|
|
|
EntityExtractionDTO existingEntity = extractionDTOS.stream()
|
|
|
|
EntityExtractionDTO existingEntity = extractionDTOS.stream()
|
|
|
|
.filter(e -> StrUtil.equals(e.getEntityEn(), nodeType))
|
|
|
|
.filter(e -> StrUtil.equals(e.getEntityEn(), nodeType_f))
|
|
|
|
.findFirst().orElse(null);
|
|
|
|
.findFirst().orElse(null);
|
|
|
|
|
|
|
|
|
|
|
|
if (existingEntity != null) {
|
|
|
|
if (existingEntity != null) {
|
|
|
@ -197,6 +201,7 @@ public class Neo4jRepository {
|
|
|
|
if (StrUtil.isEmpty(relType)){
|
|
|
|
if (StrUtil.isEmpty(relType)){
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
relType = relType.substring(1, relType.length()-1).replace("`", "");
|
|
|
|
String propertyName = record.get("propertyName").asString();
|
|
|
|
String propertyName = record.get("propertyName").asString();
|
|
|
|
List<String> propertyTypes = record.get("propertyTypes").asList(Value::asString);
|
|
|
|
List<String> propertyTypes = record.get("propertyTypes").asList(Value::asString);
|
|
|
|
|
|
|
|
|
|
|
@ -214,14 +219,15 @@ public class Neo4jRepository {
|
|
|
|
|
|
|
|
|
|
|
|
List<RelationExtractionDTO> relationExtractionDTOS = new ArrayList<>();
|
|
|
|
List<RelationExtractionDTO> relationExtractionDTOS = new ArrayList<>();
|
|
|
|
String queryEndpoints = """
|
|
|
|
String queryEndpoints = """
|
|
|
|
MATCH (s)-[r:`{rtype}`]->(t)
|
|
|
|
MATCH (s)-[r: `{rtype}` ]->(t)
|
|
|
|
WITH labels(s)[0] AS src, labels(t)[0] AS tgt
|
|
|
|
WITH labels(s)[0] AS src, labels(t)[0] AS tgt
|
|
|
|
RETURN src, tgt
|
|
|
|
RETURN src, tgt
|
|
|
|
""";
|
|
|
|
""";
|
|
|
|
for (Map.Entry<String, List<Map<String, String>>> entry : relationProperties.entrySet()) {
|
|
|
|
for (Map.Entry<String, List<Map<String, String>>> entry : relationProperties.entrySet()) {
|
|
|
|
String relType = entry.getKey();
|
|
|
|
String relType = entry.getKey();
|
|
|
|
List<Map<String, String>> properties = entry.getValue();
|
|
|
|
List<Map<String, String>> properties = entry.getValue();
|
|
|
|
Result run = session.run(queryEndpoints, parameters("rtype", relType));
|
|
|
|
String formatted = StrUtil.format(queryEndpoints,Map.of("rtype",relType));
|
|
|
|
|
|
|
|
Result run = session.run(formatted);
|
|
|
|
for (Record record : run.list()) {
|
|
|
|
for (Record record : run.list()) {
|
|
|
|
String sourceType = record.get("src").asString();
|
|
|
|
String sourceType = record.get("src").asString();
|
|
|
|
String targetType = record.get("tgt").asString();
|
|
|
|
String targetType = record.get("tgt").asString();
|
|
|
|