Method, system, device and medium for improving traversal efficiency of rule engine
By identifying and building a rule binary tree and optimizing the rule engine structure, the coupling and maintenance problems caused by hard coding of business rules in traditional software development are solved, and efficient business rule traversal and system stability are achieved.
Patent Information
- Application Number
- CN202410565866.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-09
- Publication Date
- 2024-12-24
- Estimated Expiration
- 2044-05-09
AI Technical Summary
In traditional software development methods, business rules are hard-coded to make the code highly coupled and difficult to maintain, resulting in the need to modify and recompile the entire application when business rules change, which increases development costs and may lead to system instability.
By obtaining a pre-established set of business rules, identifying judgment statements, building a rule binary tree, optimizing the rule engine structure, using concurrent traversal and caching technology, calculating the node access frequency and importance, and adjusting the rule binary tree structure to improve traversal efficiency.
It improves the traversal efficiency and throughput of the rule engine, reduces development costs, enhances the flexibility and maintainability of the system, and reduces potential risks.
Smart Images

Figure CN118467585B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of rule engine technology, and in particular to a method, system, device and medium for improving the traversal efficiency of a rule engine. Background Art
[0002] With the rapid development of information technology, business rules play an increasingly important role in software systems. They not only define how the system responds to various inputs and conditions, but also directly affect the performance and stability of the system. However, in traditional software development methods, business rules are usually hard-coded in the application code, which leads to high coupling and difficulty in maintainability of the code. Whenever the business rules change, the entire application needs to be modified and recompiled, which not only increases the development cost, but also may lead to system instability and potential risks. Summary of the invention
[0003] The present invention provides a method, system, device and medium for improving the traversal efficiency of a rule engine, the main purpose of which is to solve the problems of low flexibility and low maintainability of existing business rule traversal methods.
[0004] To achieve the above object, the present invention provides a method for improving the traversal efficiency of a rule engine, comprising:
[0005] Acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements;
[0006] Constructing a rule engine according to the judgment statement and the preset business logic, wherein the rule engine includes a rule binary tree of the number of statements;
[0007] Obtaining the parameter to be traversed, performing field attribute identification on the parameter to be traversed, and obtaining the field attribute;
[0008] Inputting the parameter to be traversed into the field interface of the rule engine according to the field attribute;
[0009] Utilizing the rule engine to perform concurrent traversal on the parameters to be traversed to obtain execution results;
[0010] Cache the parameters to be traversed and the execution results;
[0011] The total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree are obtained by accessing the log records of the rule engine, and the access frequency of each node is calculated according to the total number of visits and the number of visits to each node. The access frequency weight parameter of each node is calculated according to the access frequency and the preset time decay factor using the following formula:
[0012]
[0013] Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter;
[0014] The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula:
[0015] S(v)=W α *d(v) 1―α
[0016] Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree;
[0017] The node adjustment priority parameter is calculated according to the node importance parameter using the following formula:
[0018]
[0019] Wherein, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree;
[0020] The structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
[0021] Optionally, the performing judgment statement identification on the business rule set to obtain the judgment statement and the number of judgment statements includes:
[0022] Perform keyword recognition on the business rule set to obtain a keyword statement set;
[0023] Performing conditional expression recognition on the keyword statement set to obtain a conditional statement set;
[0024] Matching the conditional statement set to a judgment statement structure according to the keyword to obtain a first matching result;
[0025] Semantic recognition is used to screen the first matching results for judgment statements to obtain judgment statements and the number of judgment statements.
[0026] Optionally, constructing a rule engine according to the judgment statement and preset business logic includes:
[0027] Identifying object words, logical words, and conditional words in the judgment sentence;
[0028] Establish a traversal rule with the object word as the left child node, the condition word as the right child node, and the logic word as the root node;
[0029] Construct a rule binary tree according to the traversal rules and the object words, logical words and conditional words corresponding to the judgment sentence;
[0030] Define the rule structure of the rule engine according to the preset business logic to obtain an initial rule engine;
[0031] Each rule binary tree and its corresponding preset execution result are set into the initial rule engine to obtain a rule binary tree rule engine containing the number of statements.
[0032] Optionally, the performing field attribute identification on the parameter to be traversed to obtain the field attribute includes:
[0033] Obtain the field type and the number of types according to the judgment statement;
[0034] Perform word segmentation processing on the parameter to be traversed to obtain a word segmentation field;
[0035] Using a regular expression to match the field format of the word segmentation field to obtain the field format;
[0036] The field attributes of the field format are matched according to the field type and the type quantity to obtain the field attributes.
[0037] Optionally, obtaining the field type and the number of types according to the judgment statement includes:
[0038] Identify the logical words and judgment words in the judgment sentence;
[0039] Extracting the logical words in the judgment statement and the fields before and after the judgment words to obtain the fields to be identified;
[0040] The field type of the field to be identified is matched by using a regular expression according to a pre-established field type library to obtain the field type and the number of types.
[0041] Optionally, the concurrently traversing the parameters to be traversed by using the rule engine to obtain an execution result includes:
[0042] Creating concurrent tasks using the rule engine;
[0043] Call all regular binary trees and perform conditional traversal on the parameters to be traversed at the same time;
[0044] According to the parameters to be traversed, a pruning strategy is used to remove subtrees in the regular binary tree that have no effect on the traversal result, to obtain a pruned binary tree;
[0045] Obtaining the conditional traversal result of each pruned binary tree for the parameter to be traversed;
[0046] Execute subsequent actions according to the conditional traversal results to obtain execution results.
[0047] In order to solve the above problems, the present invention also provides a system for improving the traversal efficiency of a rule engine, the system comprising:
[0048] A data acquisition module is used to acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements;
[0049] A rule engine construction module, used to construct a rule engine according to the judgment statement and preset business logic, wherein the rule engine includes a rule binary tree of the number of statements;
[0050] A field identification module is used to obtain the parameters to be traversed, perform field attribute identification on the parameters to be traversed, and obtain field attributes;
[0051] A concurrent traversal module, used for inputting the parameters to be traversed into the field interface of the rule engine according to the field attributes, performing concurrent traversal on the parameters to be traversed using the rule engine, obtaining execution results, and caching the parameters to be traversed and the execution results;
[0052] The adaptive adjustment module obtains the total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree by accessing the log records of the rule engine, calculates the access frequency of each node according to the total number of visits and the number of visits to each node, and calculates the access frequency weight parameter of each node according to the access frequency and the preset time decay factor using the following formula:
[0053]
[0054] Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θis the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter;
[0055] The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula:
[0056] S(v)=W α *d(v) 1―α
[0057] Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree;
[0058] The node adjustment priority parameter is calculated according to the node importance parameter using the following formula:
[0059]
[0060] Among them, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree; the structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
[0061] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:
[0062] at least one processor;
[0063] and, a memory communicatively coupled to the at least one processor;
[0064] 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 above-mentioned method for improving the traversal efficiency of the rule engine.
[0065] In order to solve the above problems, the present invention also provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is executed by a processor in an electronic device to implement the above-mentioned method for improving the traversal efficiency of the rule engine.
[0066] The embodiment of the present invention obtains a pre-established business rule set, identifies judgment statements on the business rule set, obtains judgment statements and the number of judgment statements, thereby improving the efficiency of constructing a rule binary tree, constructs a rule engine containing the number of rule binary trees according to the judgment statements and preset business logic, thereby improving the efficiency of subsequent traversal, obtains parameters to be traversed, identifies field attributes of the parameters to be traversed, obtains field attributes, inputs the parameters to be traversed into the field interface of the rule engine according to the field attributes, uses the rule engine to perform concurrent traversal on the parameters to be traversed, obtains execution results, thereby improving the throughput of the rule engine and the traversal efficiency, caches the parameters to be traversed and the execution results, makes the traversal results reusable, and improves the traversal efficiency, obtains the access frequency of each node of the rule binary tree, calculates the node importance parameter of each node in the rule binary tree according to the access frequency, calculates the node adjustment priority parameter according to the node importance parameter, and adjusts the structure of the rule binary tree according to the node adjustment priority parameter. The traversal efficiency of the rule binary tree is improved. Therefore, the traversal efficiency improvement method, system, electronic device and computer-readable storage medium for the rule engine proposed in the present invention can solve the problems of low flexibility and low maintainability of existing business rule traversal methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] Figure 1 A flow chart of a method for improving the traversal efficiency of a rule engine provided by an embodiment of the present invention;
[0068] Figure 2 A schematic diagram of a flow chart of judgment statement recognition provided by an embodiment of the present invention;
[0069] Figure 3 A schematic diagram of a flow chart of concurrent traversal of traversal parameters by a rule engine provided in one embodiment of the present invention;
[0070] Figure 4 A functional module diagram of a system for improving the traversal efficiency of a rule engine provided by an embodiment of the present invention;
[0071] Figure 5 A schematic diagram of the structure of an electronic device for implementing the method for improving the traversal efficiency of a rule engine provided by an embodiment of the present invention.
[0072] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0073] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0074] The embodiment of the present application provides a method for improving the traversal efficiency of a rule engine. The execution subject of the method for improving the traversal efficiency of a rule engine includes but is not limited to at least one of the electronic devices such as a server, a terminal, etc. that can be configured to execute the method provided by the embodiment of the present application. In other words, the method for improving the traversal efficiency of a rule engine can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0075] Reference Figure 1 FIG. 1 is a flow chart of a method for improving the traversal efficiency of a rule engine according to an embodiment of the present invention. In this embodiment, the method for improving the traversal efficiency of a rule engine includes:
[0076] S1. Obtain a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements.
[0077] In the embodiment of the present invention, the pre-established business rule set is a set of rules that define the business operations and decision logic of the enterprise. These rules may involve various aspects of business processes, including but not limited to pricing, discounts, customer qualification verification, order processing, risk management, etc.
[0078] In the embodiment of the present invention, after the business rule set is created, the business rule set is stored in a process, and the storage path of the business rule set is recorded. The business rule set is obtained by accessing a file system according to the storage path.
[0079] In detail, the file system is a system that a computer operating system uses to store and organize computer files and their data. It is responsible for managing the data on a storage device (usually a hard drive, solid-state drive, or flash drive) and providing access to these data.
[0080] In the embodiment of the present invention, referring to Figure 2 As shown, a flow chart of a judgment statement recognition process is provided in an embodiment of the present invention, wherein the judgment statement recognition is performed on the business rule set to obtain the judgment statement and the number of judgment statements, including:
[0081] S21. Identify keywords in the business rule set to obtain a keyword statement set;
[0082] S22. Identify conditional expressions in the keyword statement set to obtain a conditional statement set;
[0083] S23. Match the conditional statement set with the judgment statement structure according to the keyword to obtain a first matching result;
[0084] S24. Use semantic recognition to filter judgment statements from the first matching result to obtain judgment statements and the number of judgment statements.
[0085] Specifically, the matching of the judgment statement result means extracting the sentences in the conditional statement set that match the judgment statement result. The judgment statement structure needs to be set according to the business rule set.
[0086] Specifically, the semantic recognition is a technology based on artificial intelligence, aiming to help the computer understand the user's intention according to the meaning and context of human language. This technology determines the true meaning of the user's instruction and performs corresponding operations by analyzing the relationships between words and phrases in natural language, as well as their meanings and contexts.
[0087] Specifically, the use of semantic recognition to filter judgment statements from the first matching result to obtain judgment statements and the number of judgment statements includes:
[0088] Perform stop word removal processing on each sentence in the first matching result to obtain a preprocessed statement set;
[0089] Perform word segmentation processing on each sentence in the preprocessed statement set to obtain a segmented statement set;
[0090] Perform part-of-speech tagging on each segmented statement in the segmented statement set to obtain a tagged statement set;
[0091] Extract the tagged statements containing the subject and predicate from the standard statement set to obtain judgment statements and the number of statements.
[0092] In the embodiments of the present invention, the stop word removal processing refers to deleting common but insignificant words in the text, such as "de", "he", "shi", etc.
[0093] Specifically, the word segmentation processing is a basic step in natural language processing. It involves splitting the original text into smaller units, usually words, phrases or other meaningful symbols, which are called "tokens". The purpose of word segmentation is to enable the computer to better understand and process human language.
[0094] Furthermore, the sentences in the first matching result are segmented by vocabulary matching, and each segmented sentence in the hierarchical sentence set is tagged with a part of speech by vocabulary matching.
[0095] In detail, the word library matching is to match the text with the words in the word library using a predefined word library. The predefined word library is a key component for tasks such as word segmentation, part-of-speech tagging, spelling checking and grammar analysis in natural language processing (NLP). The word library is essentially a data structure containing a series of known words that are legal words in the language.
[0096] In detail, the keywords are words related to judgment, such as if, when, otherwise, etc.
[0097] In detail, the conditional expression refers to a sentence containing operators (greater than, less than, equal to) and logical operators (and, or, not).
[0098] In the embodiment of the present invention, by removing stop words from each sentence in the first matching result, interference from irrelevant words is reduced, thereby improving the efficiency and accuracy of subsequent word segmentation processing.
[0099] In an embodiment of the present invention, the sentences in the first matching result are segmented by vocabulary matching, and each segmented sentence in the hierarchical sentence set is tagged with a part of speech by vocabulary matching, which can ensure the accuracy of the word segmentation and part of speech tagging, and improve the efficiency of the word segmentation and part of speech tagging.
[0100] In the embodiment of the present invention, by using semantic recognition to screen the judgment statements of the first matching results, the accuracy of judgment statement recognition is further improved.
[0101] In the embodiment of the present invention, since the preset business rule set includes multiple judgment statements, it is necessary to construct multiple rule binary trees, and each rule binary tree corresponds to a judgment statement.
[0102] In an embodiment of the present invention, by obtaining a pre-established business rule set, judgment statements are identified on the business rule set to obtain judgment statements and the number of judgment statements, the number of rule binary trees that need to be constructed is clarified, the efficiency of constructing the rule binary tree is improved, and the accuracy of subsequent construction of the rule binary tree is improved.
[0103] S2. Construct a rule engine according to the judgment statement and preset business logic, wherein the rule engine includes a rule binary tree of the number of statements.
[0104] In the embodiment of the present invention, the preset business logic refers to a series of conditions and operations predefined in the business process, which are used to guide the business system on how to handle specific business scenarios and events, and generally include defined conditions, operations corresponding to the conditions being met, and operations corresponding to the conditions not being met.
[0105] In detail, the difference between the business logic and the business rule set is that the business logic is the core of the software application, which processes data and performs calculations to achieve business functions, and the business rule set is the logic or instructions that guide business operations, which are usually defined by users or relevant staff; the business logic focuses on how to perform business operations, and the business rule set focuses on which operations should be performed in specific situations.
[0106] In the embodiment of the present invention, the regular binary tree is a special form of a binary tree. The binary tree is a tree data structure, which is characterized in that each node has at most two child nodes, which are usually called a left child node and a right child node.
[0107] In an embodiment of the present invention, the rule engine is a component embedded in an application program, which is used to separate business decisions from application program code and write business decisions using predefined semantic modules. It accepts data input, interprets business rules, and makes business decisions based on business rules. The core of the rule engine is the rule base, which contains a series of rules consisting of conditions and actions. Conditions are used to describe the characteristics or constraints of input data, while actions are operations performed when conditions are met. When the input data matches the rules in the rule base, the rule engine will decide whether to trigger the corresponding action based on the matching results.
[0108] In the embodiment of the present invention, the step of constructing a rule engine according to the judgment statement and the preset business logic includes:
[0109] Identifying object words, logical words, and conditional words in the judgment sentence;
[0110] Establish a traversal rule with the object word as the left child node, the condition word as the right child node, and the logic word as the root node;
[0111] Construct a rule binary tree according to the traversal rules and the object words, logical words and conditional words corresponding to the judgment sentence;
[0112] Define the rule structure of the rule engine according to the preset business logic to obtain an initial rule engine;
[0113] Each rule binary tree and its corresponding preset execution result are set into the initial rule engine to obtain a rule binary tree rule engine containing the number of statements.
[0114] In the embodiment of the present invention, the object words, logical words and conditional words in the judgment sentence can be identified by natural language processing tools. The natural language processing tools include spaCy, Stanford NLP, and HanLP, which all provide functions such as word segmentation, part-of-speech tagging, and syntactic dependency analysis.
[0115] In detail, the object word refers to the object being judged in the judgment sentence. For example, in the judgment sentence "such as height is greater than 180cm", "height" is the object word.
[0116] Furthermore, in the judgment sentence "such as height greater than 180cm", "greater than" is a logical word and "180cm" is a conditional word.
[0117] In the embodiment of the present invention, the traversal rule means that when traversing the rule binary tree, the content of the left child node is traversed first, the content of the root node is traversed secondly, and the content of the right child node is traversed last, so as to form a complete judgment sentence.
[0118] In the embodiment of the present invention, by establishing the traversal rule, the space efficiency of the regular binary tree can be improved, thereby improving the traversal efficiency of the regular binary tree.
[0119] In the embodiment of the present invention, by constructing a rule binary tree according to the traversal rules and the object words, logical words and conditional words corresponding to the judgment statement, the sorting and traversal optimization of the business rules in the business rule set are achieved, thereby improving the traversal efficiency.
[0120] In an embodiment of the present invention, in the rule structure of the rule engine defined according to the preset business logic, the rule structure is generally "if A then B otherwise C", wherein A corresponds to the rule binary tree, B is the execution result when the rule binary tree is satisfied, and C is the execution result when the rule binary tree is not satisfied.
[0121] In an embodiment of the present invention, a rule binary tree rule engine containing the number of statements is constructed according to the judgment statements and preset business logic, thereby achieving management and optimization of traversal rules, and increasing the amount of data that can be processed simultaneously by executing concurrent traversals, thereby improving the efficiency of subsequent traversals.
[0122] S3. Obtain the parameters to be traversed, perform field attribute identification on the parameters to be traversed, and obtain field attributes.
[0123] In an embodiment of the present invention, the parameters to be traversed may come from user input, a database, an external system, and an API call. After receiving the parameters to be traversed, the parameters to be traversed are stored, and the file system is accessed according to the storage path of the parameters to be traversed to obtain the parameters to be traversed.
[0124] In detail, the API call is a common mechanism for interaction between different components in a software system. The API defines how software components communicate with each other, including the request format, transmission method, data structure and operation rules of the data.
[0125] In the embodiment of the present invention, the parameters to be traversed are business parameters that need to be traversed using the regular binary tree.
[0126] In an embodiment of the present invention, the field attribute identification of the parameter to be traversed refers to identifying the field in the parameter to be traversed corresponding to the preset business logic attribute. For example, when the parameter to be traversed is "height: 175cm / gender: male / age: 24 years old", it contains fields of three different attributes: name, gender, and age.
[0127] In the embodiment of the present invention, the step of identifying the field attributes of the parameter to be traversed to obtain the field attributes includes:
[0128] Obtain the field type and the number of types according to the judgment statement;
[0129] Perform word segmentation processing on the parameter to be traversed to obtain a word segmentation field;
[0130] Using a regular expression to match the field format of the word segmentation field to obtain the field format;
[0131] The field attributes of the field format are matched according to the field type and the type quantity to obtain the field attributes.
[0132] In the embodiment of the present invention, the field type and the number of types are obtained according to the judgment statement, by obtaining the fields located before and after the judgment logic word in the judgment statement, and using semantic recognition to perform type recognition on the fields to obtain the field type and the number of types. For example, in the judgment statement "age is greater than 18 and height is greater than 175cm and gender is male", three field types of "age", "height" and "gender" can be identified.
[0133] In detail, obtaining the field type and the number of types according to the judgment statement includes:
[0134] Identify the logical words and judgment words in the judgment sentence;
[0135] Extracting the logical words in the judgment statement and the fields before and after the judgment words to obtain the fields to be identified;
[0136] The field type of the field to be identified is matched by using a regular expression according to a pre-established field type library to obtain the field type and the number of types.
[0137] In detail, the pre-established field type library is a database that includes field types commonly used in business needs, such as field types such as "height", "gender", "age", "nationality", and "education level".
[0138] In the embodiment of the present invention, the regular expression is a powerful tool for string search and matching, which uses a single string to describe and match a series of strings that conform to a certain syntactic rule or format.
[0139] In detail, the field format is associated with the field type. For example, if the field type includes "height" and "age", the corresponding field format is a three-digit number in centimeters and an integer between 0 and 100. The matching of these two formats can be represented by regular expressions as \b\d+(\.\d+)? (cm)\b and \b(0|[1-9][0-9]?)\b.
[0140] Furthermore, the use of regular expressions to match the field type of the field to be identified according to the pre-established field type library is to match the field to be identified according to the specific format of different field types. For example, if a field is identified to end with "cm", the type of the field is "height".
[0141] In the embodiment of the present invention, the word segmentation processing is performed on the parameter to be traversed to obtain the word segmentation field, including:
[0142] Traversing the parameters to be traversed;
[0143] Identify the separator in the parameter to be traversed;
[0144] Extract the fields before each separator and the fields after the last separator to obtain the word-separated fields.
[0145] In detail, the separator is a symbol used to separate different types of fields in the parameter to be traversed, including but not limited to ";", " / ", ".", and "\".
[0146] In an embodiment of the present invention, the field attributes of the field format are matched according to the field type and the number of types to obtain the field attributes, which is matched according to the field format of the word segmentation field and the field type. Each field type has its fixed field format. Each word segmentation field is matched with the field type corresponding to its field format to obtain the field attributes of the parameters to be traversed.
[0147] Furthermore, if the number of field format types of the word segmentation field is less than the number of types, a null value is assigned to the missing word segmentation field attribute. If the number of field format types of the word segmentation field is greater than the number of types, it means that the format of the parameter to be traversed does not meet the requirements and there are redundant parameters, and an error message is reported to the user.
[0148] In an embodiment of the present invention, the field attributes refer to all field types of the parameters to be traversed and the parameters corresponding to each field type. For example, in the parameters to be traversed "age: 18 / height: 175cm / gender: male", the field attributes are "age", "height", and "gender", and the corresponding parameters are "18", "175cm", and "male", respectively.
[0149] In the embodiment of the present invention, by obtaining the field type and the number of types according to the judgment statement, a reference sample is provided for subsequent field attribute matching, thereby improving the efficiency and accuracy of obtaining field attributes.
[0150] In detail, by removing the logical words and judgment words of the judgment sentence, the accuracy and efficiency of extracting the fields to be identified are improved.
[0151] In detail, by using regular expressions to match the field types of the fields to be identified according to a pre-established field type library, the accuracy of the acquired field types and the number of types is guaranteed.
[0152] In the embodiment of the present invention, the word segmentation processing of the parameter to be traversed is performed by utilizing the method of identifying separators, which has the advantages of high accuracy, high efficiency, and easy implementation. Moreover, since the identification method is independent of the context of the parameter to be traversed, the amount of calculation can be reduced when processing a large amount of data.
[0153] In the embodiment of the present invention, by using regular expressions to perform format matching on the word segmentation fields, the efficiency of format matching is improved and the accuracy of format matching is guaranteed.
[0154] In an embodiment of the present invention, by obtaining the parameters to be traversed, the field attributes of the parameters to be traversed are identified to obtain the field attributes, and the field attributes include the field type of each field in the parameters to be traversed and its corresponding parameters, so that the parameters to be traversed can be input into the rule engine according to the field type, thereby ensuring the accuracy of traversing the parameters to be traversed.
[0155] S4. Input the parameters to be traversed into the field interface of the rule engine according to the field attributes.
[0156] In an embodiment of the present invention, the field interface of the rule engine involves data structures, method calls and interactions within the rule engine, and can receive parameters of different field attributes, which need to be set according to the field type and number of types of the judgment statement.
[0157] Furthermore, the field interface provides access to and control over the internal state of the rule engine, allowing users to dynamically modify rules, add or delete facts, set conditions and actions, etc. as needed.
[0158] In addition, the field interface of the rule engine may also include some interfaces for managing and monitoring the running status of the rule engine, such as viewing rule execution logs, monitoring rule execution performance, etc. These interfaces help users better understand and control the behavior of the rule engine, and optimize the performance and stability of the rule engine.
[0159] In the embodiment of the present invention, the inputting of the parameters to be traversed into the field interface of the rule engine according to the field attributes means that after marking each parameter field in the parameters to be traversed with a field type, each parameter field and its corresponding parameter are input into a data interface of the corresponding field type in the field interface according to the field type. The field interface pre-sets data interfaces of different field types according to the field type, and after receiving the parameter field with the field type marking, the field interface converts the parameter field into a data format recognizable by a computer according to the pre-set conversion rules.
[0160] In detail, the preset conversion rule refers to converting a specific field type into a preset object name, for example, the parameter field "age: 18" can be converted into "age=18".
[0161] In an embodiment of the present invention, by inputting the parameters to be traversed into the field interface of the rule engine according to the field attributes, each parameter field in the parameters to be traversed can be input into the data interface of the corresponding field type in the field interface according to its field type, thereby ensuring the correctness of the traversal.
[0162] S5. Utilize the rule engine to concurrently traverse the parameters to be traversed to obtain execution results.
[0163] In the embodiment of the present invention, the concurrent traversal of the parameters to be traversed allows the rule engine to process multiple tasks simultaneously, thereby improving the response rate and throughput of the rule engine.
[0164] In the embodiment of the present invention, refer to Figure 3As shown, a schematic diagram of a process of concurrently traversing parameters to be traversed by a rule engine is provided in an embodiment of the present invention, wherein concurrently traversing the parameters to be traversed by the rule engine to obtain execution results includes:
[0165] S31, creating concurrent tasks using the rule engine;
[0166] S32, calling all regular binary trees and performing conditional traversal on the parameters to be traversed at the same time;
[0167] S33, using a pruning strategy according to the parameters to be traversed to remove subtrees in the regular binary tree that have no impact on the traversal result, to obtain a pruned binary tree;
[0168] S34, obtaining the conditional traversal result of each pruned binary tree for the parameter to be traversed;
[0169] S35. Execute subsequent actions according to the conditional traversal result to obtain an execution result.
[0170] In the embodiment of the present invention, creating concurrent tasks using the rule engine refers to creating the same number of traversal tasks according to the number of rule binary trees contained in the rule engine, and performing thread management on the traversal tasks through a thread pool.
[0171] In detail, the thread pool is a form of multithreaded processing that adds tasks to a queue during processing and then automatically starts these tasks after creating a thread. The threads in the thread pool are all background threads, each of which uses a default stack size, runs at a default priority, and is in a multithreaded unit.
[0172] The conditional traversal result in the embodiment of the present invention refers to "true" or "false", which is used to indicate whether the parameter to be traversed satisfies the condition of the regular binary tree.
[0173] In detail, the execution result is pre-confirmed according to the preset business logic.
[0174] In the embodiment of the present invention, the pruning strategy is an optimization technology, which is mainly used to reduce unnecessary calculations in the regular binary tree to improve the traversal efficiency. The core idea is to cut off unnecessary subtrees on the binary tree through a series of judgments, and terminate the traversal paths that obviously will not get results or are not the optimal solution in advance.
[0175] In the embodiment of the present invention, the subsequent action is an action executed according to the preset business logic, and different actions will be executed when the result of the traversal parameter is "true" or "false". For example, when the business logic is "push advertisements if the age is over 18, otherwise record the name", "push advertisements" is the subsequent execution action when the traversal result is "true", and "record name" is the subsequent execution action when the traversal result is "false".
[0176] In the embodiment of the present invention, in the process of calling all regular binary trees and performing conditional traversal on the parameters to be traversed at the same time, a logical circuit breaker mechanism is used to optimize the traversal efficiency. When a condition that can determine the traversal result is encountered, the traversal is stopped immediately, thereby avoiding unnecessary calculations and improving the traversal efficiency.
[0177] Specifically, the logic circuit breaker mechanism means that when processing a logical "and" (&&) operation, if the first operation is false, the result of the entire expression is already determined to be false, so the truth of the second operation will not be judged. Similarly, when processing a logical "or" (||) operation, if the first operand is true, the result of the entire expression is already determined to be true, so the truth of the second operation will not be judged.
[0178] In the embodiment of the present invention, by using the rule engine to create concurrent tasks, the data throughput of the rule engine is improved, the resource utilization is optimized, and all rule binary trees can be called at the same time to traverse the parameters to be traversed, thereby improving the traversal efficiency.
[0179] In the embodiment of the present invention, by utilizing a pruning strategy to remove subtrees in the regular binary tree that do not affect the traversal results, the structure of the regular binary tree is optimized, the space occupancy of the regular binary tree is reduced, the traversal efficiency is improved, and the flexibility of business traversal is improved.
[0180] S6. Cache the parameters to be traversed and the execution results.
[0181] In the embodiment of the present invention, by caching the parameters to be traversed and the execution results, when the same parameters need to be traversed subsequently, the execution results can be directly retrieved, thereby omitting unnecessary traversal processes and improving efficiency.
[0182] Specifically, a unique key is designed for each cacheable execution result, which can accurately identify the data in the cache.
[0183] In detail, the parameters to be traversed and the execution results may be cached in memory or in distributed mode. The cache persistence, scalability, and concurrency of these two cache modes are different and need to be selected according to different task requirements.
[0184] In the embodiment of the present invention, by caching the parameters to be traversed and the execution results, the execution results can be directly called when the same parameters to be traversed are encountered subsequently, thereby improving resource utilization and traversal efficiency.
[0185] S7. Obtain the total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree by accessing the log records of the rule engine, calculate the access frequency of each node based on the total number of visits and the number of visits to each node, calculate the access frequency weight parameter of each node based on the access frequency and a preset time decay factor, calculate the node importance parameter of each node based on the access frequency weight parameter and a preset adjustment parameter, and calculate the node importance parameter of each node based on the access frequency weight parameter and the preset adjustment parameter.
[0186] In the embodiment of the present invention, the step of calculating the access frequency weight parameter of each node according to the access frequency and the preset time decay factor includes:
[0187] The access frequency weight parameter of each node is calculated according to the access frequency and the preset time decay factor using the following formula:
[0188]
[0189] Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter;
[0190] In the embodiment of the present invention, the node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter, including:
[0191] The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula:
[0192] S(v)=W α *d(v) 1―α
[0193] Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree.
[0194] In detail, the time decay factor is a parameter used to simulate the decrease of the node access frequency weight parameter over time, and is used to control the rate at which the access frequency parameter decays over time, because some nodes of the regular binary tree may be accessed very frequently over a period of time, but then their access frequency may decrease. By introducing the time decay factor, we can make the node access frequency weight parameter gradually decrease over time, thereby reflecting the "heat" or "timeliness" of the node.
[0195] Furthermore, the size of the time decay factor needs to be set according to the specific traversal task. The larger the time decay factor, the more significant the impact of time decay.
[0196] In detail, the weight adjustment parameter is used to balance the influence of access frequency and time decay. The larger the weight adjustment parameter is, the greater the influence of time decay on the access frequency weight parameter is; the smaller the weight adjustment parameter is, the greater the influence of access frequency on the access frequency weight parameter is.
[0197] In the embodiment of the present invention, the step of calculating the node importance parameter according to the access frequency weight parameter and the preset adjustment parameter includes:
[0198] In detail, the node depth refers to the layer number of the node in the regular binary tree.
[0199] In detail, the adjustment parameter is a parameter used to balance the access frequency weight parameter and the proportion of the node depth, and is a parameter between 0 and 1. When the adjustment parameter is 0.5, the access frequency weight parameter and the node depth have the same weight proportion; when the adjustment parameter is greater than 0.5, the access frequency weight parameter has a greater impact; when the adjustment parameter is less than 0.5, the node depth has a greater impact. In an embodiment of the present invention, the node adjustment priority parameter is calculated according to the node importance parameter, including:
[0200] The node adjustment priority parameter is calculated using the following formula:
[0201]
[0202] Among them, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree.
[0203] S8. Adjust the structure of the regular binary tree according to the node adjustment priority parameter.
[0204] In the embodiment of the present invention, the adjusting the structure of the regular binary tree according to the node adjustment priority parameter is to reorder the nodes of the regular binary tree in descending order of the node adjustment priority.
[0205] In an embodiment of the present invention, the structure of the regular binary tree is adjusted according to the node adjustment priority parameter, thereby optimizing the performance of the regular binary tree, achieving priority traversal of high-priority nodes, reducing the number of traversals, and improving traversal efficiency.
[0206] like Figure 4 , which is a functional module diagram of a system for improving traversal efficiency of a rule engine provided by an embodiment of the present invention.
[0207] The traversal efficiency improvement system 100 for rule engines of the present invention can be installed in an electronic device. According to the functions implemented, the traversal efficiency improvement system 100 for rule engines can include a data acquisition module 101, a rule engine construction module 102, a field identification module 103, a concurrent traversal module 104 and an adaptive adjustment module 105. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0208] In this embodiment, the functions of each module / unit are as follows:
[0209] The data acquisition module 101 is used to acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements;
[0210] The rule engine construction module 102 is used to construct a rule engine according to the judgment statement and the preset business logic, wherein the rule engine includes a rule binary tree of the number of statements;
[0211] The field identification module 103 is used to obtain the parameter to be traversed, perform field attribute identification on the parameter to be traversed, and obtain field attributes;
[0212] The concurrent traversal module 104 is used to input the parameters to be traversed into the field interface of the rule engine according to the field attributes, perform concurrent traversal on the parameters to be traversed using the rule engine, obtain execution results, and cache the parameters to be traversed and the execution results;
[0213] The adaptive adjustment module 105 is used to obtain the total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree by accessing the log records of the rule engine, calculate the access frequency of each node according to the total number of visits and the number of visits to each node, and calculate the access frequency weight parameter of each node according to the access frequency and a preset time decay factor using the following formula:
[0214]
[0215] Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter;
[0216] The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula:
[0217] S(v)=W α *d(v) 1―α
[0218] Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree;
[0219] The node adjustment priority parameter is calculated according to the node importance parameter using the following formula:
[0220]
[0221] Among them, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree; the structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
[0222] In detail, each module described in the system 100 for improving the traversal efficiency of the rule engine in the embodiment of the present invention is used in the same manner as described above. Figures 1 to 3 The same technical means as the method for improving the traversal efficiency of the rule engine described in , and can produce the same technical effects, will not be repeated here.
[0223] like Figure 5 , which is a schematic diagram of the structure of an electronic device for a method for improving the traversal efficiency of a rule engine provided by an embodiment of the present invention.
[0224] The electronic device 1 may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a traversal efficiency improvement program for a rule engine.
[0225] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is the control core (ControlUnit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (such as a traversal efficiency improvement program for the rule engine, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.
[0226] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 can not only be used to store application software and various types of data installed in the electronic device, such as the code of the traversal efficiency improvement program for the rule engine, but also can be used to temporarily store data that has been output or is to be output.
[0227] The communication bus 12 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0228] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in this embodiment, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0229] The figure only shows an electronic device with components. Those skilled in the art will understand that the structure shown in the figure does not constitute a limitation on the electronic device, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0230] For example, although not shown, the electronic device may also include a power source (such as a battery) for supplying power to various components. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include any components such as one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0231] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0232] The traversal efficiency improvement program for the rule engine stored in the memory 11 of the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0233] Acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements;
[0234] Constructing a rule engine according to the judgment statement and the preset business logic, wherein the rule engine includes a rule binary tree of the number of statements;
[0235] Obtaining the parameter to be traversed, performing field attribute identification on the parameter to be traversed, and obtaining the field attribute;
[0236] Inputting the parameter to be traversed into the field interface of the rule engine according to the field attribute;
[0237] Utilizing the rule engine to perform concurrent traversal on the parameters to be traversed to obtain execution results;
[0238] Cache the parameters to be traversed and the execution results;
[0239] The total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree are obtained by accessing the log records of the rule engine, and the access frequency of each node is calculated according to the total number of visits and the number of visits to each node. The access frequency weight parameter of each node is calculated according to the access frequency and the preset time decay factor using the following formula:
[0240]
[0241] Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter;
[0242] The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula:
[0243] S(v)=W α *d(v) 1―α
[0244] Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree;
[0245] The node adjustment priority parameter is calculated according to the node importance parameter using the following formula:
[0246]
[0247] Wherein, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree;
[0248] The structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
[0249] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to the description of the relevant steps in the corresponding embodiment of the accompanying drawings, which will not be repeated here.
[0250] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0251] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:
[0252] Acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements;
[0253] Constructing a rule engine according to the judgment statement and the preset business logic, wherein the rule engine includes a rule binary tree of the number of statements;
[0254] Obtaining the parameter to be traversed, performing field attribute identification on the parameter to be traversed, and obtaining the field attribute;
[0255] Inputting the parameter to be traversed into the field interface of the rule engine according to the field attribute;
[0256] Utilizing the rule engine to perform concurrent traversal on the parameters to be traversed to obtain execution results;
[0257] Cache the parameters to be traversed and the execution results;
[0258] The total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree are obtained by accessing the log records of the rule engine, and the access frequency of each node is calculated according to the total number of visits and the number of visits to each node. The access frequency weight parameter of each node is calculated according to the access frequency and the preset time decay factor using the following formula:
[0259]
[0260] Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter;
[0261] The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula:
[0262] S(v)=W α *d(v) 1―α
[0263] Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree;
[0264] The node adjustment priority parameter is calculated according to the node importance parameter using the following formula:
[0265]
[0266] Wherein, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree;
[0267] The structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
[0268] In the embodiments provided by the present invention, it should be understood that the disclosed devices, systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0269] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0270] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0271] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.
[0272] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0273] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0274] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or systems stated in a system claim can also be implemented by one unit or system through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0275] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A method for improving the traversal efficiency of a rule engine, characterized in that: The method comprises: Acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements; Construct a rule engine according to the judgment statement and the preset business logic, wherein the rule engine includes a rule binary tree of the number of statements; Obtaining the parameter to be traversed, performing field attribute identification on the parameter to be traversed, and obtaining the field attribute; Inputting the to-be-traversed parameter into the field interface of the rule engine according to the field attribute; Utilizing the rule engine to perform concurrent traversal on the parameters to be traversed to obtain execution results; Cache the parameters to be traversed and the execution results; The total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree are obtained by accessing the log records of the rule engine, and the access frequency of each node is calculated according to the total number of visits and the number of visits to each node. The access frequency weight parameter of each node is calculated according to the access frequency and the preset time decay factor using the following formula: Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter; The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula: S(v)=W α *d(v) 1―α Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree; The node adjustment priority parameter is calculated according to the node importance parameter using the following formula: Wherein, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree; The structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
2. The method for improving the traversal efficiency of a rule engine according to claim 1, characterized in that: The step of identifying judgment statements on the business rule set to obtain judgment statements and the number of judgment statements includes: Perform keyword recognition on the business rule set to obtain a keyword statement set; Performing conditional expression recognition on the keyword statement set to obtain a conditional statement set; Matching the conditional statement set to a judgment statement structure according to the keyword to obtain a first matching result; Semantic recognition is used to screen the first matching results for judgment statements to obtain judgment statements and the number of judgment statements.
3. The method for improving the traversal efficiency of a rule engine according to claim 1, characterized in that: The constructing a rule engine according to the judgment statement and the preset business logic includes: Identifying object words, logical words, and conditional words in the judgment sentence; Establish a traversal rule with the object word as the left child node, the condition word as the right child node, and the logic word as the root node; Construct a rule binary tree according to the traversal rules and the object words, logical words and conditional words corresponding to the judgment sentence; Define the rule structure of the rule engine according to the preset business logic to obtain an initial rule engine; Each rule binary tree and its corresponding preset execution result are set into the initial rule engine to obtain a rule binary tree rule engine containing the number of statements.
4. The method for improving the traversal efficiency of a rule engine according to claim 1, characterized in that: The step of identifying the field attributes of the parameter to be traversed to obtain the field attributes includes: Obtain the field type and the number of types according to the judgment statement; Perform word segmentation processing on the parameter to be traversed to obtain a word segmentation field; Using a regular expression to match the field format of the word segmentation field to obtain the field format; The field attributes of the field format are matched according to the field type and the type quantity to obtain the field attributes.
5. The method for improving the traversal efficiency of a rule engine according to claim 4, characterized in that: The obtaining of the field type and the number of types according to the judgment statement includes: Identify the logical words and judgment words in the judgment sentence; Extracting the logical words in the judgment statement and the fields before and after the judgment words to obtain the fields to be identified; The field type of the field to be identified is matched by using a regular expression according to a pre-established field type library to obtain the field type and the number of types.
6. The method for improving the traversal efficiency of a rule engine according to claim 1, characterized in that: The concurrent traversal of the to-be-traversed parameters by using the rule engine to obtain execution results includes: Creating concurrent tasks using the rule engine; Call all regular binary trees and perform conditional traversal on the parameters to be traversed at the same time; According to the parameters to be traversed, a pruning strategy is used to remove subtrees in the regular binary tree that have no effect on the traversal result, to obtain a pruned binary tree; Obtaining the conditional traversal result of each pruned binary tree for the parameter to be traversed; Execute subsequent actions according to the conditional traversal results to obtain execution results.
7. A system for improving the traversal efficiency of a rule engine, characterized in that: The system comprises: A data acquisition module is used to acquire a pre-established business rule set, perform judgment statement recognition on the business rule set, and obtain judgment statements and the number of judgment statements; A rule engine construction module, used to construct a rule engine according to the judgment statement and preset business logic, wherein the rule engine includes a rule binary tree of the number of statements; A field identification module is used to obtain the parameters to be traversed, perform field attribute identification on the parameters to be traversed, and obtain field attributes; A concurrent traversal module, used for inputting the parameters to be traversed into the field interface of the rule engine according to the field attributes, performing concurrent traversal on the parameters to be traversed using the rule engine, obtaining execution results, and caching the parameters to be traversed and the execution results; The adaptive adjustment module obtains the total number of visits to the rule binary tree and the number of visits to each node in the rule binary tree by accessing the log records of the rule engine, calculates the access frequency of each node according to the total number of visits and the number of visits to each node, and calculates the access frequency weight parameter of each node according to the access frequency and the preset time decay factor using the following formula: Wherein, W represents the access frequency weight parameter of the access frequency at time t, F is the access frequency of any node of the regular binary tree, e is the base of the natural logarithm, λ is the time decay factor, T is the current time point, T θ is the time point of the last visit of any node of the regular binary tree, and β is the weight adjustment parameter; The node importance parameter of each node is calculated according to the access frequency weight parameter and the preset adjustment parameter using the following formula: S(v)=W α *d(v) 1―α Wherein, S(v) represents the node importance parameter of any node in the regular binary tree, W is the access frequency weight parameter, α is the adjustment parameter, and d(v) represents the node depth of any node in the regular binary tree; The node adjustment priority parameter is calculated according to the node importance parameter using the following formula: Among them, P(v) represents the adjustment priority parameter of any node in the regular binary tree, S(i) represents the node importance parameter of the i-th node in the regular binary tree, S(v) represents the node importance parameter of any node in the regular binary tree, V is the set of nodes in the regular binary tree, and N represents the number of nodes in the regular binary tree; the structure of the regular binary tree is adjusted according to the node adjustment priority parameter.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively coupled to the at least one processor; 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 method for improving the traversal efficiency of the rule engine as described in any one of claims 1 to 7.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for improving the traversal efficiency of a rule engine as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
A method and a device for executing rule processing by a computer
CN109947401A
Legal concept identification method based on law graph rule engine
CN110414007A
Data exception detection method and device
CN111126622A
Rule engine optimization method and device, data matching method and device, storage medium and terminal
CN113641708A
Business rule processing method and device, equipment and storage medium
CN116561134A
