Rule matching method and device based on graph theory, computer equipment and storage medium

Through the rule matching method based on graph theory, directed acyclic graph is constructed and multiple matching algorithms are used, which solves the performance problems of traditional rule engines in large-scale data and complex rules processing, and achieves efficient and flexible rule matching and processing.

CN119557656APending Publication Date: 2025-03-04CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411696780.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-22
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

Traditional rule engines have poor performance when processing large-scale data and complex rules, making it difficult to quickly adapt to data growth and business changes, and the rules are complex to configure and manage rules, which increases the risk of errors and conflicts.

Method used

The rule matching method based on graph theory is adopted to construct a directed acyclic graph by obtaining the rules to be matched, traversing the graph and using a variety of preset matching algorithms to dynamically manage and optimize rules.

Benefits of technology

It improves the efficiency and flexibility of rule matching, overcomes the performance bottlenecks of traditional rule engines in large-scale data and complex rules processing, and realizes the dynamics and optimization of rule processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119557656A_ABST
    Figure CN119557656A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of big data, and discloses a rule matching method and device based on a graph theory, computer equipment and a storage medium. The method comprises the steps of obtaining a to-be-matched rule; constructing a directed acyclic graph according to the rule to be matched; traversing the directed acyclic graph, and matching according to a plurality of preset matching algorithms to obtain a matching result; and performing code response or returning specified content according to the matching result. By implementing the method provided by the invention, the dynamic management and optimization of the rule can be realized; the performance bottleneck of a traditional rule engine in processing large-scale data and complex rules is overcome.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of big data technology, and more specifically to a graph-theory-based rule matching method, device, computer equipment and storage medium. Background Art

[0002] In today's rule engine market, a variety of technologies coexist, including products that use logical expressions to implement rule configuration and matching, such as Drools, Jess, Clips, etc. These tools have been widely used in various fields due to their excellent stability and reliability. However, even these mature technologies face a series of limitations, especially in rule matching.

[0003] First, these logical expression-based rule engines have limited flexibility in rule configuration. This means that they have difficulty adapting quickly to the growth of data volume or changes in business scenarios, especially when rule types need to be adjusted dynamically. Second, when the system needs to process large amounts of data or execute complex rule logic, the performance of these tools is often affected, resulting in longer response times and a poor user experience. In addition, since rule configuration information is usually stored in files or databases, this not only increases the difficulty of management and maintenance, but also increases the risk of errors and conflicts.

[0004] Compared with rule engines based on logical expressions, other types of rule engines excel in flexibility and handling complex rules, but they also have their own limitations. For example, some rule engines may rely on specific configuration file formats, which limits their interoperability and extensibility. At the same time, these rule engines may not be flexible enough in defining and modifying rules to fully meet changing needs.

[0005] Therefore, it is necessary to design a new method to achieve dynamic management and optimization of rules, and overcome the performance bottleneck of traditional rule engines when processing large-scale data and complex rules. Summary of the invention

[0006] The present invention provides a rule matching method, apparatus, computer equipment and storage medium based on graph theory to solve the technical problem that the traditional rule engine has poor performance when processing large-scale data and complex rules.

[0007] First, a rule matching method based on graph theory is provided, including:

[0008] Get the rules to be matched;

[0009] Constructing a directed acyclic graph according to the rules to be matched;

[0010] Traversing the directed acyclic graph, performing matching according to a plurality of preset matching algorithms to obtain matching results;

[0011] A code response or specified content is returned according to the matching result.

[0012] In the second aspect, a rule matching device based on graph theory is provided, comprising:

[0013] A rule acquisition unit, used to acquire rules to be matched;

[0014] A graph construction unit, used to construct a directed acyclic graph according to the rules to be matched;

[0015] A matching unit, used for traversing the directed acyclic graph and performing matching according to a plurality of preset matching algorithms to obtain a matching result;

[0016] The returning unit is used to make a code response or return specified content according to the matching result.

[0017] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned graph-theory-based rule matching method when executing the computer program.

[0018] In a fourth aspect, a storage medium is provided, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned graph-theory-based rule matching method are implemented.

[0019] The above-mentioned rule matching method based on graph theory obtains the rules to be matched and constructs a directed acyclic graph to represent the relationship between these rules; traverses the graph and uses a variety of preset matching algorithms to identify the rules that meet the conditions, thereby obtaining the matching results; executes the corresponding code response or returns the specified content based on the matching results; specifically, dynamically obtains and parses the rules to be matched, and constructs a directed acyclic graph to efficiently organize and manage these rules, thereby solving the performance problems of traditional rule engines when facing large-scale data and complex rules. Furthermore, by using a variety of preset matching algorithms to traverse the directed acyclic graph, the matching results can be found quickly and accurately, which improves the efficiency and flexibility of rule matching. Finally, according to the matching results, the corresponding content is immediately responded or output, realizing the dynamic and optimization of rule processing, and overcoming the performance bottleneck of traditional rule engines when processing large-scale data and complex rules.

[0020] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0022] Figure 1 A schematic diagram of an application scenario of a rule matching method based on graph theory provided in an embodiment of the present invention;

[0023] Figure 2 A schematic diagram of a flow chart of a rule matching method based on graph theory provided in an embodiment of the present invention;

[0024] Figure 3 A schematic diagram of a sub-process of a rule matching method based on graph theory provided in an embodiment of the present invention;

[0025] Figure 4 A schematic diagram of a sub-process of a rule matching method based on graph theory provided in an embodiment of the present invention;

[0026] Figure 5 A schematic block diagram of a graph-theory-based rule matching device provided in an embodiment of the present invention;

[0027] Figure 6 A schematic block diagram of a graph construction unit of a graph theory-based rule matching device provided in an embodiment of the present invention;

[0028] Figure 7 A schematic block diagram of a matching unit of a rule matching device based on graph theory provided in an embodiment of the present invention;

[0029] Figure 8 is a schematic diagram of a structure of a computer device in an embodiment of the present invention;

[0030] Fig. 9 2 is another schematic diagram of the structure of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION

[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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 creative work are within the scope of protection of the present invention.

[0032] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0033] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0034] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0035] See also Figure 1 and Figure 2 , Figure 1 A schematic diagram of an application scenario of a graph theory-based rule matching method provided in an embodiment of the present invention. Figure 2 A schematic flow chart of a rule matching method based on graph theory provided in an embodiment of the present invention. The rule matching method based on graph theory is applied to a server. The server interacts with a terminal for data, firstly organizes the rule logic by obtaining the rules to be matched and constructing a directed acyclic graph, and then traverses the graph using a variety of preset matching algorithms to efficiently find the best matching result. For each node in the graph, a matching algorithm is intelligently selected according to the relationship between its in-degree and out-degree, such as the shortest path rule, the maximum path rule or the linear rule matching algorithm, thereby improving the matching efficiency and accuracy. In addition, by defining virtual starting points and end points to handle multiple rule execution paths, the flexibility and adaptability of the system are enhanced. Finally, the corresponding code response or the specified content is executed according to the matching result, so as to realize the dynamic management and optimization of the rules. This method effectively overcomes the performance bottleneck that may occur when the traditional rule engine faces large-scale data and complex rules, and improves the overall performance of the system.

[0036] The method of this embodiment can be used in the financial and insurance industries, mainly focusing on risk management, fraud detection, customer relationship management, etc. It can not only help financial institutions and insurance companies better understand and manage risks, but also enhance customer experience and promote business growth.

[0037] Figure 2 FIG. 1 is a flow chart of a graph-based rule matching method provided by an embodiment of the present invention. Figure 2 As shown, the method includes the following steps S110 to S140.

[0038] S110: Obtain rules to be matched.

[0039] In this embodiment, the matching rule refers to a specific rule set extracted from the system to which the rule matching algorithm needs to be applied. These rules can be business logic, security policy or any data processing instructions that need to be evaluated.

[0040] In order to ensure the validity and applicability of the rules, the novelty, validity and conflict with other existing rules of the rules should also be considered in the process of obtaining the rules. The obtained rules will be used to construct a directed acyclic graph in the next step for efficient rule matching and processing.

[0041] S120: construct a directed acyclic graph according to the rules to be matched.

[0042] In this embodiment, a directed acyclic graph is constructed to effectively organize and manage the rules to be matched, thereby optimizing the rule matching process and improving the response speed and processing efficiency of the system.

[0043] In one embodiment, see Figure 3 , the above-mentioned step S120 may include steps S121 to S122.

[0044] S121. Take each rule in the to-be-matched rules as a node to construct a directed acyclic graph, wherein each node includes specific content of the rule, a preceding node, and a succeeding node.

[0045] In this embodiment, each to-be-matched rule is converted into a node in the graph.

[0046] Each node consists of three main parts:

[0047] Specific content of the rule: Describe the function and effect of the rule.

[0048] Predecessor node: Indicates which rules need to be executed before the current rule.

[0049] Post-node: Indicates which rules need to be executed after the current rule.

[0050] According to the dependency relationship between rules, connections between nodes are established to form directed edges.

[0051] By clearly displaying the information of each rule in the form of nodes, the rule structure is more intuitive and easier to understand. The concept of preceding and succeeding nodes can be used to effectively manage the dependencies between rules and ensure that the rules are executed in the correct order. During the construction process, circular dependencies between rules can be discovered to avoid runtime errors.

[0052] S122. Define the starting point and end point of the directed acyclic graph.

[0053] Specifically, when there are multiple rule execution paths, a virtual starting point and / or end point is defined.

[0054] In this embodiment, a rule that does not require any other rule as a premise is identified among all the rules and is set as the starting point of the DAG.

[0055] Similarly, find out the rules that will not affect the execution of other rules as the end point of DAG.

[0056] In the case where there are multiple independent rule paths, one or more virtual start points and / or end points need to be defined in order to connect these paths to form a complete DAG.

[0057] By explicitly specifying the start and end points, you can quickly determine the start and end points of the rule matching process, simplifying the initial configuration of the system. For complex rule sets, using virtual start and end points can help integrate different rule paths and ensure the coherence and consistency of the entire rule matching process. Even when the rule set changes, you can easily respond to rule changes by simply adjusting the definition of the start and end points, enhancing the system's adaptability.

[0058] This method is particularly suitable for application scenarios that require processing a large number of rules and complex conditions. This method not only improves the speed and accuracy of rule matching, but also makes rule management and maintenance easier through graphical display.

[0059] S130, traversing the directed acyclic graph, and performing matching according to a plurality of preset matching algorithms to obtain matching results.

[0060] In this embodiment, the matching result refers to the result obtained by matching the rules.

[0061] Traverse the entire directed acyclic graph and select the appropriate matching algorithm based on the characteristics of each node. This can improve processing efficiency, reduce unnecessary waste of computing resources, and more accurately meet the needs of different scenarios.

[0062] In one embodiment, see Figure 4 , the above-mentioned step S130 may include steps S131 to S132.

[0063] S131, traversing the directed acyclic graph, and determining a preset matching algorithm according to the relationship between the in-degree and the out-degree of the nodes.

[0064] In this embodiment, the directed acyclic graph is traversed, and when one in-degree in a node corresponds to at least two out-degrees, it is determined that the matching rule of the corresponding node is the shortest path rule matching algorithm or the maximum path rule matching algorithm.

[0065] When an in-degree in a node corresponds to an out-degree, the matching rule for determining the corresponding node is a linear rule matching algorithm.

[0066] Specifically, this step focuses on the number of in-degree and out-degree of the node, and determines which matching algorithm is most appropriate by analyzing these data.

[0067] When one in-degree in a node has at least two out-degrees, it means that there are multiple paths to choose from the node. In this case, choose the shortest path rule matching algorithm or the maximum path rule matching algorithm. Which algorithm to choose depends on the specific application scenario requirements. For example, in some cases, you may prefer to find the fastest solution; in other cases, you may need to find a path that covers the most nodes.

[0068] When there is one out-degree corresponding to one in-degree in a node, that is, the node has only one direct successor node. In this case, the linear rule matching algorithm is applicable. This is because the entire process can be simplified into a linear path, which can be processed from beginning to end in sequence without the need for a complex decision-making mechanism.

[0069] By selecting the most suitable matching algorithm according to the characteristics of different nodes, the inefficiency problem that may occur when using a single algorithm can be avoided. For example, it is obviously inappropriate to use a linear matching algorithm when there are multiple paths because it cannot effectively handle branching situations.

[0070] This method can better adapt to different application scenarios. Whether you need to find a solution quickly or want to cover as many nodes as possible, you can achieve this by choosing an appropriate matching algorithm. Reasonable selection of matching algorithms helps reduce unnecessary calculations and save computing resources. This is especially important in large-scale networks. Choosing matching algorithms based on the characteristics of different nodes can make the final matching results closer to the actual situation, thereby improving the accuracy of matching.

[0071] In summary, by dynamically selecting the matching algorithm based on the in-degree and out-degree relationship of the nodes, not only the processing efficiency and resource utilization of the system are improved, but also the flexibility and accuracy of the system are enhanced, enabling it to better serve diverse application scenarios.

[0072] S132: Perform rule matching according to a preset matching algorithm to obtain a matching result.

[0073] In this embodiment, the shortest path rule matching algorithm aims to find one or more paths with the shortest distance from the starting node to the target node. The "distance" here can be physical distance, cost, time or other metrics.

[0074] Implementation methods include:

[0075] Initialization: Set the distances of all nodes to infinity (except the starting node, whose distance is 0), and create a list of unvisited nodes.

[0076] Select node: Select the node with the smallest distance from the list of unvisited nodes as the current node.

[0077] Update neighbor nodes: For all neighbor nodes of the current node, if the distance from the current node to the neighbor node is less than the distance currently recorded by the neighbor node, update the distance value of the neighbor node.

[0078] Mark visited: Mark the current node as visited and remove it from the list of unvisited nodes.

[0079] Repeat steps 2 to 4 until all nodes have been visited or the target node is found.

[0080] Path reconstruction: Starting from the target node, trace back to the starting node along the recorded shortest path.

[0081] Common algorithms: Dijkstra algorithm, A* algorithm.

[0082] The goal of the maximum path rule matching algorithm is to find the path from the start node to the target node that passes through the most nodes in a given directed acyclic graph.

[0083] Implementation methods include:

[0084] Initialization: Set the maximum path length of all nodes to 0 (except the starting node, whose length is 1), and create a list of unvisited nodes.

[0085] Select node: Select any node from the unvisited node list as the current node.

[0086] Update neighbor nodes: For all neighbor nodes of the current node, if the path length from the current node to the neighbor node is greater than the maximum path length currently recorded by the neighbor node, update the maximum path length value of the neighbor node.

[0087] Mark visited: Mark the current node as visited and remove it from the list of unvisited nodes.

[0088] Repeat steps 2 to 4 until all nodes have been visited or the target node is found.

[0089] Path reconstruction: Starting from the target node, trace back to the starting node along the recorded maximum path.

[0090] It is important to note that since the graph is a directed acyclic graph (DAG), there are no cyclic paths and the termination of the algorithm is guaranteed.

[0091] The linear rule matching algorithm is applicable to the case where each node in the graph has exactly one in-degree and one out-degree, that is, the entire graph forms one or more independent links.

[0092] Implementation methods include:

[0093] Find the starting point: First find a node with an in-degree of 0 as the starting point of the path.

[0094] Traverse nodes: Start from the starting point and move to the next node along the unique out-degree direction.

[0095] Record the path: Each time you move to a new node, add it to the path.

[0096] Check the end point: When you encounter a node with an out-degree of 0, it means that you have reached the end of the path.

[0097] Repeat steps 1 to 4 until all links have been traversed.

[0098] The linear rule matching algorithm is very simple and efficient because the processing of each node is deterministic and there is no need for complex comparison and selection operations.

[0099] These three algorithms are suitable for different types of problem scenarios. The shortest path rule matching algorithm is suitable for finding the optimal solution; the maximum path rule matching algorithm is suitable for maximizing the path length; and the linear rule matching algorithm is suitable for scenarios with simple path structures. Choosing the right algorithm can significantly improve the efficiency and effectiveness of problem solving.

[0100] S140: Response by code or return of specified content according to the matching result.

[0101] In this embodiment, when the matching result is a rule hit, a code response is performed; when the matching result is a match failure, a match failure result is returned.

[0102] When the system matches the input data according to the preset rule set, if it finds data that meets the rules (i.e., the rules hit), it will trigger the pre-defined code logic or script.

[0103] This code response may include but is not limited to operations such as data processing, status updating, triggering events, and calling other services.

[0104] For example, in a network request processing system, if the received request meets certain conditions (such as specific HTTP headers, query parameters, etc.), it may perform a database query, generate response content, or forward the request to another service.

[0105] If the system fails to find any rules that match the input data (ie, the match fails), it needs to return a message indicating the match failure to the requester.

[0106] This feedback can be an error code, error message, or predefined response content to inform the client why the request was not processed correctly.

[0107] The response should be clear and useful, helping the requester understand why a match was not made and what actions might be needed to correct the problem.

[0108] Suppose you are building a simple Web Application Firewall (WAF), one of its functions is to filter malicious requests according to preset security rules:

[0109] Rule definition: defines a series of security rules, such as prohibiting certain User-Agent strings, restricting requests from specific IP addresses, etc.

[0110] Request received: The web server receives an HTTP request.

[0111] Rule matching: The WAF module checks the request according to the above rules.

[0112] If the User-Agent field in the request contains a string in the blacklist, the WAF immediately interrupts the request processing flow, does not forward the request to the backend application, and may record the behavior of the attempted attack. If the request does not violate any security rules, the request is allowed to continue to be passed to the backend application for further processing. At the same time, the WAF can return a standard HTTP response to indicate that the request has been successfully received.

[0113] In this way, step S140 ensures that the system can take appropriate actions according to different matching results, which not only effectively protects the security of the system but also ensures that legitimate requests can be properly processed.

[0114] Specifically, when performing graph traversal operations, specific rules can be combined to decide when and how to return results. The following is a restatement of the three strategies for different needs:

[0115] Immediately return the hit result: When the first node that meets the established rules is encountered during the traversal process, the traversal is stopped immediately and the relevant information of the node is returned. This strategy is suitable for situations where you only need to find any node that meets the conditions. It can quickly give an answer and reduce unnecessary computing overhead.

[0116] Immediately return the missed results: If a node is found to not meet the rule conditions during the traversal process, the traversal process can also be stopped immediately and the node information that does not meet the conditions can be returned. This method is particularly effective for quickly identifying situations that do not meet the standards and helps to make further decisions quickly.

[0117] Summarize the results after the complete traversal: Regardless of whether the rule is triggered, the traversal program will continue to run until the entire graph is completely traversed. After that, all matching and non-matching results are collected according to the execution of the rules, and the summary of these results is returned at one time. Although this method may increase computing time and resource usage, it provides the most detailed information and is suitable for occasions where a comprehensive understanding of the status of all nodes is required.

[0118] By properly designing the traversal algorithm, these strategies can be effectively used to optimize the graph data processing flow.

[0119] The method of this embodiment is based on graph theory and reorganizes the rules to address the limitations of traditional rule engines when faced with large amounts of data and diverse application scenarios. Specifically, by defining rules as nodes in graph theory and linking these nodes using a linked list structure, a flexible graph structure is formed. This not only allows the rule engine to dynamically adjust the rule logic during operation to adapt to changing application requirements and data scales, but also enhances the flexibility and adaptability of the system.

[0120] In view of the low efficiency of traditional rule engines in rule matching, the method of this embodiment proposes an optimization solution based on graph theory. That is, rule matching is converted into a graph traversal process, and all matching tasks can be completed in one traversal. This method not only speeds up the speed of rule matching, but also reduces resource consumption and shortens response time. It is particularly suitable for processing large-scale data sets and complex rules.

[0121] The method of this embodiment allows the rule set to be expanded by simply adding new nodes while maintaining the integrity of the original rules. In addition, the use of the linked list structure makes the connection between rules more flexible, which can easily adapt to changes in different application scenarios, ensuring the long-term scalability of the system.

[0122] The method of this embodiment adopts object-oriented design principles to disassemble the rule engine into multiple modules with specific functions. Each module is independent of each other, which is convenient for independent development and testing, and also convenient for addition, deletion and modification according to actual needs. More importantly, the method of this embodiment provides a user-friendly graphical interface, so that non-technical personnel can easily complete the setting and adjustment of rules, greatly simplifying the daily management and maintenance process.

[0123] In summary, the method of this embodiment not only significantly improves the performance, flexibility and maintainability of the rule engine through the combination of graph theory and object-oriented design, but also lays a solid foundation for coping with new challenges that may arise in the future. This design has broad application prospects, especially in areas that require efficient processing of large amounts of data and frequent changes in business logic. It has multiple advantages and benefits after improvement, such as higher performance, better scalability, higher flexibility and better maintainability, and can better meet the needs of different application scenarios and data volumes, and has broad application prospects.

[0124] The above-mentioned graph-theory-based rule matching method obtains the rules to be matched and constructs a directed acyclic graph to represent the relationship between these rules; traverses the graph and uses a variety of preset matching algorithms to identify the rules that meet the conditions, thereby obtaining the matching results; executes the corresponding code response or returns the specified content based on the matching results; specifically, dynamically obtains and parses the rules to be matched, and constructs a directed acyclic graph to efficiently organize and manage these rules, thereby solving the performance problems of traditional rule engines when facing large-scale data and complex rules. Furthermore, by using a variety of preset matching algorithms to traverse the directed acyclic graph, the matching results can be found quickly and accurately, thereby improving the efficiency and flexibility of rule matching. Finally, according to the matching results, the corresponding content is immediately responded to or output, thereby realizing the dynamic and optimization of rule processing, and overcoming the performance bottleneck of traditional rule engines when processing large-scale data and complex rules.

[0125] Figure 5 is a schematic block diagram of a graph-theory-based rule matching device 300 provided in an embodiment of the present invention. Figure 5 As shown, corresponding to the above graph-based rule matching method, the present invention further provides a graph-based rule matching device 300. The graph-based rule matching device 300 includes a unit for executing the above graph-based rule matching method, and the device can be configured in a server. Figure 5 The graph theory-based rule matching device 300 includes a rule acquisition unit 301 , a graph construction unit 302 , a matching unit 303 and a returning unit 304 .

[0126] A rule acquisition unit 301 is used to acquire rules to be matched; a graph construction unit 302 is used to construct a directed acyclic graph according to the rules to be matched; a matching unit 303 is used to traverse the directed acyclic graph and perform matching according to multiple preset matching algorithms to obtain matching results; a return unit 304 is used to make a code response or return specified content according to the matching results.

[0127] In one embodiment, if Figure 6 As shown, the graph construction unit 302 includes a node determination subunit 3021 and a start point and end point definition subunit 3022 .

[0128] The node determination subunit 3021 is used to construct a directed acyclic graph by taking each rule in the to-be-matched rules as a node, wherein each node contains the specific content of the rule, the preceding node, and the succeeding node; the starting point and ending point definition subunit 3022 is used to define the starting point and the ending point of the directed acyclic graph.

[0129] In one embodiment, the start point and end point definition subunit 3022 is used to define a virtual start point and / or end point when there are multiple rule execution paths.

[0130] In one embodiment, if Figure 7 As shown, the matching unit 303 includes an algorithm determination subunit 3031 and a rule matching subunit 3032 .

[0131] The algorithm determination subunit 3031 is used to traverse the directed acyclic graph and determine the preset matching algorithm according to the relationship between the in-degree and out-degree of the node; the rule matching subunit 3032 is used to perform rule matching according to the preset matching algorithm to obtain a matching result.

[0132] In one embodiment, the algorithm determination subunit 3031 is used to traverse the directed acyclic graph, and when one in-degree in a node corresponds to at least two out-degrees, determine that the matching rule of the corresponding node is the shortest path rule matching algorithm or the maximum path rule matching algorithm. When one in-degree in a node corresponds to one out-degree, determine that the matching rule of the corresponding node is the linear rule matching algorithm.

[0133] In one embodiment, the returning unit 304 is used to make a code response when the matching result is a rule hit; and return a matching failure result when the matching result is a matching failure.

[0134] It should be noted that technicians in the relevant field can clearly understand that the specific implementation process of the above-mentioned graph theory-based rule matching device 300 and each unit can refer to the corresponding description in the aforementioned method embodiment, and for the convenience and brevity of description, it will not be repeated here.

[0135] Each module in the graph-based rule matching device 300 can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.

[0136] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client through a network connection. When the computer program is executed by the processor, it realizes the functions or steps of a rule matching method based on graph theory on the server side.

[0137] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, it realizes the functions or steps of the client side of a rule matching method based on graph theory

[0138] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:

[0139] Obtaining rules to be matched; constructing a directed acyclic graph according to the rules to be matched; traversing the directed acyclic graph, matching according to a plurality of preset matching algorithms to obtain matching results; and responding with a code or returning specified content according to the matching results.

[0140] In one embodiment, a storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

[0141] Obtaining rules to be matched; constructing a directed acyclic graph according to the rules to be matched; traversing the directed acyclic graph, matching according to a plurality of preset matching algorithms to obtain matching results; and responding with a code or returning specified content according to the matching results.

[0142] It should be noted that the functions or steps that can be implemented by the above storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.

[0143] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0144] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0145] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

[0146] The non-Company software tools or components appearing in the embodiments of this application are merely examples and do not represent actual use.

Claims

1. A rule matching method based on graph theory, characterized in that: include: Get the rules to be matched; Constructing a directed acyclic graph according to the rules to be matched; Traversing the directed acyclic graph, performing matching according to a plurality of preset matching algorithms to obtain matching results; A code response or specified content is returned according to the matching result.

2. The graph-theory-based rule matching method according to claim 1, characterized in that: The step of constructing a directed acyclic graph according to the rules to be matched includes: Each rule in the to-be-matched rules is used as a node to construct a directed acyclic graph, wherein each node includes specific content of the rule, a preceding node, and a succeeding node; Define the start and end points of a directed acyclic graph.

3. The graph-theory-based rule matching method according to claim 2, characterized in that: The definition of the starting point and the end point of the directed acyclic graph includes: When there are multiple rule execution paths, define virtual start and / or end points.

4. The graph-theory-based rule matching method according to claim 1, characterized in that: The traversing the directed acyclic graph and matching according to a plurality of preset matching algorithms to obtain matching results include: Traversing the directed acyclic graph, and determining a preset matching algorithm according to the relationship between the in-degree and the out-degree of the nodes; Rules are matched according to the preset matching algorithm to obtain matching results.

5. The graph-theory-based rule matching method according to claim 4, characterized in that: The traversing the directed acyclic graph and determining a preset matching algorithm according to a relationship between an in-degree and an out-degree in a node include: The directed acyclic graph is traversed, and when one in-degree in a node corresponds to at least two out-degrees, it is determined that the matching rule of the corresponding node is a shortest path rule matching algorithm or a maximum path rule matching algorithm.

6. The graph-theory-based rule matching method according to claim 5, characterized in that: The traversing the directed acyclic graph and determining a preset matching algorithm according to the relationship between the in-degree and the out-degree of the node also includes: When an in-degree in a node corresponds to an out-degree, the matching rule for determining the corresponding node is a linear rule matching algorithm.

7. The graph-theory-based rule matching method according to claim 1, characterized in that: The step of responding with a code or returning specified content according to the matching result includes: When the matching result is a rule hit, a code response is performed; when the matching result is a match failure, a match failure result is returned.

8. A rule matching device based on graph theory, characterized in that: include: A rule acquisition unit, used to acquire rules to be matched; A graph construction unit, used to construct a directed acyclic graph according to the rules to be matched; A matching unit, used for traversing the directed acyclic graph and performing matching according to a plurality of preset matching algorithms to obtain a matching result; The returning unit is used to make a code response or return specified content according to the matching result.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the graph-theory-based rule matching method according to any one of claims 1 to 7 are implemented.

10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the graph-theory-based rule matching method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Data cleaning method and data cleaning engine based on rule data driving

    CN119938662A