|
@@ -20,8 +20,8 @@ class DBUtil {
|
|
|
private static final Set<String> FIRST_DB_TABLES = new HashSet<>(Set.of("special_table1", "special_table2"));
|
|
|
|
|
|
// 数据库路径配置
|
|
|
- private static final String FIRST_DB_PATH = "D:/Projects/北交/北交/dc数据库/yq_dlp.db"; // 需要用户补充
|
|
|
- private static final String SECOND_DB_PATH = "D:/Projects/北交/北交/dc数据库/yq_dlp_02.db";
|
|
|
+ private static final String FIRST_DB_PATH = "D:\\Study\\postgraduate\\project\\BJ_screen\\database\\yq_dlp.db"; // 需要用户补充
|
|
|
+ private static final String SECOND_DB_PATH = "D:\\Study\\postgraduate\\project\\BJ_screen\\database\\yq_dlp_02.db";
|
|
|
|
|
|
public static Connection getConnection(String sql) throws SQLException {
|
|
|
String tableName = extractTableName(sql);
|
|
@@ -302,7 +302,7 @@ class KnowledgeGraph {
|
|
|
|
|
|
|
|
|
class DBConfig {
|
|
|
- private static final String URL = "jdbc:mysql://localhost:3306/knowledge_graph?useSSL=false&serverTimezone=UTC";
|
|
|
+ private static final String URL = "jdbc:mysql://DN:3306/knowledge_graph?useSSL=false&serverTimezone=UTC";
|
|
|
private static final String USER = "root";
|
|
|
private static final String PASSWORD = "123456";
|
|
|
|
|
@@ -323,6 +323,9 @@ public class KnowledgeGraphBuilder {
|
|
|
String attr1 = entity.properties.get("attr1");
|
|
|
if (attr1 == null || attr1.isEmpty()) continue;
|
|
|
|
|
|
+ String attr3 = entity.properties.get("attr3");
|
|
|
+ if (attr3 == null || attr3.isEmpty()) continue;
|
|
|
+
|
|
|
try {
|
|
|
// 解析 JSON
|
|
|
Map<String, Object> jsonMap = mapper.readValue(attr1, new TypeReference<>() {});
|
|
@@ -333,6 +336,7 @@ public class KnowledgeGraphBuilder {
|
|
|
);
|
|
|
|
|
|
if (matched) {
|
|
|
+// System.out.println("Matched entity: " + entity.id + ", attr3: " + attr3);
|
|
|
matchingBlocks.add(entity);
|
|
|
}
|
|
|
|
|
@@ -436,25 +440,30 @@ public class KnowledgeGraphBuilder {
|
|
|
|
|
|
|
|
|
// 匹配Block节点
|
|
|
- List<String> keywords = List.of("送出电量");
|
|
|
+ List<String> keywords = List.of("受入电量");
|
|
|
List<Entity> matchedBlocks = findMatchingBlocksByKeywords(kg, keywords);
|
|
|
|
|
|
System.out.println("匹配到的Block节点:");
|
|
|
for (Entity e : matchedBlocks) {
|
|
|
System.out.println(e.id + " - " + e.properties.get("node_name"));
|
|
|
+// System.out.println(e.properties.get("attr3"));
|
|
|
+ String filePath = "Json/json_data/" + e.properties.get("attr3") + "_output.json";
|
|
|
+ System.out.println(filePath);
|
|
|
}
|
|
|
|
|
|
// 新增处理SQL查询的调用
|
|
|
processEntitiesWithSQL(kg);
|
|
|
|
|
|
- // 提取子图并导出
|
|
|
- Set<String> entities = Set.of("9b6349887dc54a9e9b8e0a192ed64e52");
|
|
|
- Set<String> relTypes = Set.of("Block-Node");
|
|
|
- Set<Relation> requiredTriples = Set.of();
|
|
|
+ //
|
|
|
|
|
|
- KnowledgeGraph sub = kg.extractMinimumConnectedSubgraph(entities, relTypes, requiredTriples);
|
|
|
- sub.printGraph();
|
|
|
- sub.exportToDot("output_subgraph.dot");
|
|
|
+ // 提取子图并导出
|
|
|
+// Set<String> entities = Set.of("9b6349887dc54a9e9b8e0a192ed64e52");
|
|
|
+// Set<String> relTypes = Set.of("Block-Node");
|
|
|
+// Set<Relation> requiredTriples = Set.of();
|
|
|
+//
|
|
|
+// KnowledgeGraph sub = kg.extractMinimumConnectedSubgraph(entities, relTypes, requiredTriples);
|
|
|
+// sub.printGraph();
|
|
|
+// sub.exportToDot("output_subgraph.dot");
|
|
|
}
|
|
|
|
|
|
private static void loadFromDatabase(KnowledgeGraph kg) {
|