Sub-graph query method and device

By conducting preliminary query based on querying the same parts between subgraphs in the graph database, and then conducting subgraph query on the remaining parts, the problem of low matching efficiency in the graph database is solved, and more efficient matching and privacy data protection is achieved.

CN119782586AActive Publication Date: 2025-04-08ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411779293.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-04-08
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

The prior art is less efficient when sub-map matching data graphs in graph databases, and it is difficult to effectively protect privacy data.

Method used

By obtaining several query subgraphs to be queried, first perform a preliminary query based on the same part between the query subgraphs in the graph database to obtain the query results of the same part, and then perform a subgraph query in the data graph based on the remaining part of the query subgraph to reduce duplicate matching.

Benefits of technology

It improves the efficiency of data graph subgraph matching in the graph database, reduces duplicate matching of the same parts in multiple query subgraphs, and protects private data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119782586A_ABST
    Figure CN119782586A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a subgraph query method and device which are used for conducting subgraph query on a data graph stored in a graph database. The query sub-graphs to be queried comprise nodes, edges and attribute information of the nodes and the edges. The data graph contains privacy data of the user, and privacy protection needs to be continued in the data processing process. When subgraph query is carried out, preliminary query is carried out in a data graph stored in a graph database based on the same part among a plurality of query subgraphs to obtain a first query result of the same part, and the same part is contained in the plurality of query subgraphs and is a subgraph corresponding to the same edge of the plurality of query subgraphs. And on the basis of the first query result, performing sub-graph query in the data graph based on the remaining parts of the plurality of query sub-graphs to obtain a query result of each query sub-graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of graph database processing technology, and in particular, to a subgraph query method and device. Background Art

[0002] In the computer field, a database is a system used to store, manage, and retrieve data. A relational database is a very common type of database, which is usually used to store structured data. When a user submits a query, the database matches the query with the data in the database. When a match is successful, the database reads the data and returns it to the user.

[0003] Non-relational databases can be used to store unstructured data. For example, graph databases store and query data in a graph structure. Data is stored in the form of nodes and edges, where nodes represent data entities and edges represent the relationship between entities. The data stored in the graph database is also called a data graph. When a user provides a query subgraph, the given query subgraph can be matched in the data graph to obtain all isomorphic graphs of the query subgraph. The data graph contains the user's private data. When matching the data graph, it is necessary to ensure that the private data is not leaked.

[0004] At present, it is hoped that there will be an improved solution that can more efficiently perform subgraph matching on data graphs stored in graph databases. Summary of the invention

[0005] One or more embodiments of this specification describe a subgraph query method and device to more efficiently perform subgraph matching on a data graph stored in a graph database. The specific technical solution is as follows.

[0006] In a first aspect, an embodiment provides a subgraph query method, including:

[0007] Acquire several query subgraphs to be queried; the several query subgraphs include nodes and edges, and attribute information of the nodes and edges;

[0008] Based on the same parts among the several query subgraphs, a preliminary query is performed in the data graph stored in the graph database to obtain a first query result of the same parts; the same parts are contained in the several query subgraphs and are subgraphs corresponding to the same edges of the several query subgraphs;

[0009] On the basis of the first query result, subgraph queries are performed in the data graph based on the remaining parts of the several query subgraphs respectively to obtain query results of each query subgraph.

[0010] In one implementation, the common parts among the query subgraphs are obtained based on the following method: merging the query subgraphs into a query tree; and dividing the trunk of the query tree into the common parts among the query subgraphs.

[0011] In one implementation, the remaining portion of any query subgraph is a branch portion of the query tree.

[0012] In one embodiment, any first query subgraph contains a number of edges and their matching order, and the edges contained in the same part have the same corresponding matching order in different query subgraphs; the step of merging the several query subgraphs into a query tree includes: using the edges in the first query subgraph as tree nodes in the query tree, and merging the first query subgraph into the query tree according to the matching order, so that the several edges contained in the same part are sequentially merged into the trunk of the query tree.

[0013] In one embodiment, in the first query subgraph, the edges included in the same portion have a matching order that is prior to the matching order of other edges; and the operation of merging the first query subgraph into the query tree includes:

[0014] The first query subgraph is merged into the query tree according to the matching order of the edges in the first query subgraph and the order from the root node to the leaf nodes in the query tree.

[0015] In one embodiment, when the first query subgraph is the first one, the step of merging the first query subgraph into the query tree includes: according to the matching order, using the edges of the current matching order in the first query subgraph as parent nodes in the query tree, and using the edges of the next matching order as child nodes of the parent nodes.

[0016] In one implementation, when the first query subgraph is not the first one, the step of merging the first query subgraph into the query tree includes:

[0017] Determine a first edge from the first query subgraph according to the matching order, determine a first tree node from the query tree in an order from a parent node to a child node, and perform iterative merging in the following manner:

[0018] Determine whether the first edge can be merged with an edge in a child node of the first tree node;

[0019] If yes, updating the first edge and the first tree node;

[0020] If not, the first edge and other edges in the first query subgraph are used in sequence as child nodes of each level of the first tree node.

[0021] In one embodiment, the step of determining whether the first edge and the child nodes of the first tree node can be merged includes: when the first edge matches an edge of any child node included in the first tree node, determining that the first edge and the child nodes can be merged.

[0022] In one embodiment, the tree nodes in the query tree have corresponding edge data, and the edge data includes: an identifier of the tree node and child nodes of the tree node, and an identifier for indicating whether the edge of the tree node is the last one in a query subgraph;

[0023] When executing the step of using the first edge in a query subgraph as a tree node in the query tree, it includes: determining the edge data of the tree node based on the edge data of the first edge.

[0024] In one embodiment, the edge data of the tree node also includes: a node identifier and an edge identifier corresponding to the edge; the edge identifier is used as the identifier of the tree node; the step of determining the edge data of the tree node based on the edge data of the first edge includes: when the node identifier of the first edge is recorded in the mapping relationship library, determining the node identifier of the tree node based on the node identifier in the tree node corresponding to the node identifier in the mapping relationship library; the mapping relationship library is used to record the mapping relationship between the node identifier in the query subgraph and the node identifier in the query tree.

[0025] In one embodiment, the preliminary query includes: performing a subgraph query in the data graph stored in the graph database based on the trunk portion of the query tree; the step of performing a subgraph query in the data graph based on the remaining portions of the several query subgraphs based on the first query result includes: performing a subgraph query based on the branch portions of the query tree based on the first query result.

[0026] In one embodiment, the step of performing a subgraph query in the data graph stored in the graph database based on the trunk portion of the query tree includes:

[0027] When the edge of the first tree node is an edge to be queried, a subgraph query is performed on the edge to be queried in the data graph based on a subgraph obtained by querying the edge of the parent node of the first tree node in the data graph.

[0028] In one embodiment, the step of performing a subgraph query in the query graph based on the branch part of the query tree includes: when the first tree node is the last tree node in the corresponding path of the first query subgraph in the query tree, based on the subgraph query result of the first tree node in the data graph, determining the query result corresponding to the first query subgraph.

[0029] In a second aspect, an embodiment provides a subgraph query device, the device comprising:

[0030] A subgraph acquisition module, configured to acquire a plurality of query subgraphs to be queried; the plurality of query subgraphs include nodes and edges, and attribute information of the nodes and edges;

[0031] A preliminary query module is configured to perform a preliminary query in a data graph stored in a graph database based on the same parts between the query subgraphs to obtain a first query result of the same parts; the same parts are contained in the query subgraphs and are subgraphs corresponding to the same edges of the query subgraphs;

[0032] The remaining query module is configured to perform subgraph queries in the data graph based on the remaining parts of the several query subgraphs on the basis of the first query result, so as to obtain query results for each query subgraph.

[0033] In a third aspect, an embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute any one of the methods described in the first aspect.

[0034] In a fourth aspect, an embodiment provides a computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in any one of the first aspects is implemented.

[0035] In the method and apparatus provided in the embodiments of this specification, a preliminary query is performed on the same parts between several query subgraphs in the data graph stored in the graph database to obtain a first query result, and then a subgraph query is continued on the remaining parts of each query subgraph, thereby reducing repeated matching of the same parts in multiple query subgraphs, thereby enabling more efficient subgraph matching of the data graph stored in the graph database. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0037] Figure 1 A schematic diagram of an implementation scenario disclosed in this specification;

[0038] Figure 2 A schematic diagram of a flow chart of a subgraph query method provided in an embodiment;

[0039] Figure 3 A schematic diagram of a process for constructing a query tree provided in an embodiment;

[0040] Figure 4 A schematic diagram of a class of edge data of a tree node provided by an embodiment;

[0041] Figure 5 A schematic block diagram of a subgraph query device provided in an embodiment. DETAILED DESCRIPTION

[0042] The solution provided in this specification is described below in conjunction with the accompanying drawings.

[0043] A large number of data graphs are stored in the graph database. Data graphs are graph structured data constructed using a large amount of business data. The data graph contains a large number of nodes and edges between nodes, as well as attribute information of nodes and edges. Among them, nodes represent data entities, and edges represent the relationship between entities. Node attribute information and edge attribute information contain different meanings according to specific scenarios. For example, in a transaction scenario, nodes represent users, edges represent transactions between users, and the attribute information of nodes refers to user attribute information, which may include user accounts, user attributes, and user historical behavior information; the attribute information of edges refers to transaction attribute information, which may include transaction number, transaction amount, transaction time, transaction method, and transaction parties' accounts. In the field of product push, nodes represent users and products, and edges represent the behavioral relationship between users and products (for example, including behavioral relationships such as clicks, searches, or views). The attribute information of user nodes refers to user attribute information, the attribute information of product nodes refers to product attribute information, which may include product information, and the attribute information of edges includes information related to behavior. In addition, the data in the data graph can also be data from other business fields. It should be noted that user-related information, including user attributes and transaction attributes, is private data and needs to be protected during data processing. In addition, the above user-related private data is obtained after the user's authorization.

[0044] The query subgraph (query) is a small graph structure data relative to the data graph. The query subgraph contains nodes and edges, and can specifically contain multiple nodes and multiple edges, at least two nodes and one edge between the two nodes. The query subgraph is a specific pattern graph with a specified structure determined by some known methods. For example, it can be a specific pattern graph with a transaction risk structure, etc. It contains some specific nodes and edges, which constitute the graph pattern that needs to be matched.

[0045] Subgraph query refers to finding all subgraphs in the data graph that are isomorphic to the query subgraph. The purpose of subgraph query is to find all subgraphs in a given large graph that are isomorphic to a given small graph. The query subgraph is the small graph used for query in subgraph matching. In the field of transaction risk prediction, the subgraphs matched in the data graph using the query subgraph are transactions containing risks. These subgraphs can be used to predict risks, thereby more quickly determining business risks and eliminating business risks.

[0046] The subgraph found and the query subgraph belong to isomorphic graphs. There is a one-to-one mapping between the node sets of two graphs belonging to isomorphic graphs, and the edges between corresponding vertices also maintain a one-to-one correspondence. In two isomorphic graphs, a group of corresponding nodes have the same node attribute information, and the corresponding edges have the same node attribute information.

[0047] Figure 1 This is a schematic diagram of an implementation scenario disclosed in this specification. It includes a risk control platform, a computing device and a graph database. Among them, the risk control platform is used to send the query subgraph to the computing device. The computing device is used to perform subgraph query in the graph database based on the query subgraph, and send the query results obtained to the risk control platform. The risk control platform is used to predict risks based on the query results. The graph database is used to store data in the data graph. Figure 1 The diagrams of the query subgraph, data graph, and query results are also given. The colors of the nodes and edges represent the corresponding node attributes and edge attributes. The numbers in the circles are the node numbers. The numbers of the corresponding nodes in the matched user subgraph and query subgraph may be different. For example, the edge 1→2 in the query subgraph corresponds to the edge 2→1 in the user subgraph, but the node numbers are different. Figure 1 This is only a schematic diagram of a scenario of this embodiment. In actual applications, the embodiment can also be applied to a variety of implementation scenarios.

[0048] In the actual application scenario of subgraph query, there are usually more than one query subgraph, so batch subgraph query is needed. Batch subgraph query is to perform subgraph query on multiple query subgraphs in the data graph.

[0049] In order to improve the efficiency of the batch subgraph query process, the embodiment of this specification provides a subgraph query method. Figure 2 This embodiment is described.

[0050] Figure 2 A schematic flow chart of a subgraph query method provided in an embodiment. The data graph contains a large number of nodes and edges between the nodes, and the edges may have directions or may not have directions. The method may be executed by a computing device. Figure 1 In the scenario shown, the method of this embodiment can be performed by Figure 1The computing device in the embodiment of the method comprises the following steps.

[0051] Step S210, obtaining a plurality of query subgraphs Q to be queried. A plurality includes one or more. Each query subgraph Q contains at least two nodes and the connecting edges therebetween, as well as the attribute information of the nodes and the attribute information of the edges.

[0052] Step S220, based on the same parts among the several query subgraphs Q, a preliminary query is performed in the data graph G stored in the graph database to obtain a first query result for the same parts.

[0053] The same part is included in several query subgraphs, which are subgraphs corresponding to the same edges of several query subgraphs. The same edges of several query subgraphs can be one or more. Any same edge includes the same edge attribute information and the same attribute information of the two nodes connected by the edge.

[0054] In an example, several query subgraphs Q include a first query subgraph Q1 and a third query subgraph Q3, etc., and these two query subgraphs Q have identical parts and different parts. The edge 1→2 in the first query graph Q1 is the same edge as the edge 1→4 in the third query graph Q3, and the edge 2→3 in the first query graph Q1 is the same edge as the edge 4→3 in the third query graph Q3, so the identical parts are the parts composed of black dots, blue lines, white dots, black lines, and blue dots in sequence. The remaining parts are the different parts of the two query subgraphs, which are the parts composed of black dots, yellow lines, and blue dots in the first query subgraph Q1 and the parts composed of black dots, black lines, white dots, blue lines, and blue dots in the third query subgraph Q3. In order to make the description more concise and clear, Figure 2 The colors of circles and lines represent node attributes and edge attributes.

[0055] The first query result is only the intermediate data of the subgraph query process, and is not the final query result.

[0056] When this step is executed, the edges included in the query subgraphs Q can be compared to determine the same parts among the query subgraphs Q, and the same parts among the query subgraphs Q can be merged into one or more graphs, and the number of merged graphs is less than the number of query subgraphs Q. In other words, the same part can be understood as a graph containing nodes and the edges between them. Usually, the same part can be a continuous part among the query subgraphs Q.

[0057] When a preliminary query is performed in the data graph G based on the same part, the same part can be regarded as a query subgraph. The existing method can be used to perform a subgraph query on the same part in the data graph G. The specific process will not be repeated here.

[0058] Step S230, based on the first query result, subgraph queries are performed in the data graph G based on the remaining parts of the query subgraphs, respectively, to obtain query results for each query subgraph Q. For each query subgraph Q, its query result includes one or more subgraphs. In the field of transaction risk control, the query results are used to predict transaction risks.

[0059] After obtaining the first query result of the same part, since the same part is related to the remaining part of each query subgraph Q, the subgraph query can be continued on the basis of the first query result corresponding to the same part, so as to obtain the complete subgraph query result corresponding to each query subgraph Q. For example, within the data graph range included in the first query result, the subgraph query can be continued on the remaining part of any first query subgraph Q1 to obtain the query result corresponding to the first query subgraph Q1. The remaining part of each query subgraph Q is also a query subgraph, and the query on the query subgraph can be performed in an existing manner.

[0060] In the graph database query method provided in the present embodiment, since the same part is preliminarily queried in the data graph G, subgraph matching is continued for the remaining parts of each query subgraph based on the first query result obtained. There is no need to repeatedly perform subgraph matching on the same part, which reduces the amount of calculation during the query and can improve the efficiency of batch subgraph queries.

[0061] In order to improve the query efficiency, in another embodiment of the present specification, Figure 2 In the embodiment, between steps S210 and S220, a step of obtaining the same part of several query subgraphs Q may be further included. In specific implementation, the step of obtaining the same part of several query subgraphs Q may be implemented by following step 1, and steps S220 and S230 may be implemented by step 2.

[0062] Step 1: Merge several query subgraphs Q into a query tree T.

[0063] The trunk of the query tree T is divided into the same parts among several query subgraphs Q1, the remaining part of any query subgraph Q is the branch part of the query tree T, and the several paths contained in the query tree T correspond to several query subgraphs Q. The query tree T contains multiple tree nodes, and the multiple tree nodes form multiple paths from the root node to the leaf node.

[0064] Step 2, in the order from the trunk part to the branch part of the query tree T, based on the query tree T, perform subgraph query in the data graph G, and obtain query results corresponding to several query subgraphs Q. Specifically, step 2 may include the following steps 2_1 and 2_2.

[0065] Step 2_1, preliminary query. The preliminary query includes: performing a subgraph query on the data graph G stored in the graph database based on the trunk of the query tree T to obtain a first query result.

[0066] Step 2_2, remaining query. The remaining query includes: based on the first query result, performing subgraph query based on the branch parts of the query tree T respectively.

[0067] In this embodiment, merging several query subgraphs Q into a query tree T can merge as many identical parts as possible between the query subgraphs Q, thereby avoiding repeated queries as much as possible, thereby improving query efficiency.

[0068] In step 1, since there is a connection relationship between nodes and edges in the query subgraph, there is also a connection relationship between tree nodes in the query tree T. Based on this similarity, multiple query subgraphs Q can be merged into a query tree T, so that the trunk of the query tree T contains the same part mentioned above, and the several paths contained in the query tree T correspond to several query subgraphs Q. Based on this idea, multiple implementation methods can be used to merge several query subgraphs Q into a query tree T. The execution process of step 1 is described below in combination with specific implementation methods.

[0069] In one implementation, for any first query subgraph Q1 among several query subgraphs Q, the first query subgraph Q1 includes several edges and their matching order, and the edges included in the same part have the same corresponding matching order in different query subgraphs Q. In this case, step 1 can be performed as follows:

[0070] The edges included in the first query subgraph Q1 are used as tree nodes in the query tree T. According to the matching order of the edges in the first query subgraph Q1, the first query subgraph Q1 is merged into the query tree T, so that the edges of the same part are sequentially merged into the trunk of the query tree T, and the different parts (i.e., the remaining parts) of the first query subgraph Q1 relative to other query subgraphs Q are merged into the branch part of the query tree T. The edges in the query subgraph Q are used as tree nodes in the query tree T, and each tree node is an edge in the query subgraph Q. The edge data in the query subgraph Q can be directly used to determine the data of the tree nodes. This correspondence can reduce the complexity of constructing the tree node data.

[0071] Here and in the following sections, the operations performed on any first query subgraph Q1 are taken as an example for description. The same or similar operations are performed on other query subgraphs Q1.

[0072] Edges are the smallest matching units in the subgraph matching process. In the subgraph query process, edges and the two nodes they connect constitute the basic units for matching. The matching order refers to the query order of a certain edge when the query subgraph is queried separately in the data graph G. For example, in Figure 2 In the first query subgraph Q1, edge 1→2 is a matching unit in the query. Edge 2→3 and edge 1→3 are different matching units. Each edge in the query subgraph Q1 and its matching order can be expressed as follows:

[0073] edges[0]: {node1, node2, black, white, blue}

[0074] edges[1]: {node2, node3, white, blue, black}

[0075] edges[2]: {node1, node3, black, blue, yellow}

[0076] Taking edges[0] as an example, edges[0] is the identifier of the edge, where 0 represents the matching order of the edge, and the contents in the curly brackets are the source node, target node, source node color, target node color, and edge color of the edge, respectively.

[0077] In the third query subgraph Q3, each edge and its matching order can be expressed as follows:

[0078] edges[0]: {node1, node4, black, white, blue}

[0079] edges[1]: {node4, node3, white, blue, black}

[0080] edges[2]: {node3, node2, blue, white, blue}

[0081] edges[3]: {node2, node1, white, black, black}

[0082] It can be seen that the same parts between the first query subgraph Q1 and the third query subgraph Q3 are edges [0] and edges [1]. The edges contained in the above-mentioned same parts have the same corresponding matching order in several query subgraphs Q. It can be understood that the matching order of the above-mentioned same parts in the first query subgraph Q1 is the same as the matching order of the same parts in the third query subgraph Q3. In other words, the matching order of edges [0] and edges [1] in the two query subgraphs is 0 and 1.

[0083] The query tree is a tree structure data. When constructing the tree structure data, it can be constructed in a top-down (starting from the root node) or bottom-up (starting from the leaf node) manner. According to the matching order of the first query subgraph Q1, when merging several edges in the first query subgraph Q1 into the query tree T, the query tree T can be constructed in a top-down or bottom-up order.

[0084] In one implementation, instead of using edges as tree nodes, the nodes in the first query subgraph Q1 may be used as tree nodes in the query tree T, the edges in the first query subgraph Q1 may be used as edges between tree nodes in the query tree T, or both the nodes and edges in the first query subgraph Q1 may be used as tree nodes in the query tree T.

[0085] The specific construction process of the query tree T is described below. In the implementation method of using edges as tree nodes in the query tree T and constructing the query tree T according to the matching order of the edges included in the first query subgraph Q1, the first query subgraph Q1 can be merged into the query tree T by setting the mutual correspondence between the matching order of the edges included in the same part and the construction order of the query tree T.

[0086] For example, the matching order of the edges contained in the above-mentioned same part can be placed after the matching order of other edges. In this case, when merging the first query subgraph Q1 into the query tree T, it can be performed as follows: according to the matching order of several edges in the first query subgraph Q1, and the order from the leaf nodes to the root nodes in the query tree T, the first query subgraph Q1 is merged into the query tree T.

[0087] Alternatively, the first query subgraph Q1 is set as follows: the matching order of the edges contained in the same part is prior to the matching order of other edges. In this case, when merging the first query subgraph Q1 into the query tree T, it can be performed as follows:

[0088] According to the matching order of several edges in the first query subgraph Q1 and the order from the root node to the leaf nodes in the query tree T, the first query subgraph Q1 is merged into the query tree T.

[0089] This matching and merging method can make it easier to merge the edges of the same part into the trunk of the query tree T. Figure 3 The construction process of the query tree T is described in detail.

[0090] Figure 3 A schematic diagram of a process of constructing a query tree provided in an embodiment, wherein the process of merging multiple query subgraphs Q1 to Q3 into the query tree T in sequence is listed from left to right.

[0091] When the first query subgraph Q1 is the first query subgraph to be merged into the query tree T, there is only a root node (root) in the query tree T, and no child nodes exist yet. The root node can be set to an empty node and is a tree node that does not contain edges.

[0092] In this case, you can follow these steps:

[0093] According to the above matching order, the edges in the current matching order in the first query subgraph Q1 are used as parent nodes in the query tree T, and the edges in the next matching order are used as child nodes of the parent node.

[0094] exist Figure 3 In the current matching order, the edge can be any one of edges[0], edges[1] and edges[2]. For example, we can start from the first edge edges[0], take the first edge as the parent node in the query tree T, take the next edge edges[1] as the child node of the root node, and take the edge edges[2] as the next-level child node of the child node. Thus, multiple edges in the first query subgraph Q1 are added to the query tree T in sequence. When the last-level leaf node is reached, the leaf node is pointed to the first query subgraph Q1, that is, query→1 is set to indicate that the path from the root node to the leaf node corresponds to the first query subgraph Q1.

[0095] When the second query subgraph Q2 is not the first query subgraph to be merged into the query tree T, there are already multiple tree nodes in the query tree T, and the tree nodes contain edges. In this case, the second query subgraph Q2 can be merged into the query tree T in the following implementation manner.

[0096] Determine the first edge from the second query subgraph Q2 according to the matching order, determine the first tree node from the query tree T according to the order from the parent node to the child node, and perform iterative merging according to the following steps 1_1 to 1_3.

[0097] Step 1_1, determine whether the first edge and the edge in the child node of the first tree node can be merged, if yes, execute step 1_2; if no, execute step 1_3;

[0098] Step 1_2, update the first edge and the first tree node;

[0099] Step 1_3, the first edge and other edges in the second query subgraph Q2 are used as child nodes of each level of the first tree node in sequence.

[0100] In this implementation, the root node is pre-set as an empty node, which is a tree node that does not contain an edge. Therefore, the root node is initially used as the first tree node, and the first edge is merged and judged with the edge of the child node of the first tree node. The above matching order is the matching order of several edges in the second query subgraph Q2. Initially, the edge of the first matching order, that is, the first edge, is used as the first edge.

[0101] When determining whether the merge is possible, it is possible to determine whether the first edge matches the edge attribute information of any child node contained in the first tree node. In other words, if the first edge is completely identical to the edge of any child node of the first tree node, it is considered to be matched; if the first edge is not completely identical to the edges of all child nodes of the first tree node, it is considered to be unmatched. If it is matched, it means that the judgment result of step 1_1 is yes. If it is not matched, it means that the judgment result of step 1_1 is no.

[0102] Specifically, the execution of step 1_1 includes a loop process. That is, it is determined whether the first edge and the edge of a child node of the first tree node can be merged. If not, it is determined whether the first edge and the edges of other child nodes of the first tree node can be merged, until all child nodes of the first tree node are judged. If none of them can be merged, it is determined that the judgment result of step 1_1 is not. If there is a child node among all child nodes of the first tree node that can be merged with the first edge, the loop stops, and it is determined that the judgment result of step 1_1 is yes.

[0103] When determining whether the first edge matches any child node (e.g., the first child node) included in the first tree node, it is possible to compare whether the first edge is the same as the edge in the first child node, that is, whether the node attribute information corresponding to the edge and the edge attribute information are the same. If they are the same, it is determined that the two match. When matching, the edge generally includes the first and last nodes and the edge between the first and last nodes.

[0104] When updating the first edge and the first tree node in step 1_2, the edge in the next matching order in the second query subgraph Q2 can be updated to the first edge, and the child nodes of the first tree node that are determined to be mergeable (such as the first child node) can be updated to the first tree node.

[0105] In step 1_3, the first edge is used as a child node of the first tree node, and the next edge of the first edge is used as a child node of the child node, until the remaining edges in the second query subgraph Q2 are added to the query tree T.

[0106] After step 1_2 or step 1_3, the process returns to step 1_1, thereby iteratively performing judgment and merging.

[0107] by Figure 3For example, the first edge is edges[0] in graph Q2, and the first tree node in the query tree T is the root node root, which has only one child node. Match the edge edges[0] with the edge in the child node of the root node, and find that the source node color, target node color, and edge color are all the same, that is, the node attribute information and the edge attribute information are the same, then determine that the two can be merged. Since there is only one edge in the second query graph Q2, the child node of the root node can be pointed to the second query subgraph Q2, that is, query→2 is set to indicate that the path from the root node to the child node corresponds to the second query subgraph Q2.

[0108] Similarly, for the third query subgraph Q2, it contains the edges edges[0], edges[1], edges[2], and edges[3]. The numbers in the brackets [] indicate the matching order. The first edge edges[0] is merged with the edge of the child node of the root node (i.e., the second tree node from the top of the query tree T). If the result is that the merge is possible, the second edge edges[1] is merged with the edge of the next-level child node (i.e., the third tree node from the top of the query tree T). If the result is that the merge is possible, the third edge edges[2] is merged with the edge of the next-level child node (i.e., the fourth tree node from the top of the query tree T, see the query tree T on the right side of Q3). If the result is that the merge is not possible, the third edge edges[2] can be added to the query tree T as a new child node, i.e., a child node parallel to the fourth tree node, and the fourth edge edges[3] is continued as the next-level child node of the child node. The last-level leaf node is pointed to the third query subgraph Q3, that is, query→3 is set, which is used to indicate that the path from the root node to the leaf node corresponds to the third query subgraph Q3.

[0109] When creating a tree node of query tree T, no matter whether the query subgraph is the first or not, several edges in the query subgraph need to be added or merged into query tree T as tree nodes in query tree T, which is essentially creating edge data of the tree node.

[0110] For example, when the first edge in a query subgraph is used as a tree node in the query tree T, the edge data of the tree node can be determined based on the edge data of the first edge. The first edge is any edge that needs to be added to the query tree.

[0111] Among them, the edge data corresponding to the tree node may include: the identifier of the tree node and the child nodes of the tree node, and an identifier used to indicate whether the edge of the tree node is the last one in a query subgraph. The identifier can be represented by a pointing parameter (query). When an edge is the last edge in a query subgraph, the pointing parameter is pointed to the query subgraph. In addition, the edge data of the tree node may also include: the node identifier and edge identifier in the edge, as well as edge attribute information and node attribute information, etc. The edge identifier can be used as the identifier of the tree node.

[0112] Generally, in order to make the numbering inside the query tree T consistent, the nodes and edges in the query tree T may be renumbered, that is, the node identifiers and edge identifiers may be re-determined.

[0113] The edge data of a tree node can be recorded through the class of the tree node. Figure 4 A schematic diagram of the class of edge data of a tree node provided in an embodiment. The following edge data are included: integer variable (int) source node identifier (source_id) and target node identifier (target_id), string variable (string) source node property (source_property), target node property (target_property) and edge property (edge_property), integer variable edge identifier (edge_id), and the child node (Edge*[]childs) of the tree node, pointing to parameter (Query*query). edge_id is also used to identify which tree node in the query tree T the edge corresponds to.

[0114] As mentioned above, the node identifiers and edge identifiers in the query tree T can be re-determined. In order to more accurately determine the node identifiers in the query tree during the process of creating the query tree T, a mapping relationship table (id_mapping) can be maintained during the process of merging a query subgraph into the query tree T, in which the mapping relationship is used to record the mapping relationship between the node identifiers in the query subgraph and the node identifiers in the query tree T.

[0115] When determining the edge data of a tree node based on the edge data of the first edge, the following steps can be performed:

[0116] When the node identifier of the first edge is not recorded in the mapping relationship, the node identifier of the tree node is directly generated, and the corresponding relationship between the node identifier in the query subgraph and the node identifier in the query tree T is recorded;

[0117] When the node identifier of the first edge is recorded in the mapping relationship, the node identifier of the tree node is determined based on the node identifier in the tree node corresponding to the node identifier in the mapping relationship. For example, the node identifier in the tree node corresponding to the node identifier in the mapping relationship can be determined as the node identifier of the tree node, thereby avoiding repeated generation of new node identifiers.

[0118] Let's take an example and combine it with Figure 4 The classes in Detail describe the process of merging query graphs.

[0119] Create an empty Edge class as the root node of the query tree, with its attribute "edge_id" set to 0 and the rest empty.

[0120] Define an integer variable max_vertex_id to assist in the generation of tree node identifiers (IDs) in the query tree T and initialize it to 1.

[0121] Define an integer variable max_edge_id to assist in the generation of edge IDs in the query tree T, initialized to 1 because 0 is already occupied by the root node.

[0122] For any query subgraph, perform the following preprocessing:

[0123] Define a temporary pointer parent pointing to the root node in the query tree T, indicating the current parent node (that is, the first tree node mentioned above);

[0124] Create an empty temporary mapping table id_mapping to save the mapping relationship between the node ID (key) in the query subgraph and the node ID (value) in the edge of the tree node in the query tree. Both IDs are integer variables int and are stored in the form of key-value pairs.

[0125] After performing the above preprocessing, for the query subgraph, the query subgraph is merged into the query tree T through the following steps 1_4 to 1_10.

[0126] Step 1_4, traverse each edge in the query subgraph in matching order, and use the current edge as q_edge (that is, the first edge mentioned above).

[0127] Step 1_5, traverse each child node of the pointer parent, and call the current child node edge t_edge.

[0128] Step 1_6, determine whether edge q_edge and edge t_edge can be merged.

[0129] The specific judgment process may include:

[0130] If the source_property of q_edge is different from the source_property of t_edge, return no; otherwise, return yes;

[0131] If the target_property of q_edge is different from the target_property of t_edge, return no; otherwise, return yes;

[0132] If the edge_property of q_edge is different from the edge_property of t_edge, return no; otherwise, return yes;

[0133] If the source_id of q_edge does not exist in the key of id_mapping, return yes. If the source_id of q_edge exists in the key of id_mapping, and if the value of id_mapping[q_edge.source_id] is different from the source_id of t_edge in the class, return no, if they are the same, return yes;

[0134] If the target_id of q_edge does not exist in the key of id_mapping, return yes. If the target_id of q_edge exists in the key of id_mapping, and if the value of id_mapping[q_edge.target_id] is different from the target_id of t_edge in the class, return no; if they are the same, return yes;

[0135] When judging, if any of the above multiple judgment options has a negative result, it means that they cannot be merged. If all the judgment options are positive, it means that they can be merged.

[0136] Step 1_7, if it can be merged, save the mapping relationship of the node ID in the mapping relationship table id mapping, change the pointer parent to point to this edge t_edge, and return to step 1_4 to continue with the next edge q_edge.

[0137] When saving the mapping relationship of node IDs, it can be saved in the following key-value pair format:

[0138] id_mapping[q_edge.source_id]=t_edge.source_id;

[0139] id_mapping[q_edge.target_id]=t_edge.target_id.

[0140] Step 1_8, if the merge is not possible, return to step 1_5 and continue to use the next child node of the pointer parent as the edge t_edge.

[0141] Step 1_9, if the pointer parent does not have a child node that can be merged with the edge q_edge, or the pointer parent has no child node at all, execute the following steps 1_9_1 to 1_9_6.

[0142] Step 1_9_1, directly add the current edge q_edge to the pointer parent->childs[] as the new child node of the parent node.

[0143] Step 1_9_2, set the edge_id in the class of the newly added tree node to the value of max_edge_id, and add 1 to the value of max_edge_id.

[0144] Step 1_9_3, for the newly added tree node, when putting the edge from the query subgraph into the query tree T, the node ID of the edge needs to be changed to the node ID corresponding to the newly added tree node in the query tree T. Specifically, the point ID in the class of the newly added tree node can be modified as follows:

[0145] If the source_id of the edge q_edge exists in the key of id_mapping, modify the source_id of the class of the newly added tree node to the value corresponding to id_mapping[q_edge.source_id].

[0146] If the source_id of the edge q_edge does not exist in the key of id_mapping, set the source_id of the class of the newly added tree node to the value of max_vertex_id, save the corresponding relationship in id_mapping, and increase the max_vertex_id value by 1.

[0147] If the target_id of the edge q_edge exists in the key of id_mapping, modify the target_id of the class of the newly added tree node to the value corresponding to id_mapping[q_edge.target_id].

[0148] If the target_id of the edge q_edge does not exist in the key of id_mapping, set the target_id of the class of the newly added tree node to the value of max_vertex_id, save the corresponding relationship in id_mapping, and increase the max_vertex_id value by 1.

[0149] Step 1_9_4, use the attribute information in the class of edge q_edge as the corresponding attribute information in the class of the newly added tree node, including [source_property], [target_property] and [edge_property] in the class.

[0150] Step 1_9_5, change the pointer parent to point to the newly added tree node in the current query tree.

[0151] Step 1_9_6, return to step 1_4, and take the next edge in the matching order in the query subgraph as q_edge.

[0152] Step 1_10, if the edge q_edge is the last edge of the query subgraph, the query in the class of the corresponding tree node is set to point to the query subgraph.

[0153] The above is a specific example to illustrate the process of merging a query subgraph into a query tree T. After merging several query subgraphs Q into the query tree T, the resulting query tree T can be referred to Figure 3 The rightmost graph in the figure. The edge ID of each tree node is marked next to it, from edge[0] to edge[5]. Figure 3 It can be seen from the embodiment that in the process of merging several query subgraphs Q into a query tree, the edges of the same parts can be pre-set in the same matching order in the front of the several query subgraphs Q, so as to more conveniently merge the same parts into the trunk of the query tree T.

[0154] After merging several query subgraphs Q into the query tree T, the subgraph matching process also changes accordingly. Instead of taking the next edge from edges[] in the query subgraphs Q, the next edge is taken from the current tree node of the query tree T.

[0155] The specific implementation of step 2 is described below. In the above step 2_1, when performing a subgraph query in the data graph G stored in the graph database based on the trunk of the query tree T, the following steps can be performed:

[0156] When the edge of the first tree node is the to-be-queried edge of the trunk, a subgraph query is performed on the to-be-queried edge in the data graph G based on the subgraph obtained by matching the edge of the parent node of the first tree node in the data graph G. For example, the edge of the first tree node is matched within the subgraph range obtained by matching the edge of the parent node of the first tree node in the data graph G, thereby gradually narrowing the query range.

[0157] Furthermore, in step 2_2, when performing subgraph queries based on the branch parts of the query tree T respectively based on the first query result, the subgraph queries can be performed based on the branch parts of the query tree T respectively within the scope included in the first query result. When the edge of the first tree node is the to-be-queried edge of the branch part, a subgraph query is performed on the to-be-queried edge in the data graph G based on the subgraph obtained by querying the edge of the parent node of the first tree node in the data graph.

[0158] When the first tree node is the last tree node in the corresponding path of the first query subgraph Q1 in the query tree T, the query result corresponding to the first query subgraph Q1 is determined based on the subgraph query result of the subgraph to be queried in the data graph G. For example, the subgraph query result of the last tree node in the data graph G can be directly used as the query result corresponding to the first query subgraph Q1.

[0159] The first tree node is any tree node in the query tree T. When the root node does not contain an edge, the first tree node may be one or more of all tree nodes except the root node.

[0160] by Figure 3 Take the query tree T obtained on the right side as an example. Figure 3 For the rightmost query tree T, perform subgraph query on the edges of the tree nodes in the data graph G in the order from the trunk to the branches of the query tree T. For example, perform subgraph query on the tree node edge[1] in the data graph G, and obtain matching result 1. Since the query in edge[1] points to the second query subgraph Q2, the matching result 1 is the query result corresponding to the second query subgraph Q2 in the data graph G.

[0161] Next, based on the matching result 1, a subgraph query is performed on the tree node edge[2] in the data graph G to obtain matching result 2. Based on the matching result 2, a subgraph query is performed on the tree node edge[3] in the data graph G to obtain matching result 3. Since the query in edge[3] points to the first query subgraph Q1, the matching result 3 is the query result corresponding to the first query subgraph Q1 in the data graph G.

[0162] Next, based on matching result 2, a subgraph query is performed on the tree node edge[4] in the data graph G to obtain matching result 4. Based on matching result 4, a subgraph query is performed on the tree node edge[5] in the data graph G to obtain matching result 5. Since the query in edge[5] points to the third query subgraph Q3, the matching result 5 is the query result corresponding to the third query subgraph Q3 in the data graph G.

[0163] From the above example, it can be seen that the subgraph query results of the tree nodes edge[1] and edge[2] are reused in the subgraph query process. The embodiment avoids repeated matching of the edge in the data graph G, reduces resource waste, and saves the matching time of the user subgraph, so that the query results can be obtained more efficiently. In the field of transaction risk control, efficient subgraph query can improve the efficiency of risk prediction.

[0164] In this specification, the term "first" in terms such as the first query subgraph, the first tree node and the first edge, as well as the corresponding "second" (if any) in the text, are merely for the convenience of distinction and description and do not have any limiting meaning.

[0165] In this specification, computing equipment and risk control platform can be implemented by any device, equipment, platform, equipment cluster, etc. with computing and processing capabilities.

[0166] The foregoing describes certain embodiments of the present specification, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims may be performed in an order different from that in the embodiments, and the desired results may still be achieved. In addition, the processes depicted in the accompanying drawings do not necessarily have to be performed in the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0167] Figure 5 A schematic block diagram of a subgraph query device provided in an embodiment. Figure 2 The device 500 includes:

[0168] The subgraph acquisition module 510 is configured to acquire a plurality of query subgraphs to be queried; the plurality of query subgraphs include nodes and edges, and attribute information of the nodes and edges;

[0169] The preliminary query module 520 is configured to perform a preliminary query in the data graph stored in the graph database based on the same part between the plurality of query subgraphs, and obtain a first query result of the same part; the same part is contained in the plurality of query subgraphs and is a subgraph corresponding to the same edge of the plurality of query subgraphs;

[0170] The remaining query module 530 is configured to perform subgraph queries in the data graph based on the remaining parts of the plurality of query subgraphs on the basis of the first query result, to obtain query results for each query subgraph.

[0171] In one embodiment, the device 500 also includes: a query tree merging module 540, configured to obtain the same parts between the several query subgraphs based on the following method: merging the several query subgraphs into a query tree, and the trunk of the query tree is divided into the same parts between the several query subgraphs.

[0172] In one implementation, the remaining portion of any query subgraph is a branch portion of the query tree.

[0173] In one embodiment, any first query subgraph includes a number of edges and their matching order, and the edges included in the same part have the same corresponding matching order in different query subgraphs; the query tree merging module 540 is specifically configured to: use the edges in the first query subgraph as tree nodes in the query tree, and merge the first query subgraph into the query tree according to the matching order, so that the several edges included in the same part are sequentially merged into the trunk of the query tree.

[0174] In one embodiment, in the first query subgraph, the edges included in the same portion have a matching order that is prior to the matching order of other edges. The query tree merging module 540, when merging the first query subgraph into the query tree, includes:

[0175] The first query subgraph is merged into the query tree according to the matching order of the edges in the first query subgraph and the order from the root node to the leaf nodes in the query tree.

[0176] In one implementation, the query tree merging module 540, when merging the first query subgraph into the query tree, includes:

[0177] When the first query subgraph is the first one, according to the matching order, the edges in the current matching order in the first query subgraph are used as parent nodes in the query tree, and the edges in the next matching order are used as child nodes of the parent node.

[0178] In one implementation, the query tree merging module 540, the step of merging the first query subgraph into the query tree, includes:

[0179] When the first query subgraph is not the first one, determining a first edge from the first query subgraph according to the matching order, determining a first tree node from the query tree according to the order from the parent node to the child node, and performing iterative merging in the following manner:

[0180] Determine whether the first edge can be merged with an edge in a child node of the first tree node;

[0181] If yes, updating the first edge and the first tree node;

[0182] If not, the first edge and other edges in the first query subgraph are used in sequence as child nodes of each level of the first tree node.

[0183] In one implementation, the query tree merging module 540, when determining whether the first edge and the child node of the first tree node can be merged, includes:

[0184] When the first edge matches an edge of any child node included in the first tree node, it is determined that the nodes can be merged.

[0185] In one embodiment, the tree nodes in the query tree have corresponding edge data, and the edge data includes: an identifier of the tree node and the child nodes of the tree node, and an identifier for indicating whether the edge of the tree node is the last one in a query subgraph. When executing the first edge in a query subgraph as a tree node in the query tree, the query tree merging module 540 includes: determining the edge data of the tree node based on the edge data of the first edge.

[0186] In one embodiment, the edge data of the tree node further includes: a node identifier and an edge identifier corresponding to the edge; the edge identifier is used as the identifier of the tree node. The query tree merging module 540, when determining the edge data of the tree node based on the edge data of the first edge, includes:

[0187] When the node identifier of the first edge is recorded in the mapping relationship library, the node identifier of the tree node is determined based on the node identifier in the tree node corresponding to the node identifier in the mapping relationship library; the mapping relationship library is used to record the mapping relationship between the node identifier in the query subgraph and the node identifier in the query tree.

[0188] In one embodiment, the preliminary query module 520 is specifically configured to perform subgraph queries in the data graph stored in the graph database based on the trunk portion of the query tree; the remaining query module 530 is specifically configured to perform subgraph queries based on the branch portions of the query tree respectively on the basis of the first query result.

[0189] In one embodiment, the preliminary query module 520, when performing a subgraph query in the data graph stored in the graph database based on the trunk part of the query tree, includes: when the edge of the first tree node is the edge to be queried, based on the edge of the parent node of the first tree node, querying the subgraph obtained in the data graph, and performing a subgraph query on the edge to be queried in the data graph.

[0190] In one embodiment, the remaining query module 530, when performing a subgraph query in the query graph based on the branch part of the query tree, includes: when the first tree node is the last tree node in the corresponding path of the first query subgraph in the query tree, determining the query result corresponding to the first query subgraph based on the subgraph query result of the first tree node in the data graph.

[0191] The above device embodiments correspond to the method embodiments. For specific descriptions, please refer to the description of the method embodiments, which will not be repeated here. The device embodiments are obtained based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments. For specific descriptions, please refer to the corresponding method embodiments.

[0192] The present specification also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute Figures 1 to 4 Any of the methods described above.

[0193] The embodiment of the present specification also provides a computing device, including a memory and a processor, wherein the memory stores an executable code, and when the processor executes the executable code, Figures 1 to 4 Any of the methods described above.

[0194] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the storage medium and computing device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0195] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present invention may be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions may be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.

[0196] The specific implementation methods described above further describe the purpose, technical solutions and beneficial effects of the embodiments of the present invention in detail. It should be understood that the above description is only a specific implementation method of the embodiments of the present invention and is not intended to limit the scope of protection of the present invention. Any modification, equivalent replacement, improvement, etc. made on the basis of the technical solution of the present invention shall be included in the scope of protection of the present invention.

Claims

1. A subgraph query method, comprising: Acquire several query subgraphs to be queried; the several query subgraphs include nodes and edges, and attribute information of the nodes and edges; Based on the same parts among the plurality of query subgraphs, a preliminary query is performed in a data graph stored in a graph database to obtain a first query result for the same parts; The same part is contained in the plurality of query subgraphs and is a subgraph corresponding to the same edge of the plurality of query subgraphs; On the basis of the first query result, subgraph queries are performed in the data graph based on the remaining parts of the several query subgraphs respectively to obtain query results of each query subgraph.

2. The method according to claim 1, wherein: The common parts among the plurality of query subgraphs are obtained based on the following method: The plurality of query subgraphs are merged into a query tree; and a trunk of the query tree is divided into the same parts among the plurality of query subgraphs.

3. The method according to claim 2, wherein: The remaining part of any query subgraph is the branch part of the query tree.

4. According to the method of claim 2, any first query subgraph comprises a plurality of edges and their matching order, and the edges comprised in the same part have the same corresponding matching order in different query subgraphs; the step of merging the plurality of query subgraphs into a query tree comprises: The edges in the first query subgraph are used as tree nodes in the query tree, and the first query subgraph is merged into the query tree according to the matching order, so that several edges included in the same part are sequentially merged into the trunk of the query tree.

5. The method according to claim 4, wherein in the first query subgraph, the edges included in the same portion have a matching order that is prior to the matching order of other edges; and the step of merging the first query subgraph into the query tree comprises: The first query subgraph is merged into the query tree according to the matching order of the edges in the first query subgraph and the order from the root node to the leaf nodes in the query tree.

6. The method according to claim 5, when the first query subgraph is the first one, the step of merging the first query subgraph into the query tree comprises: According to the matching order, the edges of the current matching order in the first query subgraph are used as parent nodes in the query tree, and the edges of the next matching order are used as child nodes of the parent node.

7. The method according to claim 6, when the first query subgraph is not the first one, the step of merging the first query subgraph into the query tree comprises: Determine a first edge from the first query subgraph according to the matching order, determine a first tree node from the query tree in an order from a parent node to a child node, and perform iterative merging in the following manner: Determine whether the first edge can be merged with an edge in a child node of the first tree node; If yes, updating the first edge and the first tree node; If not, the first edge and other edges in the first query subgraph are used in sequence as child nodes of each level of the first tree node.

8. The method according to claim 7, wherein the step of determining whether the first edge and the child nodes of the first tree node can be merged comprises: When the first edge matches an edge of any child node included in the first tree node, it is determined that the nodes can be merged.

9. According to the method of claim 4, the tree nodes in the query tree have corresponding edge data, and the edge data includes: an identifier of the tree node and the child nodes of the tree node, and an identifier for indicating whether the edge of the tree node is the last one in a query subgraph; When executing the step of using the first edge in a query subgraph as a tree node in the query tree, it includes: Based on the edge data of the first edge, edge data of the tree node is determined.

10. The method according to claim 9, wherein the edge data of the tree node further comprises: The node ID and edge ID corresponding to the edge; The edge identifier is used as an identifier of the tree node; The step of determining the edge data of the tree node based on the edge data of the first edge comprises: When the node identifier of the first edge is recorded in the mapping relationship library, determining the node identifier of the tree node based on the node identifier in the tree node corresponding to the node identifier in the mapping relationship library; The mapping relationship library is used to record the mapping relationship between the node identifiers in the query subgraph and the node identifiers in the query tree.

11. The method according to claim 3, wherein the preliminary inquiry comprises: Performing a subgraph query on the data graph stored in the graph database based on the trunk of the query tree; The step of performing subgraph query in the data graph based on the remaining parts of the several query subgraphs based on the first query result includes: performing subgraph query based on the branch parts of the query tree based on the first query result.

12. According to the method of claim 11, the step of performing subgraph query in the data graph stored in the graph database based on the trunk part of the query tree comprises: When the edge of the first tree node is an edge to be queried, a subgraph query is performed on the edge to be queried in the data graph based on a subgraph obtained by querying the edge of the parent node of the first tree node in the data graph.

13. The method according to claim 12, wherein the step of performing subgraph query based on the branch part of the query tree comprises: When the first tree node is the last tree node in the corresponding path of the first query subgraph in the query tree, a query result corresponding to the first query subgraph is determined based on the subgraph query result of the first tree node in the data graph.

14. A subgraph query device, comprising: A subgraph acquisition module, configured to acquire a plurality of query subgraphs to be queried; the plurality of query subgraphs include nodes and edges, and attribute information of the nodes and edges; A preliminary query module is configured to perform a preliminary query in a data graph stored in a graph database based on the same parts between the query subgraphs to obtain a first query result of the same parts; the same parts are contained in the query subgraphs and are subgraphs corresponding to the same edges of the query subgraphs; The remaining query module is configured to perform subgraph queries in the data graph based on the remaining parts of the several query subgraphs on the basis of the first query result, so as to obtain query results for each query subgraph.

15. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 13.

16. A computing device comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 13 is implemented.

Citation Information

Patent Citations

  • Data query method and device

    CN112749189A

  • Method, device and equipment for data search

    CN115408427A

  • Method and device for merging based on graph similarity and storage medium

    CN116680451A

  • Self-adaptive text generation method and system based on knowledge graph

    CN117932088A

  • Subtree for an aggregation system

    US8504733B1