Graph data storage traversal method and device, equipment and medium

By separating the vertices and edges of graph data and storing them in a document-based database, and adopting a queue-driven construction algorithm and type dimension traversal method, the problem that traditional graph structure traversal cannot handle vertex hierarchical relationships is solved, and efficient and flexible graph data storage and traversal is achieved.

CN120632162APending Publication Date: 2025-09-12AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510723062.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-30
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

Traditional graph structure traversal methods cannot effectively handle the hierarchical relationships between vertices in the graph structure in bank remittance scenarios, resulting in the inability to traverse the graph layer by layer according to the hierarchical dimension to obtain a topology that meets the requirements.

Method used

The vertices and edges of the graph data are separated and stored in a document-based database. A queue-driven construction algorithm is used to generate edge relationships between vertices. The graph data is traversed through the type dimension. The type set, starting point set, and end point set of the ring are preset. The starting point cannot be accessed repeatedly, while the end point can be accessed multiple times. A traversal algorithm for cyclic graphs is designed.

Benefits of technology

It achieves efficient storage and traversal of graph structure data with hierarchical relationships between vertices, reduces data transmission time, improves program flexibility and adaptability, and avoids dead loops and repeated access.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120632162A_ABST
    Figure CN120632162A_ABST
Patent Text Reader

Abstract

The invention discloses a graph data storage traversal method and device, equipment and a medium. The method comprises the following steps: separately storing vertexes and edges of graph data in a document database, and generating an edge relationship between the vertexes based on a queue-driven construction algorithm; traversing the graph data according to a type dimension from a set initial vertex, managing nodes to be processed through a queue to be accessed, and avoiding repeated processing of types through an accessed type set; a type set, a starting point set and an end point set of a ring are preset, and the ring is a vertex group formed by vertexes which are connected end to end and formed based on the edge relation; when it is detected that a ring exists in the traversal path, the ring is processed, the starting point is controlled not to be repeatedly accessed, and the terminal point is controlled to be repeatedly accessed. By means of the scheme, storage and traversal of graph structure data with the upper-lower hierarchical relation between the vertexes can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a graph data storage traversal method, apparatus, device and medium. Background Art

[0002] With the rapid development of technologies such as the internet and social media, graph-structured data has been widely used in various complex systems, including social networks, recommendation systems, and bioinformatics. In traditional graph structures, there is no hierarchical relationship between vertices. Graph traversal can be accomplished using breadth-first search (BFS) or depth-first search (DFS).

[0003] However, in the bank remittance scenario, remittance accounts are classified by category (such as small and micro enterprises, state-owned enterprises, personal accounts, etc.). At this time, the vertices in the graph structure have a hierarchical relationship. The traditional traversal method cannot traverse the graph layer by layer based on the hierarchy to obtain a topological graph that meets the requirements.

[0004] Therefore, a method is needed to store and traverse graph structure data with hierarchical relationships between vertices. Summary of the Invention

[0005] The present invention provides a graph data storage and traversal method, apparatus, device and medium to achieve storage and traversal of graph structure data with hierarchical relationships between vertices.

[0006] According to one aspect of the present invention, a graph data storage traversal method is provided, comprising:

[0007] Separate the vertices and edges of graph data and store them in a document-based database. Generate edge relationships between vertices based on a queue-driven construction algorithm.

[0008] Starting from the set initial vertex, traverse the graph data according to the type dimension, manage the nodes to be processed through the to-be-processed queue, and avoid repeated processing of types through the visited type set;

[0009] A set of ring types, a set of starting points, and a set of end points are preset, wherein the ring is a vertex group consisting of the first connected vertices formed based on the edge relationship; when a ring is detected in the traversal path, the ring is processed to control the starting point to not be repeatedly visited, while the end point can be visited multiple times.

[0010] Optionally, the vertices are stored as documents containing the following fields:

[0011] The ID of the entity data is used to uniquely identify the vertex entity;

[0012] The name of the entity data, used to identify the name of the vertex entity;

[0013] Basic information about entity data, including the entity data type and dynamic extended attributes. The entity data type is used to identify the category to which the vertex belongs, and the dynamic extended attributes are used to store additional attributes of the vertex.

[0014] The edges are stored as documents containing the following fields:

[0015] Source type, used to identify the category of the starting point of the edge;

[0016] Source entity ID, used to identify the starting entity of the edge;

[0017] Target type, used to identify the category of the end point of the edge;

[0018] Target entity ID list, used to store the unique identifier list of the end entities of the edge.

[0019] Optionally, the queue-driven construction algorithm generates edge relationships between vertices, including:

[0020] Initialize the queue of types to be constructed and add the root type;

[0021] Loop out the current type in the queue, get its adjacent type list and all entities;

[0022] For each entity, query its associated entities with adjacent types and generate edge data; if the adjacent type has not been processed, add it to the queue for further processing.

[0023] Optionally, traversing the graph data by type dimension includes:

[0024] Initialize the result set, queue to be accessed, and set of accessed types;

[0025] Add the initial vertex to the queue and result set, take out the first node of the queue and mark its type as visited;

[0026] Query the adjacent type entities of the current node and add the entities of unvisited types to the queue and result set;

[0027] Repeat the above steps until the queue is empty.

[0028] Optionally, perform ring detection as follows:

[0029] A list of preset ring rules, each of which defines a type set, a start point set, and an end point set;

[0030] During the traversal process, when the type of the current node belongs to the type set of a certain ring rule and other types of nodes of the ring rule have been visited, the ring detection logic is triggered;

[0031] Check whether the current node belongs to the starting point set of the ring rule. If it does and has been visited, then determine that the path forms a ring.

[0032] Optionally, the processing the ring includes:

[0033] When a loop is detected, if the current node belongs to the starting point set of the loop rule and has been visited, the subsequent path traversal of this node is skipped;

[0034] If the current node belongs to the endpoint set of the ring rule, it is allowed to continue visiting and marked as a node in the ring to limit its subsequent path to only visit the types within the ring rule;

[0035] If the current node is neither the starting point nor the end point, continue traversing and record the loop path;

[0036] Whether a node participates in the ring traversal is determined by the ring tag field in the vertex index, wherein the tag field includes whether the node belongs to the starting point set and whether the node has been visited.

[0037] Optionally, the method further includes:

[0038] Converting the type set of the ring rule into a hash table structure;

[0039] Preprocessing the starting point set and the ending point set to generate a query index for determining the set to which a node belongs during ring detection;

[0040] The traversal path constraints of each ring rule are cached to avoid repeated parsing of rule configurations during the traversal process.

[0041] According to another aspect of the present invention, a graph data storage and traversal device is provided, comprising:

[0042] The edge relationship generation unit is used to store the vertices and edges of the graph data separately in a document-based database and generate edge relationships between vertices based on a queue-driven construction algorithm;

[0043] A traversal unit, configured to traverse the graph data according to the type dimension starting from the set initial vertex, manage the nodes to be processed through the to-be-accessed queue, and avoid repeated processing of types through the visited type set;

[0044] A ring processing unit is used to preset a set of ring types, a set of starting points, and a set of end points, wherein the ring is a vertex group consisting of the first connected vertices formed based on the edge relationship; when a ring is detected in the traversal path, the ring is processed to control the starting point to not be repeatedly visited and the end point to be visited multiple times.

[0045] According to another aspect of the present invention, an electronic device is provided, comprising:

[0046] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the graph data storage traversal method described in any embodiment of the present invention.

[0047] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the graph data storage traversal method described in any embodiment of the present invention when executed.

[0048] The technical solution of the embodiment of the present invention abstracts the common structure of graph data storage and stores graph data in the form of separating vertex data and edge data, thereby reducing data transmission and the time required for graph traversal; it proposes the concept of start and end point sets for cyclic graphs, and designs and implements a traversal algorithm for such graphs, which increases the flexibility and adaptability of the program compared to using traditional graph databases.

[0049] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the technical solutions in 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. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0051] Figure 1 This is a flowchart of a graph data storage and traversal method provided by the first embodiment of the present invention;

[0052] Figure 2 This is a cyclic graph applicable to the first embodiment of the present invention;

[0053] Figure 3 This is a flowchart of a graph data traversal method provided by the second embodiment of the present invention;

[0054] Figure 4 yes Figure 4 This is a flow chart of a ring detection method provided in Example 3 of the present invention;

[0055] Figure 5 This is a flow chart of a ring processing method provided by Example 3 of the present invention;

[0056] Figure 6 This is a structural diagram of a graph data storage and traversal device provided by the third embodiment of the present invention;

[0057] Figure 7 It is a structural diagram of an electronic device that implements the graph data storage and traversal method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0058] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0059] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0060] Example 1

[0061] Figure 1 This is a flowchart of a graph data storage and traversal method provided by the first embodiment of the present invention. This embodiment is applicable to the storage and traversal of graph data with hierarchical relationships. The method can be executed by a graph data storage and traversal device. The graph data storage and traversal device can be implemented in the form of hardware and / or software. The graph data storage and traversal device can be configured in an electronic device. Figure 1 As shown, the method includes:

[0062] S110 , separate the vertices and edges of the graph data and store them in a document-based database, and generate edge relationships between vertices based on a queue-driven construction algorithm.

[0063] A vertex represents each data node in a graph-structured data structure, while an edge represents the relationship between data vertices in the graph-structured data structure. Separate storage decouples the entity (vertex) from how entities are connected (edges). Each vertex is a separate document, and each edge records the connection between the source and target vertices. Document-based databases support dynamic fields: Vertices can have new attributes added at any time without affecting the edge structure. Furthermore, indexing fields can be used to accelerate subsequent relationship queries.

[0064] Because graph data may contain multiple entity types (such as accounts, transactions, and customers), they must be processed sequentially to avoid circular dependencies. Queues ensure that relationship generation tasks for each type are executed in an orderly manner. The queue construction process includes: adding a root type (such as a business account) to the queue; removing "business account" from the queue and querying all entities of that type (such as ACC001 and ACC002); for each entity, identifying its associated adjacent types (such as transfer transactions); generating edge data (such as ACC001 → TX001) and storing it in the edge index; if an adjacent type (such as a transfer transaction) has not been processed, it is added to the end of the queue; and until the queue is empty, all relationships of all types have been generated.

[0065] Separate the static attributes of graph data from its dynamic relationships, and solve scalability issues through the flexibility of document databases; utilize queue-driven task flows to transform complex graph construction into schedulable type processing units.

[0066] In this embodiment of the present invention, vertices are stored as documents containing the following fields:

[0067] The ID of the entity data is used to uniquely identify the vertex entity;

[0068] The name of the entity data, used to identify the name of the vertex entity;

[0069] Basic information about entity data, including the entity data type and dynamic extended attributes. The entity data type is used to identify the category to which the vertex belongs, and the dynamic extended attributes are used to store additional attributes of the vertex.

[0070] For example, the ID of the entity data is PCID, the name of the entity data is PC server No. 1, and the basic information of the entity data is the relevant attributes of PC server No. 1, where PCID is the primary key of the entity, the name of the entity data is the name of the resource entity, and the basic information of the entity data is other attributes of the entity. All resource types can be stored according to this structure, and different fields between resource types can be added or reduced at will in the basic information field of the entity data. It is universal, and all resource entities can share a structure for storage.

[0071] Edges are stored as documents containing the following fields:

[0072] Source type, used to identify the category of the starting point of the edge;

[0073] Source entity ID, used to identify the starting entity of the edge;

[0074] Target type, used to identify the category of the end point of the edge;

[0075] Target entity ID list, used to store the unique identifier list of the end entities of the edge.

[0076] For example, the source type is server, the source entity ID is PCID, the target type is virtual machine, and the target entity ID list is ["virtual machine ID 1", "virtual machine ID 2"]. Each data item represents an edge in the graph. The source type indicates the resource entity from which the edge originates, the source entity ID is the ID of that resource entity, the target type indicates the resource type to which the edge reaches, and the target entity ID list lists the entities of the target type that this entity can reach. Storing the graph in this format provides great flexibility, whether adding new entity resource types or adding / modifying edges in the graph.

[0077] In an embodiment of the present invention, the edge relationship between vertices is generated based on a queue-driven construction algorithm, including:

[0078] Initialize the queue of types to be constructed and add the root type;

[0079] Loop out the current type in the queue, get its adjacent type list and all entities;

[0080] For each entity, query its associated entities with adjacent types and generate edge data; if the adjacent type has not been processed, add it to the queue for further processing.

[0081] Create a queue of pending types and add the root type (such as a business account) as the initial task to the queue. The root type is usually the core entity in the business, such as an account in a financial system, a user in a social network, and so on.

[0082] Loop through the queue to remove the head type and obtain all entities of that type. For each entity, search for its associated adjacent types (types associated with the current type are considered adjacent types). Generate edge relationships between the current entity and the adjacent types. If the adjacent type has not been processed, add it to the end of the queue. For example, to obtain a list of adjacent types: determine the downstream associated types of the current type using predefined type association rules, such as corporate account → transfer transaction → personal account. For each entity, such as corporate account ACC001, use business logic to search for its associated adjacent type entities, such as all transfer transactions TX001 and TX002 initiated by the account.

[0083] By querying the association relationship between the current type of entity and the adjacent types, all types of entities associated with the current entity are obtained for edge construction; according to the specified generation order, the queue is used to construct and store the edge information for each entity of each type.

[0084] S120 , starting from the set initial vertex, traverse the graph data according to the type dimension, manage the nodes to be processed through the to-be-accessed queue, and avoid repeated processing of types through the visited type set.

[0085] The core of the type-based traversal strategy is to control by type rather than vertex granularity, and to achieve efficient hierarchical traversal through queues and collections. The specific execution logic is as follows:

[0086] Add the initial vertex (e.g., corporate account: ACC001) to the queue to be visited, mark its type (e.g., corporate account) as visited, and store it in the set of visited types. Remove the current node (e.g., ACC001) from the queue and query all its associated nodes of adjacent types (e.g., TX001 and TX002 of transfer transaction types). For each associated node, if its type (e.g., transfer transaction) has not been visited, mark that type as visited and add the associated node to the queue. Even if other nodes of the same type (e.g., TX003) are encountered later, the global processing logic for that type will no longer be triggered because the type has been marked. Prioritize processing nodes of new types rather than all nodes of the same type. For example, after processing the transfer transaction type associated with ACC001, immediately switch to the new type associated with the transfer transaction (e.g., personal account) rather than continuing to process other corporate account nodes.

[0087] S130. Preset a set of ring types, a set of starting points, and a set of end points, wherein the ring is a vertex group consisting of the first connected vertices formed based on the edge relationship; when a ring is detected in the traversal path, process the ring to control the starting point to not be repeatedly visited and the end point to be visited multiple times.

[0088] Graph data can be categorized as acyclic or cyclic. A circular graph is defined as a set of vertices connected end-to-end within a series of edges found during a graph traversal. This set of vertices is called a cycle. To topologically sort an acyclic graph, simply traverse each resource sequentially based on its entity type, preventing duplicate access to a resource. However, when a cycle exists in the graph, traversing based on the entity type dimension can lead to ambiguous results. Figure 2 is a cyclic graph applicable to the first embodiment of the present invention, such as Figure 2As shown in the figure, three resource types, ABC, form a ring. Type A has one vertex, A1; type B has two vertices, B1 and B2; and type C has three vertices, C1, C2, and C3. Traversal begins by resource type, starting with A1. After type A has accessed type B, it enqueues type B. Two scenarios can occur. In the first scenario, thread 1 switches to the wait state, and thread 2 dequeues B and begins accessing C. When thread 1 wakes up, it discovers that C has already been accessed, thus completing the graph traversal. Finally, the path from A to C has not been accessed, and the returned search set is {A1, B1, B2, C2, C3}. In the second scenario, thread 2 switches to the wait state, and thread 1 continues accessing C. When thread 2 wakes up, it discovers that C has already been accessed, thus completing the graph traversal and returning the search set {A1, B1, B2, C1}. Both scenarios can result in data omissions or bias, which can affect subsequent access results.

[0089] The embodiments of the present invention introduce the concepts of starting and ending sets to address the problem of loops. During graph data traversal, a set of loop types (combinations of vertex types that constitute a loop), a starting set (vertices in the loop that cannot be accessed repeatedly), and an ending set (vertices in the loop that can be accessed multiple times) are predefined. A loop here refers to a closed loop of vertices connected by edge relationships (e.g., vertex A→B→C→A). When a loop is detected in a traversal path, the following control rules are implemented: once a vertex in the starting set has been visited, it is no longer allowed to be accessed again in subsequent paths to avoid infinite loops; however, vertices in the ending set are allowed to be accessed multiple times to ensure the integrity of valid paths within the loop. For example, in a loop of corporate account → transfer transaction → personal account → corporate account, the corporate account is set as the starting set and the personal account as the ending set. After traversing to the personal account, the associated payment records can be accessed, but the accessed corporate account will not be returned. This prevents loop traversal while preserving the business relationships within the loop.

[0090] The technical solution of the embodiment of the present invention abstracts the common structure of graph data storage and stores graph data in the form of separating vertex data and edge data, thereby reducing data transmission and the time required for graph traversal; it proposes the concept of start and end point sets for cyclic graphs, and designs and implements a traversal algorithm for such graphs, which increases the flexibility and adaptability of the program compared to using traditional graph databases.

[0091] Example 2

[0092] Figure 3 This is a flowchart of a graph data traversal method provided by the second embodiment of the present invention. This embodiment further explains the above-mentioned first embodiment. Figure 3 As shown, the method includes:

[0093] S310: Initialize the result set, the queue to be accessed, and the set of accessed types.

[0094] During the graph data traversal process, the initialization operation is first performed to create a result set for storing the traversal results, a queue for managing the nodes to be processed, and a set of accessed types for recording the processed types.

[0095] S320: Add the initial vertex to the queue and the result set, take out the first node of the queue and mark its type as visited.

[0096] Add the initial vertex to the queue to be visited and the result set at the same time, then take the node from the head of the queue and mark the type of the node as visited to avoid subsequent repeated processing of the same type.

[0097] S330: Query the adjacent type entities of the current node, add the entities of the unvisited type to the queue and result set, and repeat until the queue is empty.

[0098] Query the adjacent entities of the current node. If the adjacent entities have not been visited, add them to the queue and result set. This cycle repeats, repeatedly extracting nodes from the queue, marking their types, querying adjacent entities, and adding them to the queue until the queue is empty, completing the entire graph data traversal. This approach manages the order of node access through the queue and controls the number of type processing times using the visited type set, ensuring efficient and complete traversal.

[0099] If there is no cycle in the graph, each resource type in the graph will be accessed and only needs to be accessed once to get the desired result. When there is a cycle in the graph, it is necessary to combine the business context to determine whether to control the type nodes in the cycle. For example, even if there is a cycle, it will not affect the access results and it can be regarded as an acyclic graph. If there is an impact, it is necessary to determine the entrance and exit of the cycle. In the process of accessing the node, it is determined whether the current node has been visited and whether it is in the cycle. If it is in the cycle, find the starting set and end point set corresponding to the cycle structure we preset in advance (for example, there are cycles A→(B, C), B→D, C→D in a directed graph, then a cycle can be formed from A, B, C, D, the starting set of the cycle is [A], and the end point set is [D]). Using the rules of the two sets as the direction, we can ensure that we get the correct data without falling into an endless loop of repeated access.

[0100] Example 3

[0101] Figure 4 This is a flow chart of a ring detection method provided by the third embodiment of the present invention. This embodiment further explains the above-mentioned first embodiment. Figure 4 As shown, the method includes:

[0102] S410 , a preset ring rule list, each ring rule defining a type set, a start point set, and an end point set.

[0103] In graph data processing, a preset list of ring rules is a set of configurations used to manage potential circular paths within a graph. Each ring rule consists of three core components: a type set that defines the vertex type combinations that form a ring, such as the type combination of a business account → a transfer transaction → a personal account → a business account. This is used to identify whether a ring has formed during traversal. A starting point set specifies the vertices in the ring that cannot be accessed repeatedly, typically the starting node of the ring, to prevent traversal from falling into an infinite loop. An end point set specifies the vertices in the ring that can be accessed repeatedly, ensuring the normal traversal of valid paths within the ring.

[0104] S420: During the traversal process, when the type of the current node belongs to a type set of a certain ring rule and other type nodes of the ring rule have been visited, the ring detection logic is triggered.

[0105] As mentioned above, during the traversal of graph data, several loop rules are pre-set, and each rule contains a set of types that constitute a loop. When traversing to a certain node, if the node type belongs to the type set of a certain loop rule, and other types of nodes in the loop rule have already been visited, this means that the current traversal path may have formed a loop. For example, starting from a corporate account, passing through a transfer transaction, a personal account, and then returning to the corporate account, the system will trigger the loop detection logic to determine whether the current path needs to be looped to avoid falling into an infinite loop or repeated traversal. This process is similar to navigation, where the system determines whether it has entered a loop based on the route it has traveled and the current location and triggers the corresponding detour strategy.

[0106] S430: Check whether the current node belongs to the starting point set of the ring rule. If it does and has been visited, determine that the path forms a ring.

[0107] In graph data traversal, each preset ring rule clearly specifies a starting point set. When traversing to a certain node, check whether the node belongs to the starting point set of a certain ring rule. If the node does belong to the starting point set and has been visited before, it means that the current traversal path has formed a closed loop (for example, starting from the starting point node A, passing through a series of nodes and returning to A). At this time, it can be determined that the path constitutes a ring, and the corresponding ring processing mechanism needs to be triggered (such as skipping the path that repeatedly visits the starting point) to prevent the traversal from falling into an infinite loop.

[0108] Figure 5 This is a flow chart of a ring processing method provided by the third embodiment of the present invention. Figure 5 As shown, the method includes:

[0109] S510: When a loop is detected, if the current node belongs to the starting point set of the loop rule and has been visited, skip the subsequent path traversal of the node.

[0110] If the current node belongs to the starting point set of the ring rule and has been visited, it indicates that the traversal path has formed a closed loop. In this case, the subsequent path traversal of this node is skipped to avoid an infinite loop. For example, if corporate account A has been visited as a starting point, the associated edge will be ignored when it is encountered again to prevent the path from corporate account A to transfer transaction from being repeated.

[0111] S520: If the current node belongs to the endpoint set of the ring rule, it is allowed to continue to be accessed and marked as an in-ring node to limit its subsequent path to only access types within the ring rule.

[0112] If the current node belongs to the end point set of the ring rule, it is allowed to continue to access the node, but it will be marked as an in-ring node, restricting its subsequent path to only access types within the ring rule. For example, if personal account B is the end point of the ring, after accessing it, you can still continue to access its associated payment records (if the payment records belong to the ring rule type), but you cannot access financial product types outside the ring, ensuring that traversal is carried out effectively within the ring.

[0113] S530: If the current node is neither the starting point nor the end point, continue traversing and record the loop path.

[0114] If the current node is neither the starting point nor the end point, the traversal will continue normally, but the path information of the current ring, such as the type and order of the nodes passed through, will be recorded for subsequent business analysis, such as tracking the flow of funds.

[0115] S540 , judging whether the node participates in the ring traversal through the ring tag field in the vertex index, where the tag field includes whether the node belongs to the starting point set and whether the node has been visited.

[0116] The ring tags stored in the vertex index can quickly determine whether a node belongs to the starting set or has been visited by the ring traversal, avoiding real-time query rule configuration and improving detection efficiency.

[0117] In an embodiment of the present invention, the method may further include:

[0118] Convert the type set of ring rules into a hash table structure;

[0119] Preprocess the starting and ending sets to generate a query index, which is used to determine the set to which a node belongs during ring detection;

[0120] Cache the traversal path constraints of each ring rule to avoid repeated parsing of rule configurations during the traversal process.

[0121] To optimize the efficiency of ring detection during graph data traversal, the preset ring rules are preprocessed, including:

[0122] Type set hashing converts the type set in the ring rule into a hash table structure, reducing the time complexity of type matching operations from O(n) to O(1). For example, when traversing to a transfer transaction type node, it can instantly determine whether it belongs to a certain ring type set.

[0123] Generate a query index (such as a Bloom filter or inverted index) for the start and end sets. This allows for quick determination of whether the current node belongs to the start / end set during loop detection. For example, when checking whether corporate account A is the start point of a loop, the result is returned directly using the index, avoiding traversal of the set elements.

[0124] Loop rule traversal constraints, such as "starting point cannot be accessed repeatedly" and "end point can only access types within the loop," are pre-cached in memory, eliminating the need to repeatedly parse the rule configuration file during traversal. For example, when a loop is detected, constraints are directly retrieved from the cache and actions such as skipping the starting point or restricting the end point path are immediately executed, reducing rule parsing time.

[0125] In summary, the embodiments of the present invention have at least the following advantages and improvements:

[0126] 1. Graph data is stored in a form that separates vertex data from edge data, separates the business data of graph vertices from the relationship data of graph vertices, and proposes a general graph storage method.

[0127] 2. Using a document-based database search engine to store graph-structured data retains the flexibility and scalability of the search engine compared to traditional graph storage solutions, opening up new ideas for graph data storage solutions.

[0128] 3. Improve the traditional graph traversal method and propose a graph traversal method for cyclic graphs and acyclic graphs based on dimensions.

[0129] Example 4

[0130] Figure 6 This is a schematic diagram of the structure of a graph data storage and traversal device provided by the third embodiment of the present invention. Figure 6 As shown, the device includes:

[0131] An edge relationship generating unit 610 is configured to store the vertices and edges of the graph data separately in a document-based database, and to generate edge relationships between vertices based on a queue-driven construction algorithm;

[0132] A traversal unit 620 is configured to traverse the graph data by type dimension starting from a set initial vertex, manage the nodes to be processed through a to-be-visited queue, and avoid repeated processing of types through a set of visited types;

[0133] The loop processing unit 630 is used to preset a set of loop types, a set of starting points, and a set of end points, where a loop is a vertex group consisting of the first connected vertices formed based on an edge relationship; when a loop is detected in the traversal path, the loop is processed to control the starting point to not be repeatedly visited, while the end point can be visited multiple times.

[0134] Optionally, vertices are stored as documents containing the following fields:

[0135] The ID of the entity data is used to uniquely identify the vertex entity;

[0136] The name of the entity data, used to identify the name of the vertex entity;

[0137] Basic information about entity data, including the entity data type and dynamic extended attributes. The entity data type is used to identify the category to which the vertex belongs, and the dynamic extended attributes are used to store additional attributes of the vertex.

[0138] Edges are stored as documents containing the following fields:

[0139] Source type, used to identify the category of the starting point of the edge;

[0140] Source entity ID, used to identify the starting entity of the edge;

[0141] Target type, used to identify the category of the end point of the edge;

[0142] Target entity ID list, used to store the unique identifier list of the end entities of the edge.

[0143] Optionally, when executing the queue-driven construction algorithm to generate edge relationships between vertices, the edge relationship generation unit 610 specifically performs:

[0144] Initialize the queue of types to be constructed and add the root type;

[0145] Loop out the current type in the queue, get its adjacent type list and all entities;

[0146] For each entity, query its associated entities with adjacent types and generate edge data; if the adjacent type has not been processed, add it to the queue for further processing.

[0147] Optionally, when traversing the graph data by type dimension, the traversal unit 620 specifically performs:

[0148] Initialize the result set, queue to be accessed, and set of accessed types;

[0149] Add the initial vertex to the queue and result set, take out the first node of the queue and mark its type as visited;

[0150] Query the adjacent type entities of the current node and add the entities of unvisited types to the queue and result set;

[0151] Repeat the above steps until the queue is empty.

[0152] Optionally, the ring processing unit 630 is configured to perform ring detection in the following manner:

[0153] A list of preset ring rules, each of which defines a type set, a start point set, and an end point set;

[0154] During the traversal process, when the type of the current node belongs to the type set of a certain ring rule and other type nodes of the ring rule have been visited, the ring detection logic is triggered;

[0155] Check whether the current node belongs to the starting point set of the ring rule. If it does and has been visited, then the path is determined to form a ring.

[0156] Optionally, when processing the ring, the ring processing unit 630 specifically performs:

[0157] When a loop is detected, if the current node belongs to the starting point set of the loop rule and has been visited, the subsequent path traversal of this node is skipped;

[0158] If the current node belongs to the endpoint set of the ring rule, it is allowed to continue visiting and marked as a node in the ring to limit its subsequent path to only visit the types within the ring rule;

[0159] If the current node is neither the starting point nor the end point, continue traversing and record the loop path;

[0160] Whether a node participates in the ring traversal is determined by the ring tag field in the vertex index. The tag field includes whether it belongs to the starting set and whether it has been visited.

[0161] Optionally, the ring processing unit 630 is further configured to execute:

[0162] Convert the type set of ring rules into a hash table structure;

[0163] Preprocess the starting and ending sets to generate a query index, which is used to determine the set to which a node belongs during ring detection;

[0164] Cache the traversal path constraints of each ring rule to avoid repeated parsing of rule configurations during the traversal process.

[0165] The graph data storage and traversal device provided in an embodiment of the present invention can execute the graph data storage and traversal method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0166] Example 5

[0167] Figure 7 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.

[0168] like Figure 7 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. Various programs and data required for the operation of the electronic device 10 can also be stored in the RAM 13. The processor 11, ROM 12, and RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0169] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0170] The processor 11 may be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the graph data storage traversal method.

[0171] In some embodiments, the graph data storage traversal method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the graph data storage traversal method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the graph data storage traversal method in any other appropriate manner (e.g., by means of firmware).

[0172] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0173] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0174] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0175] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0176] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0177] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.

[0178] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.

[0179] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

Claims

1. A graph data storage traversal method, characterized in that: include: Separate the vertices and edges of graph data and store them in a document-based database. Generate edge relationships between vertices based on a queue-driven construction algorithm. Starting from the set initial vertex, traverse the graph data according to the type dimension, manage the nodes to be processed through the to-be-processed queue, and avoid repeated processing of types through the visited type set; A set of ring types, a set of starting points, and a set of end points are preset, wherein the ring is a vertex group consisting of the first connected vertices formed based on the edge relationship; when a ring is detected in the traversal path, the ring is processed to control the starting point to not be repeatedly visited, while the end point can be visited multiple times.

2. The method according to claim 1, characterized in that The vertices are stored as documents containing the following fields: The ID of the entity data is used to uniquely identify the vertex entity; The name of the entity data, used to identify the name of the vertex entity; Basic information about entity data, including the entity data type and dynamic extended attributes. The entity data type is used to identify the category to which the vertex belongs, and the dynamic extended attributes are used to store additional attributes of the vertex. The edges are stored as documents containing the following fields: Source type, used to identify the category of the starting point of the edge; Source entity ID, used to identify the starting entity of the edge; Target type, used to identify the category of the end point of the edge; Target entity ID list, used to store the unique identifier list of the end entities of the edge.

3. The method according to claim 1, characterized in that The queue-driven construction algorithm generates edge relationships between vertices, including: Initialize the queue of types to be constructed and add the root type; Loop out the current type in the queue, get its adjacent type list and all entities; For each entity, query its associated entities with adjacent types and generate edge data; if the adjacent type has not been processed, add it to the queue for further processing.

4. The method according to claim 1, wherein The traversing the graph data according to the type dimension includes: Initialize the result set, queue to be accessed, and set of accessed types; Add the initial vertex to the queue and result set, take out the first node of the queue and mark its type as visited; Query the adjacent type entities of the current node and add the entities of unvisited types to the queue and result set; Repeat the above steps until the queue is empty.

5. The method according to claim 1, characterized in that Ring detection is performed as follows: A list of preset ring rules, each of which defines a type set, a start point set, and an end point set; During the traversal process, when the type of the current node belongs to the type set of a certain ring rule and other types of nodes of the ring rule have been visited, the ring detection logic is triggered; Check whether the current node belongs to the starting point set of the ring rule. If it does and has been visited, then determine that the path forms a ring.

6. The method according to claim 1, wherein The processing of the ring includes: When a loop is detected, if the current node belongs to the starting point set of the loop rule and has been visited, the subsequent path traversal of this node is skipped; If the current node belongs to the endpoint set of the ring rule, it is allowed to continue visiting and marked as a node in the ring to limit its subsequent path to only visit the types within the ring rule; If the current node is neither the starting point nor the end point, continue traversing and record the loop path; Whether a node participates in the ring traversal is determined by the ring tag field in the vertex index, wherein the tag field includes whether the node belongs to the starting point set and whether the node has been visited.

7. The method according to claim 5, characterized in that The method further includes: Converting the type set of the ring rule into a hash table structure; Preprocessing the starting point set and the ending point set to generate a query index for determining the set to which a node belongs during ring detection; The traversal path constraints of each ring rule are cached to avoid repeated parsing of rule configurations during the traversal process.

8. A graph data storage and traversal device, characterized in that: include: The edge relationship generation unit is used to store the vertices and edges of the graph data separately in a document-based database and generate edge relationships between vertices based on a queue-driven construction algorithm; A traversal unit, configured to traverse the graph data according to the type dimension starting from the set initial vertex, manage the nodes to be processed through the to-be-accessed queue, and avoid repeated processing of types through the visited type set; A ring processing unit is used to preset a set of ring types, a set of starting points, and a set of end points, wherein the ring is a vertex group consisting of the first connected vertices formed based on the edge relationship; when a ring is detected in the traversal path, the ring is processed to control the starting point to not be repeatedly visited and the end point to be visited multiple times.

9. An electronic device, characterized in that: The electronic device comprises: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the graph data storage traversal method described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the graph data storage and traversal method according to any one of claims 1 to 7 when executed.

Citation Information

Cited By

  • Alarm linkage endless loop detection method and system in rule trigger chain

    CN121257669A