Method and device for acquiring isomorphic subgraph, computer device and readable storage medium
By combining the query order of breadth-first search and depth-first search, along with node neighbor matching and merging operations, the process of obtaining isomorphic subgraphs is optimized, solving the problem of slow query speed in existing technologies and improving efficiency and flexibility.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-26
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, subgraph matching algorithms based on depth-first search take a long time to determine the matching order of each query node in the query graph, resulting in low speed and low efficiency in obtaining isomorphic subgraphs.
By combining breadth-first search and depth-first search when determining the node for the current query in the query graph, and by combining the node's neighbor node matching and merging operations, the query order is optimized and duplicate matching operations are reduced.
It improves the efficiency and flexibility of obtaining isomorphic subgraphs, reduces storage space usage, and optimizes query time.
Smart Images

Figure CN113779085B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet search and mining technology, and in particular to a method, apparatus, computer device and readable storage medium for obtaining isomorphic subgraphs. Background Technology
[0002] Subgraph matching is a graph-based pattern recognition method commonly used in the field of Internet search and mining. It is used to find isomorphic subgraphs of a query graph in a data graph.
[0003] In related technologies, isomorphic subgraphs of the query graph are generally obtained from the data graph based on subgraph matching algorithms. The algorithm framework of this subgraph matching algorithm is depth-first search plus backtracking. After determining the candidate nodes in the data graph corresponding to each query node in the query graph, the various combinations obtained by matching each query node with each candidate node in the query graph are enumerated according to the matching order of each query node. The valid combinations that meet the conditions are determined, thereby obtaining all isomorphic subgraphs of the query graph in the data graph.
[0004] In the process of obtaining isomorphic subgraphs, the matching order of each query node in the query graph and the structure of the data graph and query graph affect the speed of obtaining isomorphic subgraphs. Subgraph matching algorithms in related technologies take a long time to determine the matching order of each query node in the query graph, resulting in low speed of obtaining isomorphic subgraphs, long overall acquisition process, long average time of obtaining isomorphic subgraphs, and low acquisition efficiency. Summary of the Invention
[0005] This application provides a method, apparatus, computer device, and readable storage medium for obtaining isomorphic subgraphs, which can reduce repetitive matching operations during the process of obtaining isomorphic subgraphs and improve the efficiency and flexibility of obtaining isomorphic subgraphs.
[0006] On the one hand, a method for obtaining isomorphic subgraphs is provided, the method comprising:
[0007] Determine the first node of the current query among all nodes in the first query graph;
[0008] In response to the first node satisfying the first condition, at least one matching node of the first node is determined. Satisfying the first condition means that all neighboring nodes of the first node have been identified as matching nodes. The matching node of any node in the first query graph is the node with the same structure corresponding to any node in the first data graph.
[0009] Based on the query order of each node in the first query graph, the matching nodes of the second node are determined sequentially. The second node is the node in the first query graph for which no matching node has been determined.
[0010] In response to the fact that the second node has determined a matching node, the first node is matched with at least one matching node of the first node;
[0011] Based on the matching results, the isomorphic subgraphs of the first query graph in the first data graph are determined.
[0012] In one possible implementation, determining at least one matching node for the first node includes:
[0013] In the first query graph, determine all neighboring nodes of the first node and obtain the matching nodes of each neighboring node; in the first data graph, determine the neighboring nodes of each matching node, and obtain the set of neighboring nodes of any matching node based on the neighboring nodes of any matching node; perform an intersection operation on the set of neighboring nodes of each matching node, and take at least one node included in the intersection operation result as at least one matching node of the first node.
[0014] In one possible implementation, before determining the first node of the current query among the nodes of the first query graph, the following steps are also included:
[0015] Based on the breadth-first search order, starting from the starting node of the first query graph, at least one corresponding node in the first data graph is determined for each node in the first query graph, and the matching results of each node in the first query graph are stored. If, after storing at least one corresponding node in the first data graph for the currently queried node, the storage space occupied by the nodes corresponding to the already matched nodes reaches the storage threshold, then the first node is determined from the already matched nodes in the first query graph. Based on the first node, the matching nodes of each node in the first query graph are determined according to the depth-first search order. Based on the matching results of each node in the first query graph, the isomorphic subgraph of the first query graph in the first data graph is determined.
[0016] In one possible implementation, before determining the first node of the current query among the nodes of the first query graph, the following steps are also included:
[0017] The target nodes in the second query graph are merged, and the first query graph is obtained based on the merging result. The target nodes are multiple nodes in the second query graph that meet the target conditions. Meeting the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label.
[0018] Determining the isomorphic subgraph of the first query graph in the first data graph includes: determining the isomorphic subgraph of the second query graph in the first data graph.
[0019] In one possible implementation, before determining the first node of the current query among the nodes of the first query graph, the following steps are also included:
[0020] The target nodes in the second data graph are merged, and the first data graph is obtained based on the merging result. The target nodes are multiple nodes in the second data graph that meet the target conditions. Meeting the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label.
[0021] Determining the isomorphic subgraph of the first query graph in the first data graph includes: determining the isomorphic subgraph of the first query graph in the second data graph.
[0022] In one possible implementation, the target nodes in the second query graph are merged, and the first query graph is obtained based on the merging result, including:
[0023] Based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph, multiple target nodes in the second query graph are determined; all target nodes are merged, and the first query graph is obtained based on the merging result.
[0024] In one possible implementation, the target nodes in the second query graph are merged, and the first query graph is obtained based on the merging result, including:
[0025] Based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph, multiple target nodes in the second query graph are determined; all leaf nodes in the multiple target nodes are merged, and non-leaf nodes in the multiple target nodes are merged based on the first limiting condition; the first query graph is determined based on the merging results.
[0026] In one possible implementation, the target nodes in the second data graph are merged, and the first data graph is obtained based on the merging result, including:
[0027] Based on the labels of each node in the second data graph and the connection relationships between each node in the second data graph, multiple target nodes in the second data graph are determined; the target nodes are merged based on the second limiting condition, and the first data graph is determined based on the merging result.
[0028] On the one hand, an apparatus for obtaining isomorphic subgraphs is provided, the apparatus comprising:
[0029] The first determining module is used to determine the first node of the current query among the nodes of the first query graph;
[0030] The second determining module is used to determine at least one matching node of the first node in response to the first node satisfying the first condition. Satisfying the first condition means that all neighboring nodes of the first node have been determined to have matching nodes. The matching node of any node in the first query graph means that any node has a node with the same structure in the first data graph.
[0031] The third determining module is used to determine the matching nodes of the second node in sequence based on the query order of each node in the first query graph. The second node is a node in the first query graph for which no matching node has been determined.
[0032] The matching module is used to match the first node with at least one matching node of the first node in response to the fact that the second node has determined matching nodes;
[0033] The subgraph determination module is used to determine isomorphic subgraphs of the first query graph in the first data graph based on the matching results.
[0034] In one possible implementation, the second determining module is used to determine all neighboring nodes of the first node in the first query graph and obtain the matching nodes of each neighboring node; determine the neighboring nodes of each matching node in the first data graph, and obtain the set of neighboring nodes of any matching node based on the neighboring nodes of any matching node; perform an intersection operation on the set of neighboring nodes of each matching node, and take at least one node included in the intersection operation result as at least one matching node of the first node.
[0035] In one possible implementation, the device further includes: a switching module, configured to, based on a breadth-first search order, sequentially determine at least one node in the first data graph corresponding to each node in the first query graph, starting from the starting node of the first query graph, and store the matching results of each node in the first query graph; if, after storing at least one node corresponding to the currently queried node in the first data graph, the storage space occupied by the nodes corresponding to each matched node reaches a storage threshold, then, among the nodes already matched in the first query graph, determine a first node; based on the first node, determine the matching nodes of each node in the first query graph according to a depth-first search order; and based on the matching results of each node in the first query graph, determine the isomorphic subgraph of the first query graph in the first data graph.
[0036] In one possible implementation, the device further includes: a first merging module, used to merge target nodes in the second query graph, and obtain a first query graph based on the merging result, wherein the target nodes are multiple nodes in the second query graph that satisfy the target conditions, and satisfying the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label; and a subgraph determination module, used to determine isomorphic subgraphs of the second query graph in the first data graph.
[0037] In one possible implementation, the device further includes: a second merging module, used to merge target nodes in the second data graph and obtain a first data graph based on the merging result, wherein the target nodes are multiple nodes in the second data graph that satisfy the target conditions, which means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label; and a subgraph determination module, used to determine isomorphic subgraphs of the first query graph in the second data graph.
[0038] In one possible implementation, the first merging module is used to determine multiple target nodes in the second query graph based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph; merge all target nodes, and obtain the first query graph based on the merging result.
[0039] In one possible implementation, the first merging module is used to determine multiple target nodes in the second query graph based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph; merge all leaf nodes in the multiple target nodes, and merge non-leaf nodes in the multiple target nodes based on a first limiting condition; and determine the first query graph based on the merging result.
[0040] In one possible implementation, the second merging module is used to determine multiple target nodes in the second data graph based on the labels of each node in the second data graph and the connection relationships between each node in the second data graph; merge the target nodes based on the second limiting conditions; and determine the first data graph based on the merging result.
[0041] On the other hand, a computer device is provided, the electronic device including a processor and a memory, the memory storing at least one program code or instruction, the at least one program code or instruction being loaded and executed by the processor to enable the computer device to implement any of the above-described methods for obtaining isomorphic subgraphs.
[0042] On the other hand, a computer-readable storage medium is provided that stores at least one piece of program code or instruction, which is loaded and executed by a processor to enable a computer to implement any of the above methods for obtaining isomorphic subgraphs.
[0043] On the other hand, a computer program or computer program product is provided, which stores at least one computer instruction, which is loaded and executed by a processor to enable the computer to implement any of the above methods for obtaining isomorphic subgraphs.
[0044] The technical solution provided in this application further determines the query matching method for the first data graph for the first node that meets the first condition in the first query graph. A better query order can be selected to reduce repeated matching operations and improve the efficiency and flexibility of obtaining isomorphic subgraphs. Attached Figure Description
[0045] Figure 1 A schematic diagram of a query graph provided in an embodiment of this application;
[0046] Figure 2 A flowchart illustrating a method for obtaining isomorphic subgraphs provided in this application embodiment;
[0047] Figure 3 A schematic diagram of a data graph provided in an embodiment of this application;
[0048] Figure 4 A schematic diagram of a merged query graph provided in an embodiment of this application;
[0049] Figure 5 A schematic diagram of another query diagram provided for an embodiment of this application;
[0050] Figure 6 A schematic diagram of an apparatus for obtaining isomorphic subgraphs provided in an embodiment of this application;
[0051] Figure 7 A schematic diagram of an apparatus for obtaining isomorphic subgraphs provided in an embodiment of this application;
[0052] Figure 8 This is a schematic diagram of a computer device provided in an embodiment of this application. Detailed Implementation
[0053] To enable those skilled in the art to better understand the technical methods in this application, some embodiments of this application will be described below with reference to the accompanying drawings. It should be understood that, unless otherwise defined, all technical terms used in the embodiments of this application have the same meaning as commonly understood by those skilled in the art, and are used only to explain the embodiments of this application, and are not intended to limit this application.
[0054] To better understand the methods provided in the embodiments of this application, some definitions involved in the relevant content of this application will be introduced first.
[0055] Definition 1. Graph: A graph can be represented as G = {V, E, L}, where V is the set of all nodes. L is the set of all undirected edges, and L is a function that assigns labels to nodes and / or edges.
[0056] For example, see Figure 1 , Figure 1The query graph in the diagram has 5 nodes, some of which are connected by lines (edges). "A, B, C" represent the labels, or attributes, of each node, indicating its properties. "u0, u1, u2, u3, u4" represent the identifiers of each node; for example, a node's identifier can be its name, used to uniquely identify the node.
[0057] Definition 2, Subgraph: Given a graph G = {V, E, L}, a subgraph of G can be represented as G′ = {V′, E′, L′}, where the vertex set V′ and the edge set E′ are subsets of V and E, respectively. and Furthermore, for the label function,
[0058] Definition 3, Derived Subgraph: Given a graph G = {V, E, L}, G′ is a derived subgraph of G if and only if: according to the definition of a subgraph, G′ is a subgraph of G; Where v1 and v2 are nodes of graph G. Indicates the edge between nodes v1 and v2.
[0059] Definition 4. Graph Isomorphism: Given two graphs H and G, H and G are isomorphic if and only if:
[0060] There exists a bijective function f (denoted as f: V(H)→V(G)) between the point sets H and G, such that:
[0061] · f(u)∈V(G) and L H (u)=L G (f(u))
[0062] · And when there is a label on the side
[0063] · And when there is a label on the side
[0064] Definition 5. Subgraph Isomorphism Search Problem: Given a query graph Q and a data graph G, the subgraph isomorphism search problem aims to find all subgraphs G′ in G that are isomorphic to Q. That is, to find at least one isomorphic subgraph G′ of the query graph Q in the data graph G. Here, G′ can be called a match of Q.
[0065] This application provides a method for obtaining isomorphic subgraphs, which is applied to determine the various isomorphic subgraphs of a query graph in a data graph. See also Figure 2The method for obtaining isomorphic subgraphs disclosed in this application includes, but is not limited to, the following steps 201-205.
[0066] Step 201: Determine the first node of the current query among all nodes in the first query graph.
[0067] Based on the above definition of a graph, it can be seen that the first query graph includes multiple nodes and multiple edges for connecting the nodes. The process of obtaining a isomorphic subgraph of the first query graph in this embodiment includes: determining the matching nodes corresponding to each node of the first query graph in the first data graph; and determining the isomorphic subgraph of the first query graph in the first data graph based on the matching nodes of each node of the first query graph. Here, a matching node of any node in the first query graph refers to a node with the same structure as that node in the first data graph. For example, the same structure indicates that any node in the first query graph and its corresponding matching node have the same label, and the number and labels of all neighboring nodes connected by the edges of any node in the first query graph are also the same as the number and labels of all neighboring nodes connected to the matching node in the first data graph.
[0068] In this step, the first node of the current query in the first query graph is determined based on the depth-first search order, and then steps 202-205 are executed. In one possible implementation, before step 201, the first query graph is queried based on a breadth-first search order. This breadth-first search order indicates that the query in the first query graph starts from the root node and proceeds according to the node hierarchy. That is, after querying all nodes at the same level, the next level of nodes is queried, and the matching results are stored during the query process. Therefore, during the breadth-first search matching process, the memory usage of the node matching results continuously increases. In this possible implementation, the process of obtaining the isomorphic subgraph includes:
[0069] Based on the breadth-first search order, starting from the starting node of the first query graph, at least one corresponding node in the first data graph is determined for each node in the first query graph, and the matching results of each node in the first query graph are stored. If, after storing at least one corresponding node in the first data graph for the currently queried node, the storage space occupied by the nodes corresponding to the already matched nodes reaches the storage threshold, then a first node is determined from the already matched nodes in the first query graph. Based on this first node, matching nodes for each node in the first query graph are determined according to the depth-first search order. Based on the matching results of each node in the first query graph, the isomorphic subgraph of the first query graph in the first data graph is determined. The process of obtaining the isomorphic subgraph is described in steps 2011-2014 below.
[0070] Step 2011: Based on the breadth-first search order, starting from the starting node of the first query graph, determine at least one node in the first data graph corresponding to each node in the first query graph in sequence, and store the matching results of each node in the first query graph.
[0071] A starting node is determined among the nodes in the first query graph. This embodiment of the application does not limit the method of determining the starting node; it can be determined based on the logic of the algorithm used. Once the node to be queried in the first query graph is determined, at least one node corresponding to the queried node is determined in the first data graph. During this process, the matching results of the queried node in the first query graph are stored in memory. The node in the first data graph corresponding to the queried node in the first query graph refers to a node in the first data graph that has the same label as the queried node.
[0072] In one possible implementation, prior to step 2011, the method further includes: estimating the size of the search space during the acquisition of the isomorphic subgraph based on the first query graph and the first data graph; and performing step 2011 if the size of the search space is smaller than the memory size. Here, the search space refers to the size of the space occupied by the matching results of each node in the first query graph under the width-first search order.
[0073] Step 2012: If the storage space occupied by the nodes corresponding to the currently queried node in the first data graph reaches the storage threshold after storing at least one node corresponding to each matched node, then determine the first node among the matched nodes in the first query graph.
[0074] In this possible implementation, nodes are queried and matched in the first query graph, and the matching results are continuously stored. As more nodes in the first query graph are queried and matched, the memory space occupied by the matching results continuously increases. In one possible implementation, if the memory storage space reaches a storage threshold after storing the matching results of at least one node corresponding to the currently queried node in the first data graph, then the first node to be matched is determined from the already matched nodes in the first query graph. The storage threshold is used to limit the maximum amount of data stored in memory. Optionally, the storage threshold is the actual size of the memory storage space, or it can be a maximum amount of data allowed to be stored in memory, set empirically.
[0075] Step 2013: Based on the first node, determine the matching nodes of each node in the first query graph according to the depth-first search order.
[0076] In this step, given the significant memory usage, a first node is determined. Based on this first node, matching nodes for each node in the first query graph are determined according to a depth-first search order. This determination process can be referred to steps 202-205 below.
[0077] Step 2014: Based on the matching results of each node, determine the isomorphic subgraph of the first query graph in the first data graph.
[0078] In one possible implementation, during the depth-first search process, memory is continuously released, and when the current storage space falls below the aforementioned storage threshold, the search can be reverted to a breadth-first search. This possible implementation alternates between breadth-first and depth-first search orders during the acquisition of isomorphic subgraphs.
[0079] In practical applications, the storage device for the nodes of the first query graph corresponding to the nodes in the first data graph can be the L3 memory in the computer's central processing unit. In practical applications, various algorithms exist to implement breadth-first search or depth-first search; this application does not limit the specific form of the algorithm.
[0080] In one possible implementation, prior to this step, based on the labels of each node in the first query graph and the labels of each node in the first data graph, at least one candidate node corresponding to any node in the first query graph is determined in the first data graph. This candidate node refers to a node in the first data graph that has the same label as any node in the first query graph. The at least one candidate node of any node in the first query graph constitutes a candidate set for that node. In this possible implementation, the determination of matching nodes for each node in the first query graph within the first data graph can be based on the candidate set corresponding to that node. During the process of obtaining the isomorphic subgraph, the candidate nodes of each node can be updated based on the matching status of other nodes.
[0081] In one possible implementation, prior to step 201, a first query graph is first determined based on a second query graph, and / or a first data graph is determined based on a second data graph. If a second query graph exists, the final determined graph is an isomorphic subgraph of the second query graph.
[0082] Based on this, before step 201, the method further includes: merging the target nodes in the second query graph, and obtaining a first data graph based on the merging result. Here, a target node refers to multiple nodes in the second query graph that satisfy the target conditions; satisfying the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label. In this possible approach, the isomorphic subgraph of the second query graph in the first data graph is finally determined.
[0083] Before step 201, the process also includes: obtaining a first data graph based on the merging results for the target nodes in the second data graph. Here, a target node refers to multiple nodes in the second data graph that satisfy the target conditions; satisfying the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label. In this possible approach, the isomorphic subgraph of the first query graph in the second data graph is finally determined.
[0084] In one possible approach, before step 201, the target nodes in the second query graph and the second data graph are merged respectively, and the final determined graph is the isomorphic subgraph of the second query graph in the second data graph.
[0085] Before step 201, during the process of obtaining the first query graph, multiple target nodes in the second query graph are determined based on the labels of each node in the second query graph and the connection relationships between each node.
[0086] In one possible implementation, all target nodes are merged, and a first query graph is obtained based on the merging result. Based on multiple nodes in the second query graph, in one possible implementation, there are multiple groups of similar nodes with different labels. For example, nodes 1, 2, and 5 in the second query graph are labeled A, and each of these three nodes is connected to a node labeled 3. The second query graph also contains nodes 11, 12, and 16 labeled B, and the labels of their connection points are the same. Therefore, in the first query graph, nodes 1, 2, and 5 are similar nodes to each other, and nodes 11, 12, and 16 are similar nodes to each other. During the merging process, these similar nodes with different labels are merged separately.
[0087] In one possible implementation, the second query graph is a tree graph. Based on the properties of a tree graph, each node in the second query graph can be divided into leaf nodes and non-leaf nodes. Therefore, the target node in the second query graph may simultaneously contain both leaf nodes and non-leaf nodes. Thus, all leaf nodes in the target node are merged, and the non-leaf nodes in the target node are merged based on the first limiting condition. For example, the first limiting condition is as follows:
[0088] Let SU denote the set of target nodes to be merged, and |SU| denote the number of target nodes in SU. Based on the properties of target nodes, target nodes are either unconnected by edges or form a clique. If SU is a clique, then the more nodes there are, the stronger the pruning ability. The decision to merge target nodes is based on the following formulas 1 and 2. A clique is composed of multiple nodes where all nodes are paired.
[0089]
[0090] Turbo(SU)=|C(SU)| |SU|1-2IsClique(SU) (Formula 2)
[0091] Where C(SU) indicates the size of the candidate set, |SU| indicates the number of target nodes, and IsClique(SU) indicates whether the target nodes form a clique. C(SU) represents the candidate set of nodes in the SU. "if SU forms a clique" means "if the target nodes form a clique," then IsClique(SU) is 1; "otherwise" means "otherwise," that is, if the target nodes do not form a clique, then IsClique(SU) is 0. The value of Turbo(SU) is used to determine whether to perform a merge process; it can be called the first merge value. The smaller the final calculated Turbo(SU) value, the more likely the SU should be merged.
[0092] In one possible implementation, in the second query graph, the target node is a similar node that satisfies the target condition, and the node obtained after merging is called a virtual node.
[0093] Before step 201, during the process of obtaining the first data graph, multiple target nodes in the second data graph are determined based on the labels of each node and the connection relationships between each node; the target nodes are then merged based on a second constraint, and the first data graph is obtained based on the merging result. The second constraint is as follows:
[0094]
[0095] Where SV represents the set of similar nodes to be merged, |SV| indicates the number of target nodes, and d(SV) represents the reading of nodes in SV; IsClique(SV) indicates whether the target nodes are clustered. The determination of the value of IsClique(SV) is similar to that in Formula 1 above, taking a value of 1 if similar nodes are clustered, and 0 otherwise. Based on the above formula, the value of Boost(SV) is used to determine whether to perform the merge process, and can be called the second merge value. The larger the value of Boost(SV), the more likely SV should be merged.
[0096] In this possible implementation, when the SV set is clique, the number of edges that can be saved is:
[0097] (|SV|-1)×[d(SV)-|SV|+1]+|SV|×(|SV|-1) / 2=(|SV|-1)[d(SV)+0.5-0.5|SV|] (Formula 4)
[0098] In one possible implementation, when the nodes in the SV set are not cliques, i.e. there are no edges between the nodes, the number of edges saved is (|SV|-1)×d(SV).
[0099] In one possible implementation, in the second data graph, the target node is an equivalent node that satisfies the target condition, and the node obtained after merging is called a super node.
[0100] In one possible implementation, before performing a query, the nodes of the second query graph are merged, thus determining the isomorphic subgraph of the second query graph in the first data graph; in another possible implementation, before performing a query, the nodes of the second data graph are merged, thus determining the isomorphic subgraph of the first query graph in the second data graph; in yet another possible implementation, before performing a query, the nodes of the second query graph and the second data graph are merged, thus determining the isomorphic subgraph of the second query graph in the second data graph.
[0101] Step 202: In response to the first node satisfying the first condition, determine at least one matching node of the first node. Satisfying the first condition means that all neighboring nodes of the first node have been matched. The matching node of any node in the first query graph is the node with the same structure corresponding to that node in the first data graph.
[0102] In one possible implementation, if there are nodes that have already been matched and whose matching nodes have been determined before the first node, then starting from the initial matching step, nodes in the first query graph are paired with matching nodes to form matching pairs, and multiple matching pairs constitute a matching set. The matching set can be set when the first query graph has not been queried, and is set to an empty set.
[0103] Based on the first node determined in step 201, step 202 determines whether the first node satisfies the first condition. The first node that satisfies the first condition can be called a complete node. Satisfying the first condition means that all neighboring nodes of the first node have already determined corresponding matching nodes; that is, all neighboring nodes of the first node have completed matching before the first node. In one possible implementation, if there are nodes that have already been matched before the first node, and a matching set is set, then satisfying the first condition means that all neighboring nodes of the first node belong to this matching set.
[0104] For example, see Figure 1 Given a query graph, the query is performed in a depth-first search order, that is, each node in the query graph is queried according to u0, u1, u3, u4, u2. The current query node is u2, and the neighbor nodes of this node are u0 and u1. Based on the query order, it can be determined that all the neighbor nodes of this node have been matched and the corresponding matching nodes have been determined. Therefore, this node u2 satisfies the first condition and can be called a complete node.
[0105] In one possible implementation, in response to the first node satisfying the first condition, the method of determining at least one matching node of the first node may include: determining all neighboring nodes of the first node in a first query graph and obtaining the matching nodes of each neighboring node; determining the neighboring nodes of each matching node based on a first data graph; obtaining a set of neighboring nodes of any matching node based on the neighboring nodes of any matching node; performing an intersection operation on the set of neighboring nodes of each matching node, and taking at least one node included in the intersection operation result as at least one matching node of the first node.
[0106] For example, see Figure 1 If u2 is determined to be the first node satisfying the first condition, i.e., a complete node, then in this method, the determination of at least one matching node for node u2 is based on the matching nodes of u2's neighboring nodes u0 and u1; see [link to relevant documentation]. Figure 3 Given a data graph G, the matching nodes corresponding to nodes u0 and u1 are v0 and v1, respectively. 100 .
[0107] Based on the data graph G, the set of neighbor nodes {v1, v2, v3, v4, v5} formed by the neighbor nodes of v0. 100 v 202}, v 100 The set of neighboring nodes formed by the neighboring nodes {v0, v... 200 v 201 v 202}, perform an intersection operation on the sets of neighboring nodes of two matched nodes to obtain the intersection result {v 202 The result of the intersection operation includes nodes v. 202 As the matching node for node u2.
[0108] In one possible implementation, if the first node does not satisfy the first condition, a candidate set corresponding to the first node is determined, and a node that satisfies the matching condition in the candidate set is identified as a matching node of the first node. Satisfying the matching condition means that the connection relationship between the first node and the nodes that have already been matched in the first query graph (the edge between the first node and the nodes that have already been matched) exists in the connection relationship between the matching node and the nodes that have been identified as matching nodes in the first data graph (the edge between the matching node and other matching nodes).
[0109] Step 203: Based on the query order of each node in the first query graph, determine the matching node of the second node in sequence. The second node is the node in the first query graph whose matching node has not been determined.
[0110] After determining at least one matching node for the first node, the next node to be queried in the first query graph is determined according to the query order of the depth-optimal search. If the first node does not meet the first condition, a matching node for that node is determined based on its candidate set. This determination process can refer to the description of this case in step 203 above, and then the next node to be queried is determined.
[0111] Therefore, in this step, the second node in the first query graph that has not yet been matched is determined according to the query order of the depth-optimal search, and the number of such second nodes is at least one.
[0112] In one possible implementation, during the process of determining the matching nodes of the second node in sequence, if there is a second node that satisfies the first condition, at least one matching node of the second node is determined based on the method in step 202; then the matching nodes of the subsequent unmatched second nodes are determined based on the method in step 203.
[0113] In one possible implementation, before determining a second node, it is necessary to determine whether all nodes in the first query graph have been queried. If so, the second node is not determined, and step 204 is executed to obtain the isomorphic subgraph; otherwise, the second node is determined, and then the matching node of the second node is determined. An exemplary method for determining whether all nodes in the first query graph have been queried includes: if a matching set exists, determining whether the number of matching pairs in the matching set is the same as the number of nodes in the first data graph; if they are the same, then all nodes in the first query graph have been queried; otherwise, the second node is determined.
[0114] Step 204: In response to the fact that the second node has determined a matching node, match the first node with at least one matching node of the first node.
[0115] In this step, each node of the first query graph is matched with a node of the first data graph, and all nodes except the first node have a matching node. Then, the first node is matched with at least one of its matching nodes. In one implementation, at least one matching node of the first node forms a set, and step 204 involves expanding the set so that the first node is matched with each node in the set.
[0116] Step 205: Based on the matching results, determine the isomorphic subgraph of the first query graph in the first data graph.
[0117] In the above process, all nodes in the first query graph except the first node have corresponding matching nodes. Based on the matching results of the first node and at least one matching node in step 204 above, at least one isomorphic subgraph of the first query graph in the first data graph is determined.
[0118] In one possible implementation, the first query graph may contain multiple nodes that satisfy the first condition, and each node satisfying the first condition has at least one matching node determined according to step 202. In this possible implementation, each node satisfying the first condition is matched with its corresponding at least one matching node, and then, based on the matching results of each node satisfying the first condition, at least one isomorphic subgraph of the first query graph in the first data graph is determined. Wherein, a node satisfying the first condition may have multiple matching results, and determining at least one isomorphic subgraph of the first query graph in the first data graph based on the matching results of each node satisfying the first condition includes: performing full permutation processing on the matching results of each node satisfying the first condition, enumerating the combinations of matching results, and obtaining at least one isomorphic subgraph of the first query graph in the first data graph.
[0119] It should be noted that the order of the above implementation steps is an illustration of the method for obtaining isomorphic subgraphs provided in the embodiments of this application, and does not limit various possible implementation methods. In practical applications, the above various possible implementation methods can be combined based on the actual situation. In one possible implementation method, after merging the query graph and / or data graph, during the query process, it is not necessary to judge whether the first node of the current query meets the first condition, but to directly match according to the method that the first node does not meet the first condition.
[0120] The method for obtaining isomorphic subgraphs provided in this application determines the query matching method for the first data graph by judging the conditions satisfied by the first node of the current query. This allows for the selection of a better query order, reducing redundant matching operations and improving the efficiency and flexibility of the method. Furthermore, it allows for merging nodes in the query graph and the data graph, simplifying the number of nodes in both graphs, improving the efficiency of the isomorphic subgraph acquisition method, and reducing query time. It also allows for the mixed use of various query search orders, optimizing storage space utilization and further enhancing the flexibility of the method.
[0121] To better understand the method for obtaining isomorphic subgraphs provided in the embodiments of this application, the method for obtaining isomorphic subgraphs is described based on the above embodiments.
[0122] In an exemplary embodiment, based on Figure 1 In the query graph Q, Figure 3 The data graph G in the figure describes a traditional method for obtaining isomorphic subgraphs based on depth-first search order, which includes the following steps 301 to 329.
[0123] Step 301: Set up a matching set to store the matches determined during the query process. This matching set is denoted as M, and M is initialized as an empty set.
[0124] Step 302: In the data graph G, determine at least one candidate node corresponding to each node in the query graph Q. Based on the obtained candidate nodes, determine the candidate set corresponding to each node in the query graph Q, which is denoted as C(u i ), where u i This is used to identify nodes in the query graph. Nodes in the candidate set and their corresponding nodes in the candidate set have the same label. Nodes in the candidate set are nodes in the data graph, and nodes in the corresponding candidate set are nodes in the query graph.
[0125] For example, the candidate node corresponding to node u0 in the query graph is v in the data graph G. 203 If v0 and v0 are given, then the candidate set of node u0 is C(u0) = {v0, v0}. 203}; then the candidate set corresponding to other nodes in graph Q is:
[0126] C(u1) = {v1, v2, v...} 100}
[0127] C(u2)=C(u3)=C(u4)={v 101 v 102 v 200 v 201 v 202}
[0128] Step 303: Compare the number of matching pairs in the matching set M with the number of nodes in the query graph. If the numbers are equal, output the matching pairs in the matching set to obtain an isomorphic subgraph of the query graph; otherwise, continue executing the search and matching steps. Here, the number of matching pairs in the matching set is denoted as |M|, and the number of nodes in the query graph is denoted as |V(Q)|.
[0129] For example, in this embodiment, the search and matching step has not yet been performed. The number of matches in the matching set M is 0, and the number of nodes in the query graph Q is 5. Since the numbers are different, the subsequent search and matching steps will continue.
[0130] Step 304: Determine the first query node of the current query in the query graph, update the candidate set corresponding to the first query node, and obtain the updated candidate set, which can be represented as C. R (u i ).
[0131] For example, after the candidate set of the first query node u0 is updated, the candidate nodes corresponding to the first query node u0 remain unchanged, and the content of the updated candidate set is the same as before the update, i.e., C. R (u0)=C(u0)={v0,v 203}
[0132] Step 305: Traverse the updated candidate set of the first query node u0 and determine one of the matching nodes.
[0133] For example, in this embodiment of the application, v0 is first determined as the matching node of u0.
[0134] Step 306: Based on the first query node and its matching node, a matching pair is obtained. This matching pair is then added to the matching set to obtain the updated matching set.
[0135] For example, if the matching node of u0 is determined to be v0, a matching pair (u0, v0) is obtained; if this matching pair is added to the matching set, the updated matching set is: M = {(u0, v0)}.
[0136] Step 307: Compare the number of matching pairs in the matching set with the number of nodes in the query graph to determine the next steps to be performed.
[0137] In this exemplary embodiment, at this time |M|=1, |V(Q)|=5, the number of matching pairs in the matching set is not the same as the number of nodes in the query graph, so the search matching operation continues.
[0138] Step 308: Determine the second query node in the data graph according to the matching order, update the candidate set corresponding to the second query node, and obtain the updated candidate set.
[0139] In this exemplary embodiment, the second query node is determined to be a neighbor node u1 that is directly connected to the first query node u0. The candidate set originally corresponding to u1 is: C(u1) = {v1, v2, v...} 100 Based on the above steps, given that v0 is determined, the candidate set of u1 will not change. Therefore, the candidate set updated by the second query node is consistent with the one before the update, which is C. R (u1)=C(u1)={v1,v2,v 100}
[0140] Step 309: Traverse the updated candidate set of the second query node to determine the matching node corresponding to the second query node. The matching node is the candidate node in the updated candidate set that meets the matching conditions.
[0141] The matching condition is: the edge between the second query node and a node in the query graph whose matching node has already been determined (a node in the query graph that has already been stored in the matching set) also exists between the second query node and a node whose matching node has already been determined (a matching node in the matching set that has already been stored in the partial matching set). This target condition can be expressed as: Here, u and v indicate the query node and subsequent candidate node currently being searched and matched.
[0142] In this embodiment of the application, it is assumed that the first candidate node for searching and matching in the updated candidate set is v. 100 Based on v 100 Matching conditions are met: Then the candidate node v can be determined. 100 The matching node for u1.
[0143] Step 310: Based on the second query node and its matching node, obtain a matching pair, add the matching pair to the matching set, and obtain the updated matching set.
[0144] For example, the matching node corresponding to the second query node u1 is determined to be v. 100 This yields a matching pair (u1, v). 100 Adding this match to the current match set will update the match set to: M = {(u0, v0), (u1, v...} 100 )}.
[0145] Step 311: Determine if the current |M| = 2 and |V(Q)| = 5. Since the number of matches in the matching set is different from the number of nodes in the query graph, continue to perform the search matching operation.
[0146] Step 312: Determine the third query node in the data graph according to the matching order, update the candidate set corresponding to the third query node, and obtain the updated candidate set.
[0147] In this exemplary embodiment, the third query node is determined to be a neighbor node u3 that is directly connected to the second query node u1. The original candidate set of u3 is: C(u3) = {v 101 v 102 v 200 v 201 v 202 Based on the above steps, the matching node for the second query node u1 was determined to be v. 100 Based on the data graph G, u3 will not match the candidate node v. 101 and v 102 The updated candidate set is then C. R (u3)={v 200 v 201 v 202}
[0148] Step 313: Determine the matching node for the third query node u3 in the updated candidate set. Assume that the first candidate node to be searched and matched in this step is v. 200 v 200 Meets matching conditions Then the matching node for the third query node u3 is determined to be v. 200 .
[0149] Step 314: Based on the third query node u3 and the matching node v 200 This forms a new matching pair (u3, v). 200 If the matching pair is added to the current matching set M, then the updated partial matching set is: M = {(u0, v0), (u1, v...} 100 ), (u3, v 200 )}.
[0150] Step 315: Determine if the current |M| = 3 and |V(Q)| = 5. Since the number of matches in the matching set is different from the number of nodes in the query graph, continue to perform the search matching operation.
[0151] Step 316: Determine the fourth query node u4. Based on the above matching process, determine the updated candidate set corresponding to u4 as C. R (u4)={v 201 v 202}
[0152] Step 317: Assume the first candidate node for the current search and matching is v. 201 v 201 Meets matching conditions Therefore, the matching node for the fourth query node u4 is determined to be v. 201 .
[0153] Step 318, based on u4 and v 201 This forms a new matching pair (u4, v) 201 If this match is added to the current matching set, the updated matching set will be: M = {(u0, v0), (u1, v...} 100 ), (u3, v 200 ), (u4, v 201 )}.
[0154] Step 319: Determine that the current |M| = 4 and |V(Q)| = 5, since the quantities are different, and continue to perform the search and matching operation.
[0155] Step 320: Determine the fifth query node u2. Based on the above matching process, determine the updated candidate set corresponding to u2 as C. R (u2)={v 202}
[0156] Step 321, v 202 Meets matching conditions Then the matching node for the fifth query node u2 is determined to be v. 202 .
[0157] Step 322, based on u2 and v 202 This forms a new matching pair (u2, v). 202 If this match is added to the current matching set M, then the updated matching set is: M = {(u0, v0), (u1, c...} 100 ), (u3, v 200 ), (u4, v 201 ), (u2, v 202 )}.
[0158] Step 323: Determine if |M| = 5 and |V(Q)| = 5. At this point, the number of matches in the matching set is the same as the number of nodes in the query graph. Output all matching pairs in M to obtain an isomorphic subgraph of the data graph Q. That is, (u0, v0), (u1, v... 100 ), (u3, v 200 ), (u4, v 201 ), (u2, v 202 ).
[0159] Step 324: Release the matching pair (u4, v) in M 201 ), (u2, v 202 ), backtracking to step 316.
[0160] Step 325: Search the candidate set for v 202 Whether the matching conditions are met, in response to whether the target conditions are met, determine v. 202 For the matching node of the fourth query node u4, generate a new matching pair and update the matching set. The updated matching set is: M = {(u0, v0), (u1, v...} 100 ), (u3, v 200 ), (u4, v 202 )}.
[0161] Step 326: Determine that the current |M| = 4 and |V(Q)| = 5. Since the quantities are different, continue to perform the search and matching operation.
[0162] Step 327: Determine the fifth query node u2. Based on the above matching process, determine the updated candidate set corresponding to u2 as C. R (u2)={v 201 At this time, node v 201 The matching conditions are not met.
[0163] Step 328: Release (u4, v) from M 202 ) and (u3, v 200 ), backtracking to step 312.
[0164] Step 329: Search whether other candidate nodes in the candidate set match the third query node u3, and perform the corresponding search query steps as described above.
[0165] In subsequent processes, search and backtracking queries are continuously executed to enumerate all combinations of matching between each query node and candidate node in the query graph, thereby obtaining all isomorphic subgraphs of the query graph. In this exemplary embodiment, in addition to the isomorphic subgraph obtained in step 323, another isomorphic subgraph will be obtained in subsequent query processes. At this time, the matching pairs output in the matching set are: (u0, v0), (u1, v... 100 ), (u3, v 201 ), (u4, v 200 ), (u2, v 202 ).
[0166] In an exemplary embodiment, the nodes in the query graph Q are merged, and the merged nodes can be referred to as virtual nodes.
[0167] For example, based on the above Figure 1In the query graph Q, where u3 and u4 are similar nodes, merging u3 and u4 yields a virtual node u′, resulting in the following: Figure 4 The updated query graph Q1 shown is then used to obtain the isomorphic subgraph of query graph Q, which may include the following steps 401-420.
[0168] Step 401: Set up a matching set to store the matches determined during the query process. This matching set is denoted as M, and M is initialized as an empty set.
[0169] Step 402: In the data graph G, determine at least one candidate node corresponding to each node in the updated query graph Q1. Based on the obtained candidate nodes, determine the candidate set corresponding to each node, which is denoted as C(u i ), where u i This serves as the identifier for the node.
[0170] For example, the candidate node corresponding to node u0 in the data graph G is v. 203 If v0 and v0 are given, then the candidate set of node u0 is C(u0) = {v0, v0}. 203}; then the candidate set corresponding to other nodes in graph Q is:
[0171] C(u1) = {v1, v2, v...} 100}
[0172] C(u2)=C(u′)={v 101 v 102 v 200 v 201 v 202}
[0173] In this exemplary embodiment, the search and matching process for nodes u0 and u1 includes steps 403-411, which are the same as steps 303-311 in the method described above.
[0174] Step 412: Determine the third query node in the data graph according to the matching order, update the candidate set corresponding to the third query node, and obtain the updated candidate set.
[0175] In this exemplary embodiment, the third query node is determined to be a neighbor node u′ directly connected to the second query node u1, and the original candidate set of u′ is: C(u′)={v 101 v 102 v 200 v 201 v 202 Based on the above steps, the matching node for the second query node u1 was determined to be v. 100 Based on the data graph G, u′ will not match the candidate node v. 101and v 102 The updated candidate set is then C. R (u′)={v 200 v 201 v 202}
[0176] Step 413: Determine the matching node of the third query node u′ in the updated candidate set, and traverse the candidate set C. R Candidate nodes in (u′), v 200 v 201 With v 202 All conditions are met. Based on the fact that the third query node u′ (virtual node) includes query nodes u3 and u4, this step expands to determine the matching pairs of nodes u3 and u4, resulting in the following six possibilities:
[0177] Possible 1: (u3, v) 200 ), (u4, v 201 Possible 2: (u3, v) 200 ), (u4, v 202 );
[0178] Possible 3: (u3, v) 201 ), (u4, v 200 Possible 4: (u3, v) 201 ), (u4, v 202 );
[0179] Possible 5: (u3, v) 202 ), (u4, v 201 Possible 6: (u3, v) 202 ), (u4, v 200 ).
[0180] Assume that possibility 1 is selected for subsequent search and matching operations.
[0181] Step 414: Based on possibility 1, determine the current matching set M as: M = {(u0, v0), (u1, v...} 100 ), (u3, v 200 ), (u4, v 201 )}.
[0182] Step 415: Determine if the current |M| = 4 and |V(Q)| = 5. Since the number of matches in the matching set is different from the number of nodes in the query graph, continue to perform the search and matching operation.
[0183] Step 416: Determine the next query node u2. Based on the above matching process, determine the updated candidate set corresponding to u2 as C. R (u2)={v 202}
[0184] Step 417, v 202 Meets matching conditions Then the matching node for the fifth query node u2 is determined to be v. 202 .
[0185] Step 418, based on u2 and v 202 This forms a new match as (u2, v 202 If this match is added to the current matching set, the updated matching set will be: M = {(u0, v0), (u1, v...} 100 ), (u3, v 200 ), (u4, v 201 ), (u2, v 202 )}.
[0186] Step 419: Determine if |M| = 5 and |V(Q)| = 5. At this point, the number of matches in the matching set is the same as the number of nodes in the query graph. Output all matching pairs in M to obtain an isomorphic subgraph of the data graph Q. That is, (u0, v0), (u1, v... 100 ), (y3, v 200 ), (u4, v 201 ), (u2, v 202 ).
[0187] Step 420: Release the matching pairs (u3, v) in M 200 ), (u4, v 201 ), (u2, v 202 The algorithm then backtracks to step 413, where another possibility is determined, and a search query operation is performed. After all six possibilities have been searched in step 413, the algorithm backtracks to step 410, where the search query node forms a matching search query result with other candidate nodes. During the enumeration of all search results in this step, all isomorphic subgraphs of the query graph are obtained.
[0188] In the exemplary embodiment, nodes in the data graph G are merged, and the merged points are called superpoints. The process of this exemplary embodiment is similar to the process described above, and will not be repeated here.
[0189] In an exemplary embodiment, points in both the query graph Q and the data graph G are merged simultaneously.
[0190] For this improved method, one approach to obtaining isomorphic subgraphs during enumeration is as follows: Assume the current virtual node (the node obtained by merging in the data graph) contains k real nodes, and the currently considered combination is {(h... i n i), 1 < i < m}, where m is the number of different super nodes (nodes obtained by merging in the data graph), and n i is the number of times the super node hi appears in this combination. Then the two processes of enumerating the permutations of the real nodes in the query graph and enumerating the combinations of the real nodes in the super nodes can be merged, and the effect is equivalent to, for any 1 < i < m, taking out n i non-repeated nodes from the set of real nodes of the super node hi and combining them together for full permutation.
[0191] Exemplarily, u1, u2, and u3 in the query graph belong to the same virtual node u′, and there are edges connecting the nodes to each other. Their corresponding candidate sets are h1 and h2. h1 and h2 are super nodes, where h1 contains nodes v1, v2, and h2 contains nodes v3, v4, v5. The corresponding candidate nodes of the virtual node u′ are the super nodes h1 and h2.
[0192] In a possible implementation, determining the matching of the real nodes in the virtual node and the super node is as follows: M s = {(u1, h1), (u2, h1), (u3, h2)}. There is 1 way to take two nodes from {v1, v2}, and there are three ways to take one node from {v3, v4, v5}. And it can be determined that the matching M s of the real nodes in the virtual node and the super node has a total of 3 kinds. Then there are 3! = 6 full permutations. The logic of this method is clear, the process is simple and easy to implement, and the process is efficient.
[0193] In the above exemplary embodiment, the nodes in the query graph and the data graph are merged and processed, simplifying the number of nodes in the query graph and the data graph, improving the efficiency of the method for obtaining isomorphic subgraphs, and reducing the query time.
[0194] In the exemplary embodiment, the first node of the current query satisfies the first condition, and this first node can be called a complete node.
[0195] In this exemplary embodiment, a complete node is defined: Given a query graph Q and a matching order π, let M c represent the set of nodes that have been matched in the query graph. When the first node u (u ∈ Q) is matched, if N(u) is included in M c holds, then the first node is called a complete node, where N(u) represents the set of neighbor nodes of the first node u. That is, the neighbor nodes of the first node currently queried in the query graph have all determined the corresponding matching nodes, forming matching pairs and joining the matching set, then the first node currently queried is called a complete node. In other words, all the edges of the complete node are connected to the matched set.
[0196] For example, in one possible implementation, referring to step 320 of the exemplary embodiment of depth-first search described above, the fifth query node u2 is determined. Based on the search query process in the previous steps, it is known that the neighboring query nodes u0 and u1 connected to u2 have both been determined to have corresponding matches, so the query node u2 is a complete node.
[0197] For example, if the first node satisfies the first condition, in this approach, the determination of the matching node for the complete node can be based on the matching nodes of the neighboring nodes connected to the complete node.
[0198] For example, referring to step 20 in the exemplary embodiment of the depth-first search plus backtracking section above, in which node u2 is determined to be a complete node, the method for determining the matching node of node u2 is based on the matching v0 and v1 of nodes u0 and u1 from u2's neighbor queries. 100 It has been determined.
[0199] Based on the data graph G, the neighbor nodes of v0 form a set {v1, v2, v...} 100 v 202}, v 100 The neighboring nodes form a set {v0, v... 200 v 201 v 202}, taking the intersection of two sets yields node v. 202 That is, determine the matching node of node u2 as v. 202 .
[0200] In this possible implementation, the first node is determined to be a complete node. Based on the above method, at least one matching node of the complete node is determined. The at least one matching node is stored first, and then the search continues to find the second node to be matched in the query graph. After obtaining the matching nodes of all the second nodes, the at least one matching node of the complete node is expanded and matched with the first node to obtain the final isomorphic subgraph.
[0201] For example, based on Figure 5 Given a query graph Q2, the depth-first search method described above is used to perform isomorphic queries in a certain data graph. If node u4 is the first node in the current query, assuming that node u4 is a complete node (i.e., both u1 and u3 have corresponding matching nodes), then the neighboring nodes of the matching nodes corresponding to u1 and u3 determine the matching node of u4.
[0202] In the exemplary embodiment, if multiple corresponding matching nodes are determined based on the intersection operation, then a set C is generated based on at least one matching node of u4. MSave this set, then search and match subsequent query nodes u2 and u5 in sequence. If a matching node for node u2 or u5 is successfully found, then set C... M The nodes in the graph are extended and matched with node u3 to form the final matching pair, and then the isomorphic subgraphs of the data graph are determined.
[0203] In the above exemplary embodiments, by determining the conditions satisfied by the first node of the current query, the query matching method for the first data graph can be further determined, and a better query order can be selected to reduce repeated matching operations and improve the efficiency and flexibility of the method for obtaining isomorphic subgraphs.
[0204] In an exemplary embodiment, breadth-first search and depth-first search are used in combination. See also Figure 1 The query graph Q and Figure 3 The data graph G in this exemplary embodiment. The process includes the following steps 1-5.
[0205] Step 1: Determine the candidate set of each node in the query graph Q. This step is performed in the same way as in the previous embodiment.
[0206] For example, C(u0) = {v0, v...} 203 C(u1) = {v1, v2, v...} 100}
[0207] C(y2)=C(u3)=C(u4)={v 101 v 102 v 200 v 201 v 202}
[0208] Step 2: Based on the determined candidate set of each node, determine the possible matching pairs corresponding to the first query node u0 as (u0, v0) or (u0, v0). 203 The two possible matching pairs mentioned above are stored in memory. This can be done in the form of a table.
[0209] Step 3: Based on the determined candidate set and the possible matching pairs formed in Step 1, determine a matching pair for subsequent node search and matching.
[0210] In one possible implementation, a matching pair (u0, v0) is selected, and the matching pairs that may be generated when the second query node u1 is in the case of (u0, v0) are determined.
[0211] When the matching pair is (u0, v0), the candidate set corresponding to u1 is {v1, v2, v0}. 100 The possible matching pairs formed are: (u0, v1), (u0, v2), and (u0, v3).100 );
[0212] Step 4: At this point, the size of the intermediate table reaches the given memory threshold, indicating excessive memory usage. Therefore, a depth-first search with backtracking is performed on each matching pair in each row of the current intermediate table, searching independently based on each path.
[0213] Step 5: During the depth-first search plus backtracking process, memory space will be continuously released. If the current memory usage is lower than the threshold, the expansion method of the current path will be switched back to the breadth-first search plus backtracking method.
[0214] In the above exemplary embodiments, the combined use of multiple query search orders optimizes the utilization of storage space, improves the flexibility of the method for obtaining isomorphic subgraphs, and expands the applicability of the method.
[0215] In one possible implementation, different datasets are used as query graphs to verify the effectiveness of the method for obtaining isomorphic subgraphs provided in this application. In an exemplary embodiment, the Email and DBLP (Database systems and Logic Programming) datasets are selected. The Email dataset represents a network of email communications, with 36,692 nodes and 183,831 edges, and a maximum degree of 1383. The DBLP dataset represents a literature citation network, with 317,080 nodes and 1,049,866 edges, and a maximum degree of 343. In this exemplary embodiment, both datasets are power-law graphs, and their degree distribution follows a power-law distribution. Table 1 below provides specific information about the two datasets. Table 1 also includes information about other datasets (such as the YeastData Set and the Human (human posture dataset), but these other datasets were not selected for verification experiments due to their smaller size.
[0216] Table 1
[0217] Dataset Number of nodes Number of sides Number of dots Maximum degree average degree Yeast Data Set 3112 12519 179 168 8.0 Human 4674 86282 88 771 36.9 Email 36692 183831 20 1383 10.0 DBLP 317080 1049866 20 343 6.6
[0218] In this exemplary experiment, 100 query graphs were generated for each dataset, and the average query time was used as the metric. The time limit for each query graph was 10 minutes, and the top 10 queries were selected. 5 Matching stops once an isomorphic subgraph is found.
[0219] In practical applications, various algorithms exist to implement the depth-first search framework, including QuickSIFT (QSI), GraphQL (GQL), TurboISO (TBI), CFL-Match (CFL-Match), VF3, CECI, and DAF. In this exemplary experiment, the query performance of the method for obtaining isomorphic subgraphs given in this application embodiment, based on the above algorithms, is statistically analyzed. Tables 2 and 3 below show the statistical results of validation on the Email dataset and the DBLP dataset, respectively.
[0220] Table 2
[0221]
[0222] Table 3
[0223]
[0224] In Tables 2 and 3 above, +NEC a This indicates the query method after merging nodes in the query graph; +ISO b Used to indicate the query method for merging data graphs based on merged query graphs; +ORD c The instructions indicate that a query method with complete node judgment has been adopted based on the merging of the query graph and the data graph; +MIX d This indicates a mixed search approach using multiple search orders, building upon the aforementioned methods. The speedup ratios in Tables 2 and 3 are calculated by dividing the average query time of the previous query method by the average query time of the current query method. For example, in Table 3, based on the QSL algorithm, +ISO... b The corresponding speedup ratio is "1.3×", and the average query time (+NEC) using the previous query method is... a The query time (1.9) and the average query time (+ISO) of the current query method b The query time is 1.5. The result is obtained by dividing (1.9 / 1.5).
[0225] Based on the speedup data in Tables 2 and 3 above, it can be seen that the method for obtaining isomorphic subgraphs provided in this application embodiment can achieve a better speedup effect.
[0226] This application also provides an apparatus for obtaining subgraph isomorphism, see [link to relevant documentation]. Figure 6 The device includes:
[0227] The first determining module 601 is used to determine the first node of the current query among the nodes of the first query graph;
[0228] The second determining module 602 is used to determine at least one matching node of the first node in response to the first node satisfying the first condition. Satisfying the first condition means that all neighboring nodes of the first node have been determined to have matching nodes. The matching node of any node in the first query graph means that any node has a node with the same structure in the first data graph.
[0229] The third determining module 603 is used to determine the matching nodes of the second node in sequence based on the query order of each node in the first query graph. The second node is a node in the first query graph for which no matching node has been determined.
[0230] Matching module 604 is used to match the first node with at least one matching node of the first node in response to the fact that the second node has determined matching nodes;
[0231] The subgraph determination module 605 is used to determine the isomorphic subgraph of the first query graph in the first data graph based on the matching results.
[0232] In one possible implementation, the second determining module 602 is used to determine all the neighboring nodes of the first node in the first query graph and obtain the matching nodes of each neighboring node; determine the neighboring nodes of each matching node in the first data graph, and obtain the set of neighboring nodes of any matching node based on the neighboring nodes of any matching node; perform an intersection operation on the set of neighboring nodes of each matching node, and take at least one node included in the intersection operation result as at least one matching node of the first node.
[0233] In one possible implementation, see Figure 7 The device further includes: a switching module 606, configured to, based on a breadth-first search order, sequentially determine at least one node in the first data graph corresponding to each node in the first query graph, starting from the starting node of the first query graph, and store the matching results of each node in the first query graph; if, after storing at least one node corresponding to the currently queried node in the first data graph, the storage space occupied by the nodes corresponding to each matched node reaches a storage threshold, then, among the nodes already matched in the first query graph, determine a first node; based on the first node, determine the matching nodes of each node in the first query graph according to a depth-first search order; and based on the matching results of each node in the first query graph, determine the isomorphic subgraph of the first query graph in the first data graph.
[0234] In one possible implementation, the device further includes: a first merging module 607, used to merge target nodes in the second query graph and obtain a first query graph based on the merging result, wherein the target nodes are multiple nodes in the second query graph that satisfy the target conditions, which means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label; and a subgraph determination module 605, used to determine isomorphic subgraphs of the second query graph in the first data graph.
[0235] In one possible implementation, the device further includes: a second merging module 608, used to merge target nodes in the second data graph and obtain a first data graph based on the merging result, wherein the target nodes are multiple nodes in the second data graph that meet the target conditions, which means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label; and a subgraph determination module 605, used to determine isomorphic subgraphs of the first query graph in the second data graph.
[0236] In one possible implementation, the first merging module 607 is used to determine multiple target nodes in the second query graph based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph; merge all target nodes, and obtain the first query graph based on the merging result.
[0237] In one possible implementation, the first merging module 607 is used to determine multiple target nodes in the second query graph based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph; merge all leaf nodes in the multiple target nodes, and merge non-leaf nodes in the multiple target nodes based on a first limiting condition; and determine the first query graph based on the merging result.
[0238] In one possible implementation, the second merging module 608 is used to determine multiple target nodes based on the labels of each node in the second data graph and the connection relationships between each node in the second data graph; merge the target nodes based on the second limiting conditions; and determine the first data graph based on the merging result.
[0239] It should be noted that the device for obtaining subgraph isomorphism provided in the above embodiments is only an example of the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0240] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one program code or instruction, the at least one program code or instruction being loaded and executed by the processor, so that the computer device implements any of the above-described methods for obtaining isomorphic subgraphs.
[0241] Figure 8 This is a schematic diagram of a computer device provided in an embodiment of this application. The computer device can vary significantly due to differences in configuration or performance. It may include one or more Central Processing Units (CPUs) 801 and one or more memories 802. Each memory 802 stores at least one program instruction, which is loaded and executed by the one or more processors 801 to implement the method for obtaining isomorphic subgraphs provided in the various method embodiments described above. Of course, the computer device may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The computer device may also include other components for implementing device functions, which will not be elaborated here. The computer device can be a server, and the embodiments of this application can be executed in the central processing unit of a server.
[0242] On the other hand, a computer-readable storage medium is provided that stores at least one piece of program code or instruction, which is loaded and executed by a processor to enable a computer to implement any of the above methods for obtaining isomorphic subgraphs.
[0243] On the other hand, a computer program or computer program product is provided, which stores at least one computer instruction, which is loaded and executed by a processor to enable the computer to implement any of the above methods for obtaining isomorphic subgraphs.
[0244] It should be understood that in the various embodiments of this application, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0245] In this application, the term "at least one" means one or more, and the term "multiple" means two or more.
[0246] It should be understood that the terminology used in the description of the various examples herein is for the purpose of describing the particular examples only and is not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms “a” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise.
[0247] It should also be understood that the term “comprising” (also referred to as “includes”, “including”, “comprises” and / or “comprising”) as used in this specification specifies the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0248] It should be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information.
[0249] It should also be understood that the terms “if” and “if” can be interpreted as meaning “when” or “upon”, or “in response to determination” or “in response to detection”. Similarly, depending on the context, the phrases “if determination…” or “if detection [the stated condition or event]” can be interpreted as meaning “when determination…”, or “in response to determination…”, or “when detection [the stated condition or event]” or “in response to detection [the stated condition or event]”.
[0250] It should also be understood that the phrases "an embodiment," "an embodiment," and "a possible implementation" used throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment or implementation is included in at least one embodiment of this application. Therefore, the phrases "in an embodiment," "an embodiment," or "a possible implementation" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments.
[0251] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for obtaining isomorphic subgraphs, characterized in that, The method performs a search operation on a dataset, which includes a database system and a DBLP (Database Programming Language) dataset. The method includes: The first node of the current query is determined among the nodes of the first query graph, which is generated based on the dataset; In response to the first node satisfying the first condition, at least one matching node of the first node is determined. The first condition means that all neighboring nodes of the first node have been identified as matching nodes. The matching node of any node in the first query graph refers to the node with the same structure corresponding to the first data graph. In response to the first node not satisfying the first condition, a candidate set corresponding to the first node is determined, and a node that satisfies the matching condition in the candidate set is determined as a matching node of the first node. The matching condition means that the connection relationship between the first node and the nodes that have been matched in the first query graph exists in the connection relationship between the matching node and the nodes that have been determined as matching nodes in the first data graph. Based on the query order of each node in the first query graph, the matching nodes of the second node are determined sequentially. The second node is a node in the first query graph for which no matching node has been determined. In response to the fact that the second node has determined a matching node, the first node is matched with at least one matching node of the first node; Based on the matching results, the isomorphic subgraph of the first query graph in the first data graph is determined; Each node has a corresponding label and identifier. The label is used to indicate the attribute of the node, and the identifier is used to uniquely identify each node.
2. The method according to claim 1, characterized in that, Determining at least one matching node for the first node includes: In the first query graph, determine all the neighboring nodes of the first node and obtain the matching nodes of each neighboring node; In the first data graph, the neighboring nodes of each matching node are determined, and based on the neighboring nodes of any matching node, the set of neighboring nodes of any matching node is obtained. Perform an intersection operation on the set of neighbor nodes of each matching node, and take at least one node included in the intersection operation result as at least one matching node of the first node.
3. The method according to claim 1 or 2, characterized in that, Before determining the first node of the current query in each node of the first query graph, the method further includes: Based on the breadth-first search order, starting from the starting node of the first query graph, at least one node in the first data graph corresponding to each node in the first query graph is determined in sequence, and the matching results of each node in the first query graph are stored. If the storage space occupied by the nodes corresponding to the currently queried node in the first data graph reaches the storage threshold after the nodes that have been matched, then the first node is determined from the nodes that have been matched in the first query graph. Based on the first node, the matching nodes of each node in the first query graph are determined in a depth-first search order; Based on the matching results of each node in the first query graph, the isomorphic subgraph of the first query graph in the first data graph is determined.
4. The method according to claim 1 or 2, characterized in that, Before determining the first node of the current query in each node of the first query graph, the method further includes: The target nodes in the second query graph are merged, and the first query graph is obtained based on the merging result. The target nodes are multiple nodes in the second query graph that meet the target conditions. Meeting the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label. Determining the isomorphic subgraph of the first query graph in the first data graph includes: Determine the isomorphic subgraph of the second query graph in the first data graph.
5. The method according to claim 1 or 2, characterized in that, Before determining the first node of the current query in each node of the first query graph, the method further includes: The target nodes in the second data graph are merged, and the first data graph is obtained based on the merging result. The target nodes are multiple nodes in the second data graph that meet the target conditions. Meeting the target conditions means that multiple nodes have the same label, have neighboring nodes with the same amount of data, and the neighboring nodes of different nodes among the multiple nodes have the same label. Determining the isomorphic subgraph of the first query graph in the first data graph includes: Determine the isomorphic subgraph of the first query graph in the second data graph.
6. The method according to claim 4, characterized in that, The step of merging the target nodes in the second query graph and obtaining the first query graph based on the merging result includes: Based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph, multiple target nodes in the second query graph are determined. Merge all target nodes and obtain the first query graph based on the merge result.
7. The method according to claim 4, characterized in that, The step of merging the target nodes in the second query graph and obtaining the first query graph based on the merging result includes: Based on the labels of each node in the second query graph and the connection relationships between each node in the second query graph, multiple target nodes in the second query graph are determined. Merge all leaf nodes among the multiple target nodes, and merge non-leaf nodes among the multiple target nodes based on a first limiting condition; determine the first query graph based on the merging results.
8. The method according to claim 5, characterized in that, The process of merging target nodes in the second data graph and obtaining the first data graph based on the merging result includes: Based on the labels of each node in the second data graph and the connection relationships between each node in the second data graph, multiple target nodes in the second data graph are determined. The target nodes are merged based on the second limiting condition, and the first data graph is determined based on the merging result.
9. An apparatus for acquiring isomorphic subgraphs, characterized in that, The apparatus is used for searching a dataset, which includes a database system and a DBLP (Database-Based Programming Language) dataset. The apparatus includes: The first determining module is used to determine the first node of the current query among the nodes of the first query graph, the first query graph being generated based on the dataset; The second determining module is configured to, in response to the first node satisfying a first condition, determine at least one matching node for the first node, wherein satisfying the first condition means that all neighboring nodes of the first node have been identified as matching nodes, and a matching node for any node in the first query graph refers to a node with the same structure as the node in the first data graph; and in response to the first node not satisfying the first condition, determine a candidate set corresponding to the first node, and determine a node in the candidate set that satisfies the matching condition as a matching node for the first node, wherein satisfying the matching condition means that the connection relationship between the first node and the nodes that have been matched in the first query graph exists in the connection relationship between the matching node and the nodes that have been identified as matching nodes in the first data graph. The third determining module is used to determine the matching node of the second node in sequence based on the query order of each node in the first query graph. The second node is a node in the first query graph for which no matching node has been determined. A matching module is configured to match the first node with at least one matching node of the first node in response to the fact that the second node has determined matching nodes; The subgraph determination module is used to determine the isomorphic subgraph of the first query graph in the first data graph based on the matching results; Each node has a corresponding label and identifier. The label is used to indicate the attribute of the node, and the identifier is used to uniquely identify each node.
10. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one program code or instruction, the processor loading and executing the at least one program code or instruction to enable the computer device to implement the method for obtaining isomorphic subgraphs as described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one piece of program code or instruction, which is loaded and executed by a processor to enable the computer to implement the method for obtaining isomorphic subgraphs as described in any one of claims 1-8.
Citation Information
Patent Citations
Large-scale graph data processing method based on k<2>-tree and multi-valued decision diagram
CN106294739A
Sub-graph matching method and system, electronic equipment and storage medium
CN112579835A