Graph query method and device
By generating node labels that include node attributes and neighbor node connection structures, the redundant computation and high resource consumption problems of multiple graph query tasks in the prior art are solved, and more efficient graph query processing is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
- Filing Date
- 2026-01-16
- Publication Date
- 2026-05-12
AI Technical Summary
Existing graph query schemes suffer from redundant computation and high computational resource consumption when handling multiple graph query tasks, especially when the target graph is large in size, resulting in low efficiency.
By generating node labels that include node attributes and neighbor node connection structures, and utilizing label structure combinations and mapping relationships, computational steps and resource consumption are reduced, common subgraphs between query task graphs are identified, and query results are determined from the target graph based on these common subgraphs.
It significantly reduces the computation time and resource consumption of multiple graph query tasks, and improves query efficiency, especially when the target graph is large.
Smart Images

Figure CN122019536A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of graph query technology, and more particularly to a graph query method and apparatus. Background Technology
[0002] With the popularization and application of technologies such as big data and knowledge graphs, the application scale of graph queries based on large-scale graph data is growing rapidly. Subgraph query refers to the process of finding subgraphs within a large graph that satisfy specific structural and attribute constraints. Subgraph queries have wide applications in fields such as molecular structure retrieval, social network analysis, and financial fraud prevention. In real-world production environments, users often perform numerous subgraph query tasks on the same data graph that are structurally similar or partially overlapping. Existing graph query solutions typically process each query task independently, performing simple sequential processing on multiple query tasks. This results in a large amount of redundant computation in the steps of data node selection and traversal during the graph query process, severely limiting the efficiency of graph queries and increasing the consumption of computing resources. Summary of the Invention
[0003] The embodiments in this specification aim to provide a graph query method and apparatus that can generate node labels for a query task graph and a target graph, containing not only node attribute information but also structural information about the connection structure between nodes and their neighboring nodes. Furthermore, based on the node labels, common subgraphs between query task graphs can be determined, and query results can be determined from the target graph based on these common subgraphs with fewer computational steps and resources. This significantly reduces the overall computation time and resources consumed by multiple graph query tasks, improves the query efficiency of multiple graph query tasks, and overcomes the shortcomings of existing technologies.
[0004] Based on the first aspect, a graph query method is provided, including: Obtain several query requests from users for a target graph, including multiple query graphs, wherein each node in the target graph and each query graph is configured with node attributes; Several rounds of label generation are performed using node attributes as initial label values. Each round of label generation includes: for each node in the multiple query graphs, obtaining the current label value of the node and the current label values of its neighboring nodes to form a label structure combination, constructing a mapping relationship between each label structure combination and the label value of this round, and adding the label value of this round to each node in each query graph according to the mapping relationship; for the target graph, adding the corresponding label value of this round to the nodes that conform to the label structure combination according to the mapping relationship. The query nodes are matched based on the label values of each node in the target graph to obtain the first query result. The query nodes come from the query graph after the labels are added.
[0005] In one possible implementation, each round of label generation further includes: for the target graph, removing nodes that do not conform to any combination of label structures.
[0006] In one possible implementation, before matching query nodes, the process further includes: Based on the label values of each node in the multiple query graphs, a first common subgraph of the multiple query graphs is determined; The query node comes from the first common subgraph.
[0007] In one possible implementation, the method further includes: Before determining the first common subgraph of the plurality of query graphs, a cost index for matching the common subgraphs between the plurality of query task graphs in the target graph is determined based on the plurality of query task graphs and the target graph. Based on the label values of each node in the multiple query graphs, a first common subgraph of the multiple query graphs is determined, including: If the cost index is not greater than a preset threshold, a first common subgraph of the multiple query graphs is determined based on the label values of each node in the multiple query graphs.
[0008] In one possible implementation, the first common subgraph comprises at least two disconnected parts.
[0009] In one possible implementation, the label structure combination indicates the current label value of the node, the current label values of the node's neighboring nodes, and the adjacency relationship between the current label value of the node and the current label values of the node's neighboring nodes.
[0010] In one possible implementation, the method is executed through a preset graph computing engine, wherein multiple first parts of the target graph are pre-saved through multiple computing nodes of the graph computing engine; For the target graph, according to the mapping relationship, add the corresponding current-round label value to the nodes that conform to the label structure combination, including: In each of the plurality of computing nodes, according to the mapping relationship, the corresponding current round label value is added to the nodes in the first part of the target graph stored in the computing node that conform to the label structure combination; Matching query nodes based on the label values of each node in the target graph includes: in each of the plurality of computing nodes, adding corresponding current-round label values to nodes in the first part of the target graph stored in the computing node that conform to the label structure combination according to the mapping relationship.
[0011] According to the second aspect, a graph query device is provided, comprising: The acquisition unit is configured to acquire multiple query task graphs corresponding to multiple query requests from users for a target graph. Each of the target graphs and each query task graph includes multiple nodes and edges between the nodes, and each node is configured with node attributes. The processing unit is configured to, for each query task graph, determine the first label of each node in the query task graph based on the attributes of each node in the query task graph and the attributes of each node's neighboring nodes; and for the target graph, determine the first label of each node in the target graph based on the attributes of each node in the target graph, the attributes of each node's neighboring nodes, and the first label of the node in the query task graph. The determining unit is configured to: determine a first common subgraph of multiple query task graphs based on the first labels of each node in the multiple query task graphs; determine the matching result corresponding to the first common subgraph from the target graph based on the first labels of each node in the target graph; and determine the query result corresponding to each of the multiple query task graphs based on the matching result.
[0012] According to a third aspect, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method described in the first aspect.
[0013] According to a fourth aspect, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement the method described in the first aspect.
[0014] By utilizing one or more of the methods, systems, computing devices, and storage media mentioned above, node labels can be generated for both the query task graph and the target graph. These labels contain not only node attribute information but also structural information about the connections between nodes and their neighboring nodes. Furthermore, based on these node labels, common subgraphs between query task graphs can be determined, and query results can be retrieved from the target graph based on these common subgraphs, with fewer computational steps and resources. This significantly reduces the overall computation time and resources consumed by multiple graph query tasks, thereby improving the query efficiency of multiple graph query tasks. Attached Figure Description
[0015] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 A schematic diagram of a graph query scheme is shown; Figure 2This diagram illustrates another graph query scheme. Figure 3 A schematic diagram of a graph lookup method according to an embodiment of this specification is shown; Figure 4 A schematic diagram of node labels according to an embodiment of this specification is shown; Figure 5 A flowchart of a graph query method according to an embodiment of this specification is shown; Figure 6 This diagram illustrates the node relabeling in the graph query task graph and the target graph according to embodiments of this specification; Figure 7 A schematic diagram illustrating the estimated cost index according to an embodiment of this specification; Figure 8 A structural diagram of a graph query device according to an embodiment of this specification is shown. Detailed Implementation
[0017] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.
[0018] As mentioned earlier, with the popularization and application of technologies such as big data and knowledge graphs, the application scale of graph queries based on large-scale graph data is growing rapidly. Subgraph query refers to the process of finding subgraphs within a large graph that satisfy specific structural and attribute constraints. Subgraph queries have wide applications in fields such as molecular structure retrieval, social network analysis, and financial fraud prevention. In real-world production environments, users often perform numerous subgraph query tasks on the same data graph that are structurally similar or partially overlapping. Existing graph query schemes (unless otherwise specified, the graph query schemes referred to in this specification are schemes used for subgraph queries) typically employ a method of processing each graph query task independently, and performing simple sequential processing on multiple graph query tasks. For example, Figure 1 This diagram illustrates a graph query scheme. For example... Figure 1 As shown, multiple graph query tasks targeting the target graph are executed one by one, yielding the result sets for each task. The problem with this approach is that it can lead to a large amount of redundant computation in the steps of data node filtering and traversal during the graph query process, severely limiting the efficiency of graph queries and increasing the consumption of computing resources.
[0019] Figure 2 This illustrates another graph query scheme. For example... Figure 2 As shown, a common subgraph can be identified among multiple query graphs first. This common subgraph is then matched against the target graph. Based on the matching results, the differences between each query and the common subgraph are filled in, thus obtaining the query results for each query. This approach often improves processing efficiency when handling multiple graph query tasks. However, this approach also has the following problems: the common subgraph for multiple query tasks is usually determined based on the node attributes in the query task graph. After obtaining the common subgraph, the matching result in the target graph is determined based on the attributes of the nodes in the common subgraph and the target graph. However, determining the common subgraph and its corresponding matching result in the target graph based on node attributes usually requires extensive node-by-node attribute comparisons between different query task graphs or between the common subgraph and the target graph. This typically consumes significant computational resources, especially when the target graph is large, resulting in low computational efficiency.
[0020] To address the aforementioned technical problems, this specification provides an embodiment of a graph query method. Figure 3 A schematic diagram of a graph lookup method according to an embodiment of this specification is shown. For example... Figure 3As shown, multiple query task graphs for graph query tasks targeting the target graph can be obtained. These query task graphs illustrate the graph structure of the subgraph to be retrieved from the target graph. Furthermore, for multiple query task graphs and the target graph, several rounds of label generation can be performed using node attributes as initial label values. Each round of label generation can include: for each node in each query graph, obtaining the label structure combination formed by the node's current label value and the current label values of its neighboring nodes, constructing a mapping relationship between each label structure combination and the label value of this round, and adding the label value of this round to each node in each query graph according to this mapping relationship; similarly, for the target graph, the corresponding label value of this round can be added to nodes that match the label structure combination according to this mapping relationship. Specifically, nodes with the same label structure combination can be assigned the same label for this round, and nodes with different label structure combinations can be assigned different labels for this round. That is, for example, two nodes with the same label indicate that these two nodes have the same connection structure with their neighboring nodes. The process of relabeling nodes in each round is also called node relabeling. After several rounds of label generation, nodes in the target graph can be matched with nodes in the query graph based on the label values of nodes in the target graph and the label values of nodes in the query graph. Combining the matching results of nodes in each query graph with those in the target graph yields the query results for each query graph. In one example, a common subgraph of multiple query graphs can be determined based on the labels of nodes in multiple query graphs. This common subgraph is then matched against the target graph (based on the labels of nodes in the common subgraph). Finally, based on the matching results, the differences between each query graph and the common subgraph are filled in to obtain the query results for each query.
[0021] The advantage of this method is that the node labels in the relabeled query task graph and target graph essentially contain structural information about the connection structure between nodes and their neighboring nodes, rather than just node attribute information. Therefore, compared to determining the common subgraph between query task graphs based on node attributes, or determining the corresponding matching result from the target graph based on node attributes, determining the common subgraph between query task graphs or determining the corresponding matching result from the target graph based on node labels representing multi-point structural information can obtain matching results with fewer computational steps and less computational cost. For example, Figure 4The node u1 in the shown common subgraph is labeled kx, representing the following connection structure: u1 has attribute A and can be connected to three nodes with attributes B, C, and C respectively. Therefore, in determining the matching result corresponding to the common subgraph from the target graph, matching can directly start from all nodes in the target graph with label kx. However, the existing scheme starts matching from nodes with attribute A. Since the number of nodes with label kx is usually significantly less than the number of nodes with attribute A, and based on the kx label, it is not necessary to visit each node connected to a node with attribute A, it is possible to determine the nodes in the target graph with the connection structure represented by kx. This greatly reduces the computational steps in determining the matching result corresponding to the common subgraph from the target graph, improving the computational efficiency. Furthermore, this method can significantly reduce the overall computational resources consumed by multiple graph query tasks and improve the overall query efficiency of multiple graph query tasks.
[0022] The following section further elaborates on the detailed process of this method. Figure 5 A flowchart illustrating a graph query method according to an embodiment of this specification is shown. Figure 5 The method includes at least the following steps: Step S501: Obtain several query requests from the user for the target graph, including multiple query graphs, wherein the target graph and each node in each query graph are configured with node attributes; Step S503: Perform several rounds of label generation with node attributes as initial label values. Each round of label generation includes: for each node in the multiple query graphs, obtain the label structure combination formed by the current label value of the node and the current label values of its neighboring nodes, construct a mapping relationship between each label structure combination and the label value of this round, and add the label value of this round to each node in each query graph according to the mapping relationship; for the target graph, add the corresponding label value of this round to the nodes that conform to the label structure combination according to the mapping relationship.
[0023] Step S505: Match the query nodes based on the label values of each node in the target graph to obtain the first query result. The query nodes come from the query graph after the labels have been added.
[0024] First, in step S501, several query requests from the user for the target graph are obtained, including multiple query graphs, and each node in the target graph and each query graph is configured with node attributes.
[0025] Multiple query task graphs (also referred to as query graphs) can be obtained corresponding to multiple query requests from users targeting the target graph. Both the target graph and each query task graph can include multiple nodes and edges between them; nodes can be configured with node attributes. A graph, in computer science and mathematics, is an abstract model used to represent objects and their relationships. A graph can consist of nodes and edges between them. In different embodiments, the target graph can be a graph used for different specific purposes or business operations; this description does not limit this. In one embodiment, the target graph can be, for example, a social network graph, a molecular structure graph, or a financial business data graph.
[0026] In different embodiments, multiple query task graphs corresponding to multiple query requests for a target graph sent by one or more different specific users can be obtained. The query task graphs may also include multiple nodes configured with node attributes and edges between nodes, used to indicate the structure of the subgraph to be retrieved from the target graph. In different embodiments, the subgraph structure indicated by the query task graphs may have different specific graph structures. This specification does not impose any limitations on this.
[0027] Then, in step S503, several rounds of label generation can be performed on nodes in multiple query graphs and target graphs, using node attributes as initial label values. Each round of label generation may include: for each node in the multiple query graphs, obtaining a label structure combination formed by the current label value of the node and the current label values of its neighboring nodes, constructing a mapping relationship between each label structure combination and the label value of this round, and adding the label value of this round to each node in each query graph according to the mapping relationship. Also, for the target graph, adding the corresponding label value of this round to nodes that conform to the label structure combination according to the mapping relationship. In one embodiment, each round of label generation may further include: for the target graph, removing nodes that do not conform to any label structure combination.
[0028] In different embodiments and different rounds of label generation, the representation of the label structure combination formed by the current label value of a node and the current label values of its neighboring nodes can be different for each node in the query graph. In one embodiment, the label structure combination can indicate the current label value of the node, the current label values of the node's neighboring nodes, and the adjacency relationship between the current label value of the node and the current label values of its neighboring nodes.
[0029] Figure 6 This diagram illustrates node relabeling in the graph query task graph and the target graph according to embodiments of this specification. Figure 6As shown, for example, the query task graphs are Q1 and Q2. Q1 consists of nodes u11, u12, u13, and u14, where u11 has attribute A, u12 and u14 have attribute B, and u13 has attribute C. There are connecting edges between u11 and u12, u11 and u13, u12 and u13, and u13 and u14. Q2 consists of nodes u21, u22, u23, and u24, where u21 has attribute A, u22 has attribute B, and u23 and u24 have attribute C. There are connecting edges between u21 and u22, u21 and u23, u22 and u23, and u23 and u24. In the first round of relabeling, the label structure combination of each node can be determined based on the attributes of each node in Q1 and the edges between them. For example, for node u11 in Q1, its label structure combination can be determined as A-{B,C} based on its attribute A and the attributes of its neighboring nodes (u12 and u13). Here, "A" represents the node's own attribute, and "B,C" contained in the preset symbol combination "-{}" indicates that the node has two adjacent nodes with attributes B and C respectively. Similarly, the label structure combination for node u12 can be determined based on its attributes and the attributes of its neighboring nodes, for example, as B-{A,C}. And, based on the same method, the label structure combination for example, u13, is determined as B-{A,B*2}, and the label structure combination for u14 is B-{C} (or represented as u14->B-{C). And determine the label structure combination of each node in Q2: u21 -> A-{B,C}, u22 -> B-{A,C}, u23 -> B-{A,B*2}, u24 -> C-{C}.
[0030] After determining the label structure combinations of each node in each query task graph, a mapping relationship between the label structure combinations and the label values in the current round can be constructed based on these combinations. Then, labels are assigned to each node in each query task graph according to this mapping relationship. Nodes with the same label structure combination are assigned the same label, and nodes with different label structure combinations are assigned different labels. In different embodiments, different label structure combinations can be mapped to different specific label values. In one embodiment, label values can be composed of letters, numbers, and preset symbols. For example, Figure 6In the example shown, after determining the label structure combinations of each node in Q1 and Q2, different specific labels can be assigned based on these combinations. For instance, label k1 can be assigned to nodes in the query task graph with a label structure combination of A-{B,C}. Since node u11 in Q1 and node u21 in Q2 both have a label structure combination of A-{B,C}, label k1 can be assigned to both u11 and u21. Similarly, label k2 can be assigned to nodes in the query task graph with a label structure combination of B-{A,C}, and so on.
[0031] After the first round of node label reassignment in each query task graph, for the target graph, the labels reassigned to each node in this round can be determined in a similar manner to those in the query task graph, based on the attributes of each node in the target graph, the attributes of each node's neighboring nodes, and the mapping relationship between the label structure combination of nodes in the query task graph and the label values reassigned in this round. For example, Figure 6 As shown, the target graph G contains nodes v1 to v8. The label structure combination of each node in the target graph can be determined based on the attributes of each node in G and the attributes of each node's neighboring nodes. Then, according to the mapping relationship between the label structure combination of each node and the node labels in the current round of the query task graph, labels are assigned to each node in the target graph. For example, label k1 can be assigned to node v1 in the target graph G, label k2 to node v2, and so on.
[0032] In real-world production scenarios, the operation of generating node labels in the query task graph and target graph can be iterated multiple times to further improve query efficiency. The number of iterations can vary in different specific embodiments. For example, Figure 6In the example shown, after the first round of label allocation for the query graph and the target graph, a second round of label allocation can be performed. In the second round of label allocation, for example, for node u11 in Q1, the label for this round can be determined based on the label (k1) assigned to this node in the previous round, and the labels (k2) and (k3) assigned to its neighbors u12 and u13 in the previous round. Specifically, for example, the label structure combination corresponding to u11 in this iteration can be generated based on the labels (or current labels) assigned to u11, u12, and u13 in the previous round, for example, k1-{k2,k3}. Similarly, the label structure combination corresponding to node u12 in this iteration can be determined based on the current label of node u12 and the current labels of u12's neighbors, for example, k2-{k1,k3}. And, based on the same method, the label structure combination corresponding to each node in Q1 and Q2 in this iteration can be determined. Furthermore, different labels can be assigned to nodes in Q1 and Q2 based on different label structure combinations in this iteration. For example, label h1 can be assigned to nodes in the query task graph with label structure combinations of k1-{k2,k3}, label h2 to nodes with label structure combinations of k2-{k1,k3}, and so on. Then, based on the current labels of each node in the target graph G (assigned in the previous iteration) and the current labels of each node's neighboring nodes, the label structure combination of each node in the target graph for this iteration can be determined. Furthermore, based on the mapping relationship between the label structure combination formula corresponding to each node in this iteration and the label values assigned to nodes in the query task graph in this round, the labels for this round are assigned to each node in the target graph. For example, label h1 can be assigned to node v1 in the target graph G, label h2 to node v2, and so on. In one example, after the second round of label assignment, subsequent rounds of label assignment can be performed. The label classification process for subsequent rounds is similar to the process of the first and second rounds of label assignment, which will not be elaborated here.
[0033] Subsequently, in step S505, the query nodes can be matched based on the label values of each node in the target graph to obtain the first query result. The query nodes can come from the query graph after the labels are added. In this step, the query graphs can be matched in the target graph based on the query graph after the labels are added in step S503 and the target graph, and the query result of each query graph can be determined based on the matching result.
[0034] In different embodiments, the specific methods for matching each query graph in the target graph based on the tagged query graph and target graph can vary. In one embodiment, a common subgraph of multiple query graphs can be determined based on the labels of nodes in multiple query graphs. Then, this common subgraph is matched in the target graph (based on the labels of each node in the common subgraph), and the differences between each query graph and the common subgraph are filled in based on the matching results to obtain the query results for each query. A common subgraph refers to a subgraph structure that exists in both graphs. In different specific examples, the first common subgraph of multiple query task graphs can be determined based on the labels of each node in the multiple query task graphs and different preset subgraph matching algorithms. In one example, the preset subgraph matching algorithm could be, for example, one of the Ullman algorithm, VF2, or their derivative algorithms. In different embodiments, the determined first common subgraph can have different specific graphical structures, which are not limited in this specification. For example... Figure 6 In the example shown, the common subgraph includes three nodes with attributes A, B, and C, and all three nodes are connected pairwise. In one embodiment, the first common subgraph can be a fully connected subgraph. In another embodiment, the first common subgraph may also include at least two disconnected parts.
[0035] In graph querying, completion refers to the process of further searching and expanding the target graph for the unique parts of each query graph that are not included in the common subgraph (i.e., the "difference parts") after finding matching instances in the common subgraph, to obtain a complete matching result corresponding to the query graph. In different embodiments, the specific methods for completing the difference parts between each query graph and the common subgraph based on the matching results can vary, and this specification does not limit this. In one embodiment, for example, the difference parts between each query graph and the common subgraph can be defined for completion using an incremental matching algorithm based on node labels or a lightweight local expansion strategy based on label filtering. Therefore, in one embodiment, before matching query nodes, a first common subgraph of the multiple query graphs can be determined based on the label values of each node in the multiple query graphs. Furthermore, the query node can originate from the first common subgraph. In the embodiment where the first common subgraph may include at least two disconnected parts, the at least two disconnected parts of the first common subgraph may be stored in a pre-set cache. When matching the first common subgraph in the target graph, each part of the first common subgraph may be matched in the target graph, and the matching results of each part may be combined to obtain the matching result of the first common subgraph in the target graph.
[0036] In some scenarios, if the common subgraph structure is complex while the structures of each query task graph (excluding the common subgraph) are simple, the computational resources consumed by expanding the query results of multiple queries through the common subgraph can be greater than processing the multiple query tasks sequentially. Therefore, to further conserve computational resources, such as... Figure 7 As shown, in one embodiment, a cost index for matching a common subgraph among the multiple query task graphs in the target graph can be determined based on the multiple query task graphs and the target graph. Furthermore, if the cost index is not greater than a preset threshold, a first common subgraph of the multiple query task graphs is determined based on the first labels of each node in the multiple query task graphs. The matching result corresponding to the first common subgraph is determined from the target graph based on the first labels of each node in the target graph. Based on the matching result, the query result corresponding to each of the multiple query task graphs is determined.
[0037] In different embodiments, the specific method for determining the cost index of the first common subgraph among the plurality of query task graphs from the target graph can vary. In one embodiment, the cost index can be estimated, for example, by a preset machine learning model or based on a preset execution time complexity function. In different specific examples, the preset execution time complexity function can be different specific functions, and this specification does not limit this. In different specific examples, the specific value of the preset threshold can also be different, and this specification does not limit this. In another embodiment, if the cost index is greater than the preset threshold, the query results corresponding to each query task graph can be determined from the target graph based on the labels of each node in each query task graph and the labels of each node in the target graph, such as... Figure 7 As shown.
[0038] In different embodiments, the graph query method provided in this specification can be executed by different specific types of graph query engines or graph databases. In one embodiment, the method can be executed by a preset graph computing engine, where multiple first parts of the target graph are pre-saved by multiple computing nodes of the graph computing engine. Furthermore, in each round of label generation, in each of the multiple computing nodes, corresponding label values for the current round can be added to nodes in the first parts of the target graph stored in the computing node that conform to the label structure combination, according to the mapping relationship. And, in the process of matching query nodes based on the label values of each node in the target graph, corresponding label values for the current round are added to nodes in the first parts of the target graph stored in the computing node that conform to the label structure combination, according to the mapping relationship, in each of the multiple computing nodes.
[0039] According to yet another embodiment, a graph query device is also provided. Figure 8 This diagram illustrates a structural diagram of a graph lookup device according to an embodiment of this specification, such as... Figure 8 As shown, the device 800 includes: The acquisition unit 801 is configured to acquire several query requests from users for a target graph, including multiple query graphs, wherein each node in the target graph and each query graph is configured with node attributes. The processing unit 802 is configured to perform several rounds of label generation with node attributes as initial label values. Each round of label generation includes: for each node in the multiple query graphs, obtaining the label structure combination formed by the current label value of the node and the current label values of its neighboring nodes, constructing a mapping relationship between each label structure combination and the label value of this round, and adding the label value of this round to each node in each query graph according to the mapping relationship; for the target graph, adding the corresponding label value of this round to the nodes that conform to the label structure combination according to the mapping relationship. The query unit 803 is configured to match query nodes based on the label values of each node in the target graph to obtain a first query result, wherein the query nodes are from the query graph after adding labels.
[0040] In another aspect, embodiments of this specification provide a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform any of the methods described above.
[0041] In another aspect, embodiments of this specification provide a computing device, including a memory and a processor, wherein the memory stores executable code, and the processor executes the executable code to implement any of the methods described above.
[0042] It should be understood that the descriptions such as "first" and "second" in this article are merely for the sake of simplicity in description and to distinguish similar concepts, and do not have any other limiting function.
[0043] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must also be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0044] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0045] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0046] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes said elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.
[0047] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0048] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0049] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0050] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0051] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0052] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0053] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0054] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0055] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0056] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0057] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of these embodiments. Various modifications and variations can be made to these embodiments by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.
Claims
1. A graph query method, comprising: Obtain several query requests from users for a target graph, including multiple query graphs, wherein each node in the target graph and each query graph is configured with node attributes; Several rounds of label generation are performed using node attributes as initial label values. Each round of label generation includes: for each node in the multiple query graphs, obtaining the current label value of the node and the current label values of its neighboring nodes to form a label structure combination, constructing a mapping relationship between each label structure combination and the label value of this round, and adding the label value of this round to each node in each query graph according to the mapping relationship; for the target graph, adding the corresponding label value of this round to the nodes that conform to the label structure combination according to the mapping relationship. The query nodes are matched based on the label values of each node in the target graph to obtain the first query result. The query nodes come from the query graph after the labels are added.
2. The method according to claim 1, wherein, Each round of label generation also includes: for the target graph, removing nodes that do not conform to any combination of label structures.
3. The method according to claim 1, wherein, The label structure combination indicates the current label value of the node, the current label values of the node's neighboring nodes, and the adjacency relationship between the current label value of the node and the current label values of the node's neighboring nodes.
4. The method according to claim 1, further comprising, before matching the query nodes: Based on the label values of each node in the multiple query graphs, a first common subgraph of the multiple query graphs is determined; The query node comes from the first common subgraph.
5. The method according to claim 4, further comprising: Before determining the first common subgraph of the plurality of query graphs, a cost index for matching the common subgraphs between the plurality of query task graphs in the target graph is determined based on the plurality of query task graphs and the target graph. Based on the label values of each node in the multiple query graphs, a first common subgraph of the multiple query graphs is determined, including: If the cost index is not greater than a preset threshold, a first common subgraph of the multiple query graphs is determined based on the label values of each node in the multiple query graphs.
6. The method according to claim 4, wherein, The first common subgraph includes at least two disconnected parts, which are stored in a preset cache.
7. The method according to claim 1, wherein, The method is executed through a preset graph computing engine, and multiple first parts of the target graph are pre-saved through multiple computing nodes of the graph computing engine; For the target graph, according to the mapping relationship, add the corresponding current-round label value to the nodes that conform to the label structure combination, including: In each of the plurality of computing nodes, according to the mapping relationship, the corresponding current round label value is added to the nodes in the first part of the target graph stored in the computing node that conform to the label structure combination; Matching query nodes based on the label values of each node in the target graph includes: in each of the plurality of computing nodes, adding corresponding current-round label values to nodes in the first part of the target graph stored in the computing node that conform to the label structure combination according to the mapping relationship.
8. A graph query device, comprising: The acquisition unit is configured to acquire several query requests from users for a target graph, including multiple query graphs, wherein each node in the target graph and each query graph is configured with node attributes; The processing unit is configured to perform several rounds of label generation with node attributes as initial label values. Each round of label generation includes: for each node in the multiple query graphs, obtaining a label structure combination formed by the current label value of the node and the current label values of its neighboring nodes, constructing a mapping relationship between each label structure combination and the label value of this round, and adding the label value of this round to each node in each query graph according to the mapping relationship; for the target graph, adding the corresponding label value of this round to the nodes that conform to the label structure combination according to the mapping relationship. The query unit is configured to match query nodes based on the label values of each node in the target graph to obtain a first query result, wherein the query nodes are from the query graph after adding labels.
9. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-7.
10. A computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 1-7.