Cross-graph database shortest path calculation method and device, electronic equipment and medium
By obtaining the user's shortest path request, we judge whether the knowledge graph to which the starting node and the terminating node belong is in the same graph database, and obtain and splice the subgraph when necessary, the problem of shortest path calculation across graph databases is solved, and efficient path calculation is achieved.
Patent Information
- Application Number
- CN202411791011.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-14
AI Technical Summary
The prior art cannot implement the shortest path calculation across graph databases, and cannot handle the situation of different graph databases where different knowledge graphs are located.
By obtaining the user's shortest path request, it is determined whether the knowledge graph to which the starting node and the terminating node belong is in the same graph database. If not, the sub-map is obtained in their respective knowledge graphs and spliced into the target knowledge graph, and then the shortest path is calculated.
The knowledge graph fusion across graph databases is realized, reducing the amount of data loading and computing of target knowledge graphs, and improving the efficiency of shortest path calculation.
Smart Images

Figure CN119622041A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to artificial intelligence, and in particular, to a method, device, electronic device, and medium for calculating the shortest path across a graph database. Background Art
[0002] Knowledge graphs can reveal the dynamic development of knowledge fields and are widely used in various industries. Databases that carry knowledge graphs are called graph databases. Solving problems with knowledge graphs usually requires calculating the shortest path.
[0003] In the prior art, the calculation of the shortest path in a knowledge graph requires ensuring that the knowledge graph is located in the same graph database.
[0004] However, as knowledge graphs are applied to various industries, the problem of calculating the shortest path through different knowledge graphs located in different graph databases has arisen. Existing technologies cannot achieve the shortest path calculation across graph databases. Summary of the invention
[0005] The present application provides a method, device, electronic device and medium for calculating the shortest path across a graph database to implement the shortest path calculation across a graph database.
[0006] In a first aspect, an embodiment of the present application provides a method for calculating the shortest path across a graph database, and the method for calculating the shortest path across a graph database includes:
[0007] Obtain the user's shortest path request; the shortest path request includes the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs, and the maximum degree;
[0008] Determine whether the knowledge graph to which the start node belongs and the knowledge graph to which the end node belongs are stored in the same graph database;
[0009] If not, obtain the first subgraph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtain the second subgraph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree;
[0010] Concatenate the first sub-graph and the second sub-graph to obtain the target knowledge graph;
[0011] Determine the shortest path based on the target knowledge graph and the maximum degree.
[0012] In a second aspect, an embodiment of the present application further provides a device for calculating the shortest path across a graph database, the device for calculating the shortest path across a graph database comprising:
[0013] The shortest path request acquisition module is used to obtain the user's shortest path request; the shortest path request includes the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs, and the maximum degree;
[0014] A node position determination module is used to determine whether the knowledge graph to which the start node belongs and the knowledge graph to which the end node belongs are stored in the same graph database;
[0015] A sub-graph acquisition module, for, if not, acquiring a first sub-graph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and acquiring a second sub-graph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree;
[0016] A sub-graph splicing module, used to splice the first sub-graph and the second sub-graph to obtain a target knowledge graph;
[0017] The shortest path determination module is used to determine the shortest path based on the target knowledge graph and the maximum degree.
[0018] In a third aspect, an embodiment of the present application further provides an electronic device, the electronic device comprising:
[0019] one or more processors;
[0020] A storage device for storing one or more programs;
[0021] When one or more programs are executed by one or more processors, the one or more processors implement any one of the shortest path calculation methods across graph databases provided in the embodiments of the present application.
[0022] In a fourth aspect, an embodiment of the present application further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute any one of the shortest path calculation methods across a graph database provided in an embodiment of the present application.
[0023] The present application obtains the shortest path request from the user; the shortest path request includes the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs and the maximum degree; it is determined whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database; if not, a first sub-graph is obtained in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and a second sub-graph is obtained in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree, and the first sub-graph and the second sub-graph determined by the maximum degree can ensure that the target knowledge graph obtained subsequently includes all paths that meet the maximum degree; the first sub-graph and the second sub-graph are spliced to obtain the target knowledge graph, and the fusion of the knowledge graphs across the graph database is realized, and by splicing the first sub-graph and the second sub-graph, there is no need to fuse all the knowledge graphs across the graph database, thereby reducing the amount of data loaded and calculated in the subsequent target knowledge graph and improving the calculation efficiency of the shortest path; the shortest path is determined according to the target knowledge graph and the maximum degree, and the calculation of the shortest path of the knowledge graph in the cross-graph database is realized. Therefore, the technical solution of the present application solves the problem of being unable to implement the shortest path calculation across graph databases, thereby achieving the effect of implementing the shortest path calculation across graph databases. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a flowchart of a method for calculating the shortest path across a graph database in Embodiment 1 of the present application;
[0025] Figure 2 It is a flowchart of a method for calculating the shortest path across a graph database in Embodiment 2 of the present application;
[0026] Figure 3 It is a flowchart of a method for calculating the shortest path across a graph database in Embodiment 3 of the present application;
[0027] Figure 4 It is a structural schematic diagram of a device for calculating the shortest path across a graph database in Embodiment 4 of the present application;
[0028] Figure 5 It is a structural diagram of an electronic device in Embodiment 5 of the present application. DETAILED DESCRIPTION
[0029] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0030] It should be noted that the terms "first" and "second" etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0031] Embodiment 1
[0032] Figure 1 A flowchart of a method for calculating the shortest path across a graph database is provided for embodiment 1 of the present application. This embodiment can be applied to the situation of determining the shortest path between entities in a knowledge graph across a graph database. The method can be executed by a device for calculating the shortest path across a graph database. The device can be implemented in software and / or hardware and specifically configured in a shortest path calculation system.
[0033] See also Figure 1 The shortest path calculation method across the graph database shown includes the following steps:
[0034] S110, obtaining the user's shortest path request; the shortest path request includes a starting node, a knowledge graph to which the starting node belongs, an ending node, a knowledge graph to which the ending node belongs, and a maximum degree.
[0035] The shortest path request can be a calculation request from the user, which is used to trigger the calculation of the shortest path. The specific questions of the shortest path request can be different in different scenarios. In the system that uses the knowledge graph to provide services, after obtaining the user's request, the user's request is used as the shortest path request, and the shortest path calculation is automatically triggered. By calculating the shortest path in the corresponding knowledge graph, the best solution is provided to the user.
[0036] Optionally, in the system that provides services using knowledge graphs, service nodes can be set up, and an additional gateway layer can be added to the upper layer of the service node to achieve load balancing and improve service availability. There is no limit to the number of graph databases, and there is no limit to the number of service nodes for each graph database. Similarly, an additional gateway layer can be added between the graph database service node layer and the query processing node layer to achieve load balancing and improve service availability. The query processing node can be a node that responds to the user's shortest path request, and is used to obtain the user's shortest path request and determine the peer path.
[0037] The starting node may be the node corresponding to the starting entity for the shortest path calculation in the knowledge graph. The knowledge graph to which the starting node belongs may be the knowledge graph where the starting node is located. The ending node may be the node corresponding to the ending entity for the shortest path calculation in the knowledge graph. The knowledge graph to which the ending node belongs may be the knowledge graph where the ending node is located. The maximum degree may be the maximum degree allowed in the shortest path calculation. When a user sends a shortest path request, the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs, and the maximum degree are set.
[0038] S120. Determine whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database.
[0039] The shortest path calculation system is configured with multiple graph databases, each storing a different knowledge graph. The shortest path calculation system is also configured with a comprehensive information library, which is used to store basic information in each graph database, including the graph database identifier, graph database access address, and all nodes included in each graph database.
[0040] After obtaining the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs, the graph database where the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are located is queried through the comprehensive information base to determine whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database.
[0041] S130. If not, obtain a first subgraph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtain a second subgraph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree.
[0042] If not, that is, the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in different graph databases, then it is necessary to determine the shortest path across graph databases. The first sub-graph can be a sub-knowledge graph obtained from the knowledge graph to which the starting node belongs, with the starting node as the center and an out-degree not less than the maximum degree, which is used to obtain the target knowledge graph. For example, in the knowledge graph to which the starting node belongs, with the starting node as the center, the out-degree edges with the maximum degree are expanded outward to obtain the first sub-graph. The second sub-graph can be a sub-knowledge graph obtained from the knowledge graph to which the ending node belongs, with the ending node as the center and an in-degree not less than the maximum degree, which is used to obtain the target knowledge graph. For example, in the knowledge graph to which the ending node belongs, with the ending node as the center, the in-degree edges with the maximum degree are expanded outward to obtain the second sub-graph.
[0043] By obtaining the first subgraph and the second subgraph according to the maximum degree, it can be ensured that the target knowledge graph obtained by subsequently splicing the first subgraph and the second subgraph includes all paths from the start node to the end node that meet the maximum degree condition, thereby avoiding the omission of optional paths and ensuring the accuracy of the subsequent shortest path.
[0044] If so, that is, when the judgment result is yes, it can be determined whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are the same graph. If so, the shortest path can be directly determined by the preset shortest path calculation method. Otherwise, it can be executed according to S130 to reduce the amount of calculation of the graph database when calculating the shortest path.
[0045] S140: Concatenate the first sub-graph and the second sub-graph to obtain a target knowledge graph.
[0046] The target knowledge graph may be a knowledge graph obtained by fusing the first subgraph and the second subgraph. For example, the nodes in the first subgraph and the second subgraph may be equivalently matched, and the matched equivalent nodes may be merged to obtain the target knowledge graph. For another example, the nodes in the first subgraph and the second subgraph may be similarly calculated, and the nodes with higher similarity may be merged to obtain the target knowledge graph.
[0047] S150. Determine the shortest path according to the target knowledge graph and the maximum degree.
[0048] The shortest path is determined in the target knowledge graph by a preset shortest path calculation method. For example, the shortest path can be determined in the target knowledge graph by a Dijkstra (a professional term, a shortest path calculation method) algorithm.
[0049] The degree of the shortest path is compared with the maximum degree, and the determination result of the shortest path is returned to the user according to the comparison result. For example, if the degree of the shortest path is less than or equal to the maximum degree, the result corresponding to the shortest path is returned to the user, otherwise, the result that no condition is met is returned to the user, and the user is prompted to reset the maximum degree.
[0050] Knowledge graph, also known as knowledge domain visualization or knowledge domain mapping map, is a series of different graphics that show the knowledge development process and structural relationship. It uses visualization technology to describe knowledge resources and their carriers, and mine, analyze, construct, draw and display knowledge and their mutual connections. In the knowledge graph, a path is a collection of multi-hop relationships connecting two entities. For example, suppose there are three entities A, B and C, and two relationships AB and BC, then ABC is a path from A to C. The length of the path refers to the sum of the weights of all traversed relationships in the path. If not specified, the weight value of each relationship is 1 by default. For example, if the weight of the relationship is not specified, the default path length of ABC is 2.
[0051] The shortest path problem is a classic algorithmic problem in graph theory research, which aims to find the shortest path between two entities in a graph composed of entities and relationships. The specific forms of the shortest path problem include: the shortest path problem to determine the starting entity, the shortest path problem to determine the ending entity, the shortest path problem to determine the starting entity and the ending entity, and the global shortest path problem. The shortest path problem in this application refers to the shortest path problem to determine the starting entity and the ending entity, that is, knowing the starting entity and the ending entity, find the shortest path within a specified degree between the two entities.
[0052] In the prior art, solutions for shortest path calculation based on knowledge graphs can almost only support the starting entity and the ending entity in the same knowledge graph. If the starting entity and the ending entity are distributed in different knowledge graphs, no matter from which graph perspective, the path from one entity to another cannot be found, and the calculation cannot be completed. There are a few shortest path calculation methods that realize the case where the starting entity and the ending entity are in different knowledge graphs in the same graph database, that is, the shortest path calculation across knowledge graphs is realized. For the scenario where the knowledge graph is deployed in multiple graph databases, that is, across graph databases, the shortest path calculation cannot be realized.
[0053] However, in the existing technology, for the shortest path calculation across knowledge graphs, the two knowledge graphs can only be merged into the same knowledge graph and reloaded, which will cause the data volume of a single knowledge graph to expand, and bring tremendous pressure to the graph loading and graph query capabilities of the graph database.
[0054] The deployment scenarios of multiple graph databases can be high-availability scenarios such as active-active and grayscale scenarios of parallel graph databases from different manufacturers or different versions. This application can solve the computing problems in the deployment scenarios of multiple graph databases by supporting the calculation of the shortest path across graph databases, enabling users to deploy graph databases in a high-availability or grayscale release mode, thereby improving the robustness of the service.
[0055] The technical solution of this embodiment is to obtain the shortest path request of the user; the shortest path request includes the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs and the maximum degree; determine whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database; if not, obtain the first sub-graph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtain the second sub-graph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree, and the first sub-graph and the second sub-graph determined by the maximum degree can ensure that the target knowledge graph obtained subsequently includes all paths that meet the maximum degree; splice the first sub-graph and the second sub-graph to obtain the target knowledge graph, and realize the fusion of knowledge graphs across graph databases, and by splicing the first sub-graph and the second sub-graph, there is no need to fuse all knowledge graphs across graph databases, thereby reducing the amount of data loaded and calculated in the subsequent target knowledge graph and improving the calculation efficiency of the shortest path; determine the shortest path according to the target knowledge graph and the maximum degree, and realize the calculation of the shortest path of the knowledge graph in the cross-graph database. Therefore, the technical solution of the present application solves the problem of being unable to implement the shortest path calculation across graph databases, thereby achieving the effect of implementing the shortest path calculation across graph databases.
[0056] Embodiment 2
[0057] Figure 2 This is a flow chart of a method for calculating the shortest path across a graph database provided in Example 2 of the present application. The technical solution of this embodiment is further refined on the basis of the above technical solution.
[0058] Furthermore, "obtaining the first sub-graph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtaining the second sub-graph in the knowledge graph to which the terminating node belongs according to the terminating node and the maximum degree" is refined as: "taking the maximum degree as the first sub-degree, in the knowledge graph to which the starting node belongs, expanding the first sub-degree along the out-degree edge with the starting node as the center, to obtain the first sub-graph; taking the maximum degree as the second sub-degree, in the knowledge graph to which the terminating node belongs, expanding the second sub-degree along the in-degree edge with the terminating node as the center, to obtain the second sub-graph" to obtain the first sub-graph and the second sub-graph.
[0059] See also Figure 2 A method for calculating the shortest path across a graph database is shown, comprising:
[0060] S210. Obtain the user's shortest path request; the shortest path request includes a starting node, a knowledge graph to which the starting node belongs, an ending node, a knowledge graph to which the ending node belongs, and a maximum degree.
[0061] S220. Determine whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database.
[0062] S230. If not, take the maximum degree as the first sub-degree, and in the knowledge graph to which the starting node belongs, expand the first sub-degree along the out-degree edge with the starting node as the center to obtain the first sub-graph.
[0063] The first sub-degree may be the degree of the first sub-graph. The first sub-graph may be a knowledge graph after the first sub-degree is extended along the out-degree edge of the starting node in the knowledge graph to which the starting node belongs, with the starting node as the center. It can be understood that the first sub-graph is obtained after the first sub-degree out-degree edge is extended along the direction of the out-degree edge with the starting node as the vertex.
[0064] S240. Taking the maximum degree as the second sub-degree, in the knowledge graph to which the termination node belongs, the second sub-degree is expanded along the in-degree edge with the termination node as the center to obtain the second sub-graph.
[0065] The second sub-degree may be the degree of the second sub-graph. The second sub-graph may be a knowledge graph in which the second sub-degree is expanded along the in-degree edge of the terminating node with the terminating node as the center in the knowledge graph to which the terminating node belongs. It can be understood that the second sub-graph is obtained by expanding the second sub-degree in-degree edge along the direction of the in-degree edge with the terminating node as the vertex.
[0066] There may be extreme cases for the shortest path, for example, only the starting node is in the knowledge graph to which the starting node belongs, and the other nodes are in the knowledge graph to which the terminating node belongs; for another example, only the terminating node is in the knowledge graph to which the terminating node belongs, and the other nodes are in the knowledge graph to which the starting node belongs. The degrees of the first subgraph and the second subgraph are both the maximum degree, so that the first subgraph and the second subgraph can include all paths from the starting node to the terminating node that meet the maximum degree condition, which can avoid the omission of optional paths and ensure the accuracy of the subsequent shortest path; and minimize the number of nodes in the target knowledge graph, reduce the amount of data loaded and calculated in the subsequent target knowledge graph, reduce the pressure on graph storage, and improve the calculation efficiency of the shortest path.
[0067] S250: Concatenate the first sub-graph and the second sub-graph to obtain a target knowledge graph.
[0068] S260. Determine the shortest path according to the target knowledge graph and the maximum degree.
[0069] The technical solution of this embodiment is to take the maximum degree as the first sub-degree, and in the knowledge graph to which the starting node belongs, expand the first sub-degree along the out-degree edge with the starting node as the center to obtain the first sub-graph; take the maximum degree as the second sub-degree, and in the knowledge graph to which the terminating node belongs, expand the second sub-degree along the in-degree edge with the terminating node as the center to obtain the second sub-graph. In this way, the degrees of the first sub-graph and the second sub-graph are both the maximum degree. Subsequently, the target knowledge graph obtained by splicing the first sub-graph and the second sub-graph includes all paths from the starting node to the terminating node that meet the maximum degree condition, which can avoid the omission of optional paths, ensure the accuracy of the subsequent shortest path, and minimize the number of nodes in the target knowledge graph, reduce the amount of data loaded and calculated in the subsequent target knowledge graph, and improve the calculation efficiency of the shortest path.
[0070] Embodiment 3
[0071] Figure 3 This is a flowchart of a method for calculating the shortest path across a graph database provided in Example 3 of the present application. The technical solution of this embodiment is further refined on the basis of the above technical solution.
[0072] Furthermore, "joining the first sub-graph and the second sub-graph to obtain a target knowledge graph" is refined into: "determining equivalent nodes in the first sub-graph and the second sub-graph; according to the equivalent nodes, joining the first sub-graph and the second sub-graph to obtain a target knowledge graph" to obtain the target knowledge graph.
[0073] See also Figure 3 A method for calculating the shortest path across a graph database is shown, comprising:
[0074] S310. Obtain the user's shortest path request; the shortest path request includes a starting node, a knowledge graph to which the starting node belongs, an ending node, a knowledge graph to which the ending node belongs, and a maximum degree.
[0075] S320. Determine whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database.
[0076] S330. If not, obtain the first subgraph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtain the second subgraph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree.
[0077] S340: Determine equivalent nodes in the first sub-graph and the second sub-graph.
[0078] Equivalent nodes can be nodes that can be equivalently replaced in different knowledge graphs, and are used to splice the first sub-graph and the second sub-graph. Different knowledge graphs may have different names and identifiers of nodes, but the same basic information. Such two nodes can be equivalent nodes. Exemplarily, the equivalent entity situation recorded in the comprehensive information library can be used to query whether there are equivalent nodes in each node in the first sub-graph and the second sub-graph.
[0079] The comprehensive information database includes an entity similarity model, which is used to match and generate equivalent entity information in the comprehensive information database. After loading a knowledge graph, the comprehensive information database traverses all entities in the graph and compares the entity information with all existing entities in each graph database through the entity similarity model. If the entity is considered equivalent to an entity in another knowledge graph, the similarity information and attribute correspondence between the two are recorded in the equivalent entity information.
[0080] In an optional embodiment, determining equivalent nodes in the first subgraph and the second subgraph includes: converting the first subgraph and the second subgraph into a standard format to obtain a first standard subgraph and a second standard subgraph; determining whether equivalent entities exist in the first standard subgraph and the second standard subgraph; if so, treating nodes corresponding to the equivalent entities as equivalent nodes.
[0081] Since the storage formats of various knowledge graphs are different, in order to identify equivalent nodes, the first subgraph and the second subgraph need to be converted into a standard format to accurately determine equivalent nodes and improve the accuracy of equivalent node determination. The first standard subgraph can be a knowledge graph after the first subgraph is converted into a standard format, which is used to match equivalent entities. The second standard subgraph can be a knowledge graph after the second subgraph is converted into a standard format, which is used to match equivalent entities.
[0082] Traverse each entity in the first standard subgraph and the second standard subgraph to determine whether there are equivalent entities in the first standard subgraph and the second standard subgraph; if so, take the nodes corresponding to the equivalent entities as equivalent nodes.
[0083] The first standard subgraph and the second standard subgraph are obtained by converting the first subgraph and the second subgraph into a standard format; it is determined whether there are equivalent entities in the first standard subgraph and the second standard subgraph; if so, the nodes corresponding to the equivalent entities are used as equivalent nodes, and after converting the first subgraph and the second subgraph into the same format, the determination of equivalent entities is performed to improve the accuracy of the determination and the accuracy of the subsequent splicing of the first subgraph and the second subgraph.
[0084] In an optional embodiment, determining whether equivalent entities exist in the first standard subgraph and the second standard subgraph includes: traversing each entity in the first standard subgraph, and determining whether equivalent entities exist in the second standard subgraph through an equivalent entity table in a comprehensive database.
[0085] The equivalent entity table can be a table storing equivalent entity information in each knowledge graph, including two equivalent entity identifiers and the graphs they belong to, and the correspondence between the attributes of the two entities. After the comprehensive database determines the information of equivalent entities through the entity similarity model, the equivalent entity information is stored in the equivalent entity table. After obtaining the first standard subgraph and the second standard subgraph, traverse each entity in the first standard subgraph, query whether there is an equivalent entity in the second standard subgraph in the equivalent entity table in the comprehensive database, and confirm one by one whether each entity in the first standard subgraph has an equivalent entity in the second standard subgraph.
[0086] By traversing each entity in the first standard sub-graph and using the equivalent entity table in the comprehensive database, it is determined whether there are equivalent entities in the second standard sub-graph. By traversing the first standard sub-graph, it is ensured that no equivalent entity is missed and the accuracy of the equivalent entity confirmation is ensured, thereby ensuring the accuracy of the subsequent splicing of the first sub-graph and the second sub-graph.
[0087] S350. According to equivalent nodes, the first sub-graph and the second sub-graph are concatenated to obtain a target knowledge graph.
[0088] By performing equivalent replacement on equivalent nodes in the first subgraph and the second subgraph, the first subgraph and the second subgraph are spliced together to obtain the target knowledge graph.
[0089] In an optional embodiment, the first sub-graph and the second sub-graph are spliced according to equivalent nodes to obtain a target knowledge graph, including: merging equivalent nodes in the first sub-graph and the second sub-graph to obtain a target knowledge graph.
[0090] The equivalent nodes in the first sub-graph and the second sub-graph have the same meaning, so the equivalent nodes are merged to achieve the fusion of the first sub-graph and the second sub-graph to obtain the target knowledge graph.
[0091] By merging equivalent nodes in the first sub-graph and the second sub-graph, the target knowledge graph is obtained, and the accurate fusion of the first sub-graph and the second sub-graph is achieved, thereby ensuring the accuracy of the target knowledge graph after fusion.
[0092] S360. Determine the shortest path based on the target knowledge graph and the maximum degree.
[0093] The technical solution of this embodiment determines the equivalent nodes in the first sub-graph and the second sub-graph; based on the equivalent nodes, the first sub-graph and the second sub-graph are spliced to obtain the target knowledge graph, which can achieve accurate fusion of the first sub-graph and the second sub-graph, ensure the correctness of the relationship between the entities in the fused target knowledge graph, and further ensure the accuracy of the calculation result of the shortest path.
[0094] Embodiment 4
[0095] Figure 4 The figure shows a schematic diagram of the structure of a shortest path calculation device across a graph database provided in the fourth embodiment of the present application. This embodiment can be applied to the case of determining the shortest path between entities in a knowledge graph across a graph database, and is configured in a shortest path calculation system. The specific structure of the shortest path calculation device across a graph database is as follows:
[0096] The shortest path request acquisition module 410 is used to obtain the shortest path request of the user; the shortest path request includes the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs, and the maximum degree;
[0097] A node position determination module 420 is used to determine whether the knowledge graph to which the start node belongs and the knowledge graph to which the end node belongs are stored in the same graph database;
[0098] The sub-graph acquisition module 430 is used to acquire the first sub-graph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and acquire the second sub-graph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree, if not.
[0099] A sub-graph splicing module 440 is used to splice the first sub-graph and the second sub-graph to obtain a target knowledge graph;
[0100] The shortest path determination module 450 is used to determine the shortest path according to the target knowledge graph and the maximum degree.
[0101] The technical solution of this embodiment is to obtain the shortest path request of the user; the shortest path request includes the starting node, the knowledge graph to which the starting node belongs, the ending node, the knowledge graph to which the ending node belongs and the maximum degree; determine whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database; if not, obtain the first sub-graph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtain the second sub-graph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree, and the first sub-graph and the second sub-graph determined by the maximum degree can ensure that the target knowledge graph obtained subsequently includes all paths that meet the maximum degree; splice the first sub-graph and the second sub-graph to obtain the target knowledge graph, and realize the fusion of knowledge graphs across graph databases, and by splicing the first sub-graph and the second sub-graph, there is no need to fuse all knowledge graphs across graph databases, thereby reducing the amount of data loaded and calculated in the subsequent target knowledge graph and improving the calculation efficiency of the shortest path; determine the shortest path according to the target knowledge graph and the maximum degree, and realize the calculation of the shortest path of the knowledge graph in the cross-graph database. Therefore, the technical solution of the present application solves the problem of being unable to implement the shortest path calculation across graph databases, thereby achieving the effect of implementing the shortest path calculation across graph databases.
[0102] Optionally, the sub-atlas acquisition module 430 includes:
[0103] A first sub-graph acquisition unit is used to take the maximum degree as the first sub-degree, expand the first sub-degree along the out-degree edge with the starting node as the center in the knowledge graph to which the starting node belongs, and acquire the first sub-graph;
[0104] The second sub-graph acquisition unit is used to take the maximum degree as the second sub-degree, expand the second sub-degree along the in-degree edge with the termination node as the center in the knowledge graph to which the termination node belongs, and acquire the second sub-graph.
[0105] Optionally, the sub-map splicing module 440 includes:
[0106] An equivalent node determination unit, used to determine equivalent nodes in the first sub-graph and the second sub-graph;
[0107] The target knowledge graph determination unit is used to splice the first sub-graph and the second sub-graph according to equivalent nodes to obtain the target knowledge graph.
[0108] Optionally, the equivalent node determination unit includes:
[0109] A standard format conversion subunit, used for converting the first sub-map and the second sub-map into a standard format to obtain a first standard sub-map and a second standard sub-map;
[0110] An equivalent entity determination subunit, used to determine whether there are equivalent entities in the first standard sub-graph and the second standard sub-graph;
[0111] The equivalent node determination subunit is used to take the node corresponding to the equivalent entity as the equivalent node if it exists.
[0112] Optional, equivalent entity judgment subunit, specifically used for:
[0113] Traverse each entity in the first standard sub-graph, and determine whether there is an equivalent entity in the second standard sub-graph by integrating the equivalent entity table in the database.
[0114] Optionally, the target knowledge graph determination unit includes:
[0115] The equivalent node merging subunit is used to merge the equivalent nodes in the first subgraph and the second subgraph to obtain the target knowledge graph.
[0116] The cross-graph database shortest path calculation device provided in the embodiment of the present application can execute the cross-graph database shortest path calculation method provided in any embodiment of the present application, and has the corresponding functional modules and beneficial effects for executing the cross-graph database shortest path calculation method.
[0117] According to an embodiment of the present invention, the present invention also provides an electronic device, a readable storage medium and a computer program product.
[0118] Embodiment 5
[0119] Figure 5 A schematic diagram of the structure of an electronic device provided in Embodiment 5 of the present application is shown in FIG. Figure 5 As shown, the electronic device includes a processor 510, a memory 520, an input device 530, and an output device 540; the number of the processor 510 in the electronic device can be one or more. Figure 5 A processor 510 is taken as an example; the processor 510, the memory 520, the input device 530 and the output device 540 in the electronic device can be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.
[0120] The memory 520, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as the program instructions / modules corresponding to the shortest path calculation method across the graph database in the embodiment of the present application (for example, the shortest path request acquisition module 410, the node position judgment module 420, the sub-graph acquisition module 430, the sub-graph splicing module 440 and the shortest path determination module 450). The processor 510 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 520, that is, realizing the above-mentioned shortest path calculation method across the graph database.
[0121] The memory 520 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 520 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 520 may further include a memory remotely arranged relative to the processor 510, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0122] The input device 530 may be used to receive input character information and generate key signal input related to user settings and function control of the electronic device. The output device 540 may include a display device such as a display screen.
[0123] Embodiment 6
[0124] Embodiment 6 of the present application also provides a storage medium containing computer executable instructions, which, when executed by a computer processor, are used to execute a method for calculating the shortest path across a graph database, the method comprising: obtaining a user's shortest path request; the shortest path request comprises a starting node, a knowledge graph to which the starting node belongs, an ending node, a knowledge graph to which the ending node belongs, and a maximum degree; determining whether the knowledge graph to which the starting node belongs and the knowledge graph to which the ending node belongs are stored in the same graph database; if not, obtaining a first subgraph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtaining a second subgraph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree; concatenating the first subgraph and the second subgraph to obtain a target knowledge graph; and determining the shortest path according to the target knowledge graph and the maximum degree.
[0125] Of course, the storage medium containing computer executable instructions provided in an embodiment of the present application is not limited to the method operations described above, and the computer executable instructions can also execute related operations in the shortest path calculation method across graph databases provided in any embodiment of the present application.
[0126] Through the above description of the implementation method, the technicians in the relevant field can clearly understand that the present application can be implemented with the help of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application can be essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for an electronic device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0127] It is worth noting that in the above-mentioned embodiment of the shortest path calculation device across the graph database, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application.
[0128] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A method for calculating the shortest path across a graph database, characterized in that: include: Get the shortest path request from the user; The shortest path request includes a starting node, a knowledge graph to which the starting node belongs, an ending node, a knowledge graph to which the ending node belongs, and a maximum degree; Determine whether the knowledge graph to which the start node belongs and the knowledge graph to which the end node belongs are stored in the same graph database; If not, obtain the first subgraph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtain the second subgraph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree; Concatenate the first sub-graph and the second sub-graph to obtain a target knowledge graph; The shortest path is determined according to the target knowledge graph and the maximum degree.
2. The method according to claim 1, characterized in that: The step of obtaining a first subgraph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and obtaining a second subgraph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree, includes: Taking the maximum degree as the first sub-degree, in the knowledge graph to which the starting node belongs, expanding the first sub-degree along the out-degree edge with the starting node as the center, to obtain a first sub-graph; Taking the maximum degree as the second sub-degree, in the knowledge graph to which the termination node belongs, the second sub-degree is expanded along the in-degree edge with the termination node as the center to obtain the second sub-graph.
3. The method according to claim 1, characterized in that The step of splicing the first sub-graph and the second sub-graph to obtain a target knowledge graph includes: Determining equivalent nodes in the first sub-graph and the second sub-graph; According to the equivalent nodes, the first sub-graph and the second sub-graph are spliced to obtain a target knowledge graph.
4. The method according to claim 3, characterized in that: The determining of equivalent nodes in the first sub-graph and the second sub-graph includes: Converting the first sub-map and the second sub-map into a standard format to obtain a first standard sub-map and a second standard sub-map; Determining whether there are equivalent entities in the first standard sub-graph and the second standard sub-graph; If so, the node corresponding to the equivalent entity is taken as the equivalent node.
5. The method according to claim 4, characterized in that The determining whether there are equivalent entities in the first standard sub-graph and the second standard sub-graph includes: Each entity in the first standard sub-graph is traversed, and whether an equivalent entity exists in the second standard sub-graph is determined by integrating an equivalent entity table in a database.
6. The method according to claim 3, characterized in that The step of concatenating the first sub-graph and the second sub-graph according to the equivalent nodes to obtain a target knowledge graph includes: The equivalent nodes in the first sub-graph and the second sub-graph are merged to obtain the target knowledge graph.
7. A device for calculating the shortest path across a graph database, characterized in that: include: The shortest path request acquisition module is used to obtain the shortest path request of the user; The shortest path request includes a starting node, a knowledge graph to which the starting node belongs, an ending node, a knowledge graph to which the ending node belongs, and a maximum degree; A node position determination module, used to determine whether the knowledge graph to which the start node belongs and the knowledge graph to which the end node belongs are stored in the same graph database; A sub-graph acquisition module, for, if not, acquiring a first sub-graph in the knowledge graph to which the starting node belongs according to the starting node and the maximum degree, and acquiring a second sub-graph in the knowledge graph to which the ending node belongs according to the ending node and the maximum degree; A sub-graph splicing module, used for splicing the first sub-graph and the second sub-graph to obtain a target knowledge graph; The shortest path determination module is used to determine the shortest path according to the target knowledge graph and the maximum degree.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the shortest path calculation method across a graph database is implemented as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the shortest path calculation method across a graph database as described in any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the computer program implements the method for calculating the shortest path across a graph database according to any one of claims 1 to 6.
Citation Information
Cited By
Treatment method
CN121168596A