Method for executing rules and rule execution engine

CN115982209BActive Publication Date: 2026-09-15ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211313405.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-25
Publication Date
2026-09-15
Estimated Expiration
2042-10-25

Smart Images

  • Figure CN115982209B_ABST
    Figure CN115982209B_ABST
Patent Text Reader

Abstract

The embodiments of the present specification provide a method for executing rules and a rule execution engine. In the method, a plurality of rules to be executed are acquired; for each rule comprising a plurality of conditions, each condition included in the rule is arranged in descending order according to the number of occurrences of each repeated condition included in the rule and appearing multiple times in all rules; when executing each rule in the plurality of rules, for each condition included in each rule, when a condition execution result corresponding to the condition is stored in the cache, the condition execution result is acquired from the cache; and after the plurality of rules are executed, a rule execution result of each rule is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of computer technology, and more specifically, to a method for executing rules and a rule execution engine. Background Technology

[0002] In production environments, predefined rules are frequently used to filter data that meets specific requirements. These defined rules can be run in a rule execution engine after deployment; the rule execution engine is a software system that executes rules at runtime. The rule execution engine primarily consists of rules and execution. When a rule is met, the corresponding action is executed.

[0003] A rule package typically consists of multiple rules executed together. Each rule comprises one or more conditions. When a rule includes multiple conditions, these conditions are connected by logical relationships such as "AND" or "OR" to form a complete rule. In the current rule execution method, each rule is executed as a whole. Within each rule, the execution obtains the judgment result of each condition, and then outputs the execution result of the rule based on the logical relationships between the conditions. Summary of the Invention

[0004] In view of the above, embodiments of this specification provide a method and a rule execution engine for executing rules. Through the technical solutions of these embodiments, each condition in each rule is executed individually to obtain the corresponding condition execution result. The condition execution results corresponding to each repeated condition are stored in a cache, so that subsequent repeated conditions can directly retrieve their corresponding condition execution results from the cache. This achieves the sharing of condition execution results for repeated conditions and reduces redundant calculations.

[0005] According to one aspect of an embodiment of this specification, a method for executing rules is provided, comprising: acquiring a plurality of rules to be executed, wherein each rule consists of a condition or a plurality of conditions connected by logical relationships; sorting the conditions included in each rule in descending order according to the number of times each repeated condition appears multiple times in the plurality of rules; when executing each rule among the plurality of rules, for each condition included in each rule, when a condition execution result corresponding to the condition is stored in a cache, retrieving the condition execution result from the cache, wherein the cache stores the condition execution results corresponding to each repeated condition among the processed conditions, and the conditions processed in each rule are processed sequentially according to the order of conditions; and obtaining the rule execution result of each rule after the plurality of rules are executed.

[0006] According to another aspect of the embodiments of this specification, a rule execution engine is also provided, comprising: a rule acquisition unit for acquiring a plurality of rules to be executed, wherein each rule consists of a condition or a plurality of conditions connected by logical relationships; a condition sorting unit for sorting the conditions included in a rule in descending order according to the number of times each repeated condition appears multiple times in the plurality of rules included in the rule; a condition processing unit for retrieving the condition execution result from the cache when the condition included in each rule is stored in the cache, wherein the cache stores the condition execution results corresponding to each repeated condition in each processed condition, and the conditions processed in each rule are processed sequentially according to the order of conditions; and a result obtaining unit for obtaining the rule execution result of each rule after the plurality of rules are executed.

[0007] According to another aspect of the embodiments of this specification, an electronic device is also provided, comprising: at least one processor, a memory coupled to the at least one processor, and a computer program stored on the memory, wherein the at least one processor executes the computer program to implement the execution rule method as described above.

[0008] According to another aspect of the embodiments of this specification, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the execution rule method as described above.

[0009] According to another aspect of the embodiments of this specification, a computer program product is also provided, including a computer program that, when executed by a processor, implements the execution rule method as described above. Attached Figure Description

[0010] A further understanding of the nature and advantages of the embodiments described in this specification can be achieved by referring to the following accompanying drawings. In the drawings, similar components or features may have the same reference numerals.

[0011] Figure 1 A flowchart is shown as an example of a method for executing rules according to an embodiment of this specification.

[0012] Figure 2 This diagram illustrates an example of a rule defined as a string.

[0013] Figure 3 A diagram illustrating an example of multiple rules is shown.

[0014] Figure 4This diagram illustrates an example of multiple rules obtained by sorting the conditions in the rules.

[0015] Figure 5 A block diagram of an example rule execution engine provided according to embodiments of this specification is shown.

[0016] Figure 6 A block diagram of an electronic device for implementing a rule enforcement method according to an embodiment of this specification is shown. Detailed Implementation

[0017] The subject matter described herein will be discussed below with reference to exemplary embodiments. It should be understood that these embodiments are discussed merely to enable those skilled in the art to better understand and implement the subject matter described herein, and are not intended to limit the scope, applicability, or examples set forth in the claims. The function and arrangement of the elements discussed may be changed without departing from the scope of the embodiments described herein. Various processes or components may be omitted, substituted, or added as needed in the various examples. Furthermore, features described in some examples may be combined in other examples.

[0018] As used herein, the term "comprising" and its variations are open terms meaning "including but not limited to". The term "based on" means "at least partially based on". The terms "one embodiment" and "an embodiment" mean "at least one embodiment". The term "another embodiment" means "at least one other embodiment". The terms "first", "second", etc., may refer to different or the same objects. Other definitions, whether explicit or implicit, may be included below. Unless explicitly indicated by the context, the definition of a term shall remain consistent throughout the specification.

[0019] In this specification, the term "model" refers to a machine learning model applied in a business scenario to provide business prediction services, such as machine learning models used for classification prediction, business risk prediction, etc. Examples of machine learning models may include, but are not limited to: linear regression models, logistic regression models, neural network models, decision tree models, support vector machines, etc. Examples of neural network models may include, but are not limited to: deep neural network (DNN) models, convolutional neural network (CNN) models, backpropagation (BP) neural networks, etc.

[0020] The specific implementation of the model depends on the business scenario in which it is applied. For example, if the model is used to classify users, it is implemented as a user classification model. Accordingly, user classification prediction can be performed based on the user characteristic data of the users to be classified. If the model is used to predict business risks of business transactions occurring in a business system, it is implemented as a business risk prediction model. Accordingly, business risk prediction can be performed based on the business transaction characteristic data of that business transaction.

[0021] With the development of artificial intelligence technology, machine learning techniques are widely used as models in various business application scenarios to provide predictive services, such as classification prediction and business risk prediction. For example, these models have wide applications in areas such as financial fraud, recommendation systems, and image recognition. To achieve better model performance, more training data is needed to train the business model. In application areas such as healthcare and finance, different enterprises or institutions possess different data samples. Jointly training these data will greatly improve the model's accuracy, thereby bringing significant economic benefits to the enterprise.

[0022] In production environments, predefined rules are frequently used to filter data that meets specific requirements. These defined rules can be run in a rule execution engine after deployment; the rule execution engine is a software system that executes rules at runtime. The rule execution engine primarily consists of rules and execution. When a rule is met, the corresponding action is executed.

[0023] A rule package typically consists of multiple rules executed together. Each rule comprises one or more conditions. When a rule includes multiple conditions, these conditions are connected by logical relationships such as "AND" or "OR" to form a complete rule. In the current rule execution method, each rule is executed as a whole. Within each rule, the execution obtains the judgment result of each condition, and then outputs the execution result of the rule based on the logical relationships between the conditions.

[0024] However, different rules may contain the same conditions; for example, a condition might be included in three different rules. Under the current rule execution method, even repeated conditions still need to be executed each time, leading to redundant calculations and wasted computational resources.

[0025] In view of the above, embodiments of this specification provide a method and a rule execution engine for executing rules. In this method, multiple rules to be executed are obtained; for each rule including multiple conditions, the conditions included in the rule are sorted in descending order according to the frequency of occurrence of each repeated condition that appears multiple times in all rules included in the rule; when executing each rule among the multiple rules, for each condition included in each rule, if the condition execution result corresponding to that condition is stored in the cache, the condition execution result is retrieved from the cache; and after the execution of multiple rules is completed, the rule execution result of each rule is obtained. Through the technical solution of the embodiments of this specification, each condition in each rule can be processed individually to obtain the corresponding condition execution result, and the condition execution results corresponding to each repeated condition are stored in the cache, so that subsequent repeated conditions can directly retrieve the corresponding condition execution results from the cache, thereby realizing the sharing of condition execution results for repeated conditions and reducing redundant calculations.

[0026] The method for executing rules and the rule execution engine provided in the embodiments of this specification will be described in detail below with reference to the accompanying drawings.

[0027] Figure 1 A flowchart of an example 100 of a method for executing rules according to an embodiment of this specification is shown.

[0028] In the embodiments described in this specification, Figure 1 The rule execution method shown can be executed by a rule execution engine. A rule execution engine can be a software system that executes one or more rules during runtime. In one application scenario, the rule execution engine of this embodiment can be applied to a risk control scenario, where the executed rules are risk control rules.

[0029] like Figure 1 As shown, in 110, multiple rules to be executed can be obtained.

[0030] In the embodiments of this specification, each rule consists of one condition or multiple conditions connected by logical relationships. A condition is the smallest unit in a rule, and the components of each condition may include features, logical symbols (such as >, <), and condition values. For example, in the case of an amount greater than 100, the amount is the feature, greater than is the logical symbol, and 100 is the condition value.

[0031] Logical relations can include logical AND and logical OR relations. For example, a rule can be represented as {condition 1 && condition 2}, where "&&" represents the logical AND relation. A rule can include one or more logical relations. When a rule includes multiple conditions, the two conditions are connected by a logical relation.

[0032] A rule can include one or more sub-rules. A sub-rule is a whole formed by logical relationships between some conditions in its parent rule. Within the rule to which a sub-rule belongs, it can be connected to other conditions or other sub-rules through logical relationships. During rule execution, after the execution of a sub-rule yields its corresponding result, the results of that sub-rule's execution are then compared with the results of other conditions or sub-rules. For example, a rule might be represented as {condition 3||(condition 4&&condition 5)}, where "||" represents a logical OR relationship, and (condition 4&&condition 5) is a sub-rule within this rule.

[0033] In the embodiments of this specification, the multiple rules to be executed can be a rule package. When the rule execution engine runs, the multiple rules in a rule package are executed, obtaining the execution result for each rule. The obtained multiple rules can be rules that have already been deployed, for example, rules that have been deployed to the rule execution engine. When the rule execution engine runs, these deployed multiple rules are executed. In one example, the multiple rules to be executed can be run as a model, and the model composed of multiple rules can be applied to different business scenarios.

[0034] In one example, the rules can be defined as strings. Figure 2 For example, Figure 2 This shows a rule defined as a string. Strings are highly readable, and defining rules as strings improves readability.

[0035] In this example, rules can be defined on the page, and these rules can then be displayed on the page. This allows rules to be edited on the page when updates are needed, improving the ease of rule modification. Furthermore, the strong readability of the strings means that even non-experts can modify the rules.

[0036] In one example, rules are defined as strings. After each rule is defined, multiple rules defined as strings can be obtained. Then, each rule can be compiled to convert its string representation into an executable language. These executable rules can then be executed, placing the compiled rules in a state of pending execution. The compiled executable language can differ depending on the execution environment. For example, in a Java execution environment, the compiled executable language is Java bytecode.

[0037] In this example, each condition in each rule can be compiled separately, so that each condition is compiled into an executable language. Each condition is compiled individually, and thus each compiled condition can be processed independently, yielding the corresponding condition execution result. In this disclosure, the conditions can be processed in ways including: calling computing resources to execute the condition to obtain the corresponding condition execution result, and directly retrieving the corresponding condition execution result from the cache.

[0038] The rule execution method provided in the embodiments of this specification can be applied to different execution environments such as Java. This specification uses a Java execution environment as an example. In one example, in a Java execution environment, multiple acquired rules can be compiled into a single class and instantiated. After compilation into a class, the memory resources occupied are small, and the code running during rule execution only includes a few Java classes, thus reducing the dependencies of rule execution. Furthermore, after compiling multiple rules into a class, the execution of the compiled class can adapt to native Java syntax, resulting in high rule execution performance.

[0039] In this example, within the Java execution environment, the strings representing each rule can be converted into a version of an expression and then compiled into Java bytecode. Multiple versions of the Java execution environment can be used. For instance, the strings representing each rule can be converted into JDK 8 lambda expressions and then compiled into Java bytecode. JDK 8 is one version of the Java execution environment.

[0040] In one example, after compiling each condition in each rule into an executable language, different class loaders can be used to load the compiled rules. This breaks the parent delegation mechanism, allowing different class loaders to load the same rule after modification, achieving hot reloading. By using different class loaders, different versions can be loaded, thus isolating the loaded classes in memory.

[0041] In 120, for each rule that includes multiple conditions, the conditions included in the rule can be sorted in descending order according to the frequency of occurrence of each repeated condition included in the rule.

[0042] In the embodiments of this specification, a repeated condition is a condition that appears multiple times in the acquired multiple rules, that is, at least two rules include the same condition, and the same condition is a repeated condition. Figure 3 A diagram illustrating an example of multiple rules is shown. For example... Figure 3As shown, condition B appears in rule 1, rule 2, and rule 3, so condition B is a repeated condition.

[0043] Each rule, including those with multiple conditions, can be processed independently. For each rule, we can determine the repeating and non-repeating conditions among all the conditions included in that rule. A non-repeating condition is one that appears only once in all the rules to be executed. Figure 3 For example, for rule 1, condition C and A are non-repeating conditions, while condition B is a repeating condition.

[0044] Then, count the number of times each repeating condition appears in the multiple rules to be executed. Figure 3 For example, condition B appears 3 times. Each non-repeating condition appears once. Next, for each rule, all conditions within that rule are sorted in descending order based on the frequency of each repeating condition; that is, conditions with higher frequencies appear first, and conditions with lower frequencies appear last. For multiple conditions with the same frequency, a random sorting method can be used. Figure 3 For example, in rule 1, condition B appears 3 times, while conditions C and A appear once each. Therefore, condition B is ranked before conditions C and A, and conditions C and A can be randomly ordered. The descending order of rule 1 is as follows: Figure 4 As shown.

[0045] By sorting the conditions in each rule in descending order of their frequency of occurrence, each condition in each rule is processed sequentially during rule execution. This prioritizes conditions that appear frequently, thus maximizing the sharing of execution results for repeated conditions.

[0046] In one example, after sorting the conditions included in a rule in descending order based on the number of times each rule contains a repeating condition that appears multiple times in multiple rules, the rules can also be sorted in ascending order based on the number of repeating conditions included in each rule.

[0047] The order in which rules are ordered determines their execution sequence, with rules listed earlier being executed first. In this example, the rules with fewer repetitive conditions can be ordered first, while rules with more repetitive conditions can be ordered later.

[0048] In this example, by sorting the rules, rules with fewer repetitive conditions are executed first. The more repetitive conditions a rule has, the higher the probability that it will directly retrieve the condition execution result from the cache. Moreover, the more repetitive conditions there are, the more condition execution results will be retrieved directly. Correspondingly, the probability of directly obtaining the execution result of the corresponding rule based on more condition execution results is greater. As a result, the number of conditions that need to be executed by calling computing resources to obtain the condition execution result is reduced, thus reducing the computation of conditions.

[0049] In 130, when executing each rule among multiple rules, for each condition included in each rule, if the cache stores the execution result of the corresponding condition, the execution result of that condition can be retrieved from the cache.

[0050] In the embodiments of this specification, each rule can be executed independently to obtain the corresponding rule execution result. When multiple rules to be executed are ordered, they can be executed sequentially according to the order. For each rule, when the rule includes multiple conditions, these multiple conditions have been ordered according to the operation described in 120 above, so that the conditions in the rule can be processed sequentially according to the order of the conditions. When all conditions in a rule have been processed, all conditions are executed one at a time according to the order of the conditions. When the rule execution result corresponding to the rule is obtained after some conditions in the rule have been processed, and other conditions in the rule have not been processed, the conditions processed in the rule are processed sequentially according to the order of the conditions.

[0051] In the embodiments of this specification, the conditions may be processed in the following ways: by invoking computing resources to execute the conditions to obtain the corresponding condition execution results, and by directly retrieving the corresponding condition execution results from the cache. The result of processing each condition is to obtain the corresponding condition execution result.

[0052] For the currently processed condition, if the cache stores the execution result corresponding to that condition, the result can be retrieved from the cache. Specifically, the cache stores the execution results corresponding to each duplicate condition among the processed conditions. Processed conditions are those that have already been processed and have corresponding execution results. The execution results for duplicate conditions can be stored in the cache, while the execution results for non-duplicate conditions do not need to be stored in the cache.

[0053] In one example, if the cache does not store the result of the condition corresponding to the currently processed condition, then the condition is executed to obtain the result. In this example, computing resources can be invoked to execute the condition.

[0054] In one approach, before a condition is processed, the cache can be checked to see if the corresponding condition execution result is stored. If it is, the result can be retrieved directly from the cache. If not, computational resources can be invoked to execute the condition and obtain the corresponding result.

[0055] In the example above, after executing the condition by calling computing resources and obtaining the corresponding condition execution result, the obtained condition execution result can be stored in the cache.

[0056] In one example, the results of executing all conditions can be stored in a cache. In this example, the cache includes the results of executing conditions with duplicate conditions as well as the results of executing conditions with non-duplicate conditions.

[0057] In another example, the cache only stores the execution results of duplicate conditions. Therefore, when the currently executed condition is a duplicate, the obtained execution result can be stored in the cache. Before performing the storage operation, it can be determined whether the currently executed condition is a duplicate. If it is, it is stored; otherwise, it is not. In this example, the currently executed condition is completed by invoking computing resources.

[0058] Repeating and non-repeating conditions can be distinguished in advance. One method involves recording either repeating or non-repeating conditions. When a judgment operation is needed, the records are queried. Another method involves marking repeating conditions, then unmarked conditions are considered non-repeating conditions. Alternatively, marking non-repeating conditions, then unmarked conditions are considered repeating conditions. This allows judgment operations to be performed through marking.

[0059] When a rule contains only one condition, the execution result of that condition can be determined as the execution result of the rule. When a rule contains multiple conditions, the execution result of the corresponding condition can be obtained when one of the conditions is processed (including retrieving the corresponding condition execution result directly from the cache and calling computing resources to execute the condition).

[0060] Upon obtaining the execution result of the current processing condition, the rule can continue to be executed based on that result until the execution result of the rule is obtained. One way to continue rule execution is to obtain the rule's execution result based on the execution results of all previously processed conditions; another way is to continue processing the next condition.

[0061] In one example, when the currently executing rule includes multiple conditions, these conditions are connected by logical relationships. If the current processing condition is connected to other conditions via a logical AND relationship, and the execution result of the current processing condition is false, it can be determined that the execution result of the sub-rule corresponding to the sub-rule formed by that logical AND relationship is also false.

[0062] by Figure 4 For example, in rule 3, (condition D&&condition E) is a sub-rule formed by connecting condition D and condition E through a logical AND relation. When condition D is the current processing condition and the execution result of the condition corresponding to condition D is false, it can be determined that the execution result of the sub-rule (condition D&&condition E) is false.

[0063] When the execution result of the sub-rule corresponding to the sub-rule is obtained, the execution result of the rule corresponding to the determined sub-rule can be determined based on the execution result of the determined sub-rule corresponding to the sub-rule.

[0064] In another example, in the currently executing rule, when the rule includes multiple conditions, these conditions are connected by logical relationships. When the currently processed condition is connected to other conditions by a logical OR relationship, if the result of that condition's execution is true, it can be determined that the result of the sub-rule corresponding to the sub-rule formed by that logical OR relationship is also true.

[0065] For example, if a subrule (condition M||condition N) is a subrule formed by connecting condition M and condition N through a logical OR relation, and condition M is the current processing condition, and the execution result of the condition corresponding to condition M is true, then the execution result of the subrule (condition M||condition N) can be determined to be true.

[0066] When the execution result of the sub-rule corresponding to the sub-rule is obtained, the execution result of the rule corresponding to the determined sub-rule can be determined based on the execution result of the determined sub-rule corresponding to the sub-rule.

[0067] In one example, when the subrule that yields the execution result is the currently executed rule, the execution result of that subrule can be determined as the execution result of the rule corresponding to that rule. Figure 4For example, in rule2, the sub-rule formed by condition B and condition G is rule2. Therefore, when this sub-rule is true, rule2 is true; when this sub-rule is false, rule2 is false.

[0068] In another example, the currently executing rule includes not only the sub-rule that yielded the execution result of the sub-rule, but also other conditions or other sub-rules composed of other conditions. In this example, if the execution result of the currently executing rule cannot be obtained based on the currently obtained sub-rule execution result, the execution results of other conditions and / or other sub-rule execution results, the other unprocessed conditions in the currently executing rule will continue to be processed.

[0069] In step 140, after all the rules to be executed have been executed, the execution results of each rule can be obtained.

[0070] Figure 5 A block diagram of an example of a rule execution engine 500 provided according to an embodiment of this specification is shown.

[0071] like Figure 5 As shown, the rule execution engine 500 includes: a rule acquisition unit 510, a condition sorting unit 520, a condition processing unit 530, and a result acquisition unit 540.

[0072] The rule acquisition unit 510 can be configured to acquire multiple rules to be executed, wherein each rule consists of a condition or multiple conditions connected by logical relationships.

[0073] In one example, the rules are defined as strings.

[0074] In one example, the rule execution engine 500 also includes a compilation unit that can be configured to: obtain the plurality of rules defined as strings; and compile each condition in each rule into an executable language, so that the plurality of rules are in a state of pending execution.

[0075] In one example, the compilation unit can also be configured to compile the multiple rules into a single class in the Java execution environment.

[0076] In one example, the rule execution engine 500 also includes a rule loading unit that can be configured to load the compiled rules using different class loaders after they have been compiled into an executable language.

[0077] The condition sorting unit 520 can be configured to sort the conditions included in a rule in descending order according to the number of times each repeated condition appears multiple times in the multiple rules.

[0078] In one example, the rule execution engine 500 may also include a rule sorting unit that can be configured to sort the rules in ascending order based on the number of repetitive conditions included in each rule.

[0079] The condition processing unit 530 can be configured to, when executing each of the multiple rules, retrieve the condition execution result from the cache when the cache stores the condition execution result corresponding to the condition, for each condition included in each rule. The cache stores the condition execution results corresponding to each repeated condition among the processed conditions, and the conditions processed in each rule are processed sequentially according to the order of the conditions.

[0080] The resulting unit 540 can be configured to obtain the execution results of each rule after multiple rules have been executed.

[0081] In one example, the condition processing unit 530 can also be configured to: when executing each rule among multiple rules, for each condition included in each rule, if the condition execution result corresponding to the condition is not stored in the cache, execute the condition to obtain the condition execution result corresponding to the condition; and store the obtained condition execution result in the cache.

[0082] In one example, the condition processing unit 530 can also be configured to store the obtained condition execution result in a cache when the currently executed condition is a duplicate condition.

[0083] In one example, the rule execution engine 500 may also include a rule execution unit, which can be configured to: for each rule, when the condition execution result corresponding to the current processing condition is obtained, continue to execute the rule according to the condition execution result until the rule execution result corresponding to the rule is obtained.

[0084] In one example, the rule execution unit can also be configured to: when the current processing condition in the rule is connected to other conditions through a logical AND relation, determine that the execution result of the sub-rule corresponding to the sub-rule formed by the logical AND relation is false when the execution result of the condition is false; when the current processing condition in the rule is connected to other conditions through a logical OR relation, determine that the execution result of the sub-rule corresponding to the sub-rule formed by the logical OR relation is true when the execution result of the condition is true; and determine the rule execution result corresponding to the rule based on the execution result of the determined sub-rule.

[0085] In one example, the rule execution unit can also be configured to: when the sub-rule that yields the sub-rule execution result is the rule itself, determine the sub-rule execution result corresponding to the sub-rule as the rule execution result corresponding to the rule itself.

[0086] Reference above Figures 1 to 5 This specification describes embodiments of a method for executing rules and a rule execution engine.

[0087] The rule execution engine in the embodiments of this specification can be implemented in hardware, software, or a combination of hardware and software. Taking software implementation as an example, as a logical device, it is formed by the processor of the device loading corresponding computer program instructions from memory into RAM and executing them. In the embodiments of this specification, the rule execution engine can, for example, be implemented using an electronic device.

[0088] Figure 6 A block diagram of an electronic device 600 for implementing a rule enforcement method according to an embodiment of this specification is shown.

[0089] like Figure 6 As shown, electronic device 600 may include at least one processor 610, memory (e.g., non-volatile memory) 620, RAM 630, and communication interface 640, and the at least one processor 610, memory 620, RAM 630, and communication interface 640 are connected together via bus 650. At least one processor 610 executes at least one computer-readable instruction (i.e., the elements implemented in software above) stored or encoded in memory.

[0090] In one embodiment, computer-executable instructions are stored in memory, which, when executed, cause at least one processor 610 to: acquire a plurality of rules to be executed; sort the conditions included in a rule in descending order according to the number of times each repeated condition appears multiple times in the plurality of rules; when executing each rule in the plurality of rules, when a condition execution result corresponding to a condition is stored in a cache, retrieve the condition execution result from the cache for each condition included in each rule; and after the plurality of rules are executed, obtain the rule execution result of each rule.

[0091] It should be understood that the computer-executable instructions stored in memory, when executed, cause at least one processor 610 to perform the above-described combinations in the various embodiments of this specification. Figure 1-5 The description includes various operations and functions.

[0092] According to one embodiment, a program product, such as a machine-readable medium, is provided. The machine-readable medium may have instructions (i.e., the elements implemented in software as described above), which, when executed by a machine, cause the machine to perform the above-described combinations of the various embodiments of this specification. Figure 1-5 The description includes various operations and functions.

[0093] Specifically, a system or apparatus equipped with a readable storage medium may be provided, on which software program code implementing the functions of any of the embodiments described above is stored, and the computer or processor of the system or apparatus can read and execute the instructions stored in the readable storage medium.

[0094] In this case, the program code itself, which can be read from a readable medium, can perform the functions of any of the above embodiments. Therefore, the machine-readable code and the readable storage medium storing the machine-readable code constitute a part of the present invention.

[0095] The computer program code required for the operation of each part of this manual can be written in any one or more programming languages, including object-oriented programming languages ​​such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB, .NET, and Python; conventional procedural programming languages ​​such as C, Visual Basic 2003, Perl, COBOL 2002, PHP, and ABAP; dynamic programming languages ​​such as Python, Ruby, and Groovy; or other programming languages. This program code can run on the user's computer, or as a standalone software package on the user's computer, or partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer via any network, such as a local area network (LAN) or wide area network (WAN), or connected to an external computer (e.g., via the Internet), or in a cloud computing environment, or used as a service, such as Software as a Service (SaaS).

[0096] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer or the cloud via a communication network.

[0097] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0098] Not all steps and units in the above process and system structure diagrams are mandatory; some steps or units can be omitted as needed. The execution order of each step is not fixed and can be determined as required. The device structure described in the above embodiments can be a physical structure or a logical structure. That is, some units may be implemented by the same physical entity, or some units may be implemented by multiple physical entities, or they may be jointly implemented by certain components in multiple independent devices.

[0099] The term "exemplary" as used throughout this specification means "serving as an example, instance, or illustration" and does not imply that it is "preferred" or "advantageous" over other embodiments. Detailed descriptions are included for the purpose of providing an understanding of the described techniques. However, these techniques may be practiced without these detailed descriptions. In some instances, well-known structures and apparatuses are shown in block diagram form to avoid obscuring the concepts of the described embodiments.

[0100] The optional embodiments of the present specification have been described in detail above with reference to the accompanying drawings. However, the embodiments of the present specification are not limited to the specific details in the above embodiments. Within the scope of the technical concept of the embodiments of the present specification, various simple modifications can be made to the technical solutions of the embodiments of the present specification, and these simple modifications all fall within the protection scope of the embodiments of the present specification.

[0101] The foregoing description of this specification is provided to enable any person skilled in the art to implement or use the content of this specification. Various modifications to the content of this specification will be apparent to those skilled in the art, and the general principles defined herein can be applied to other variations without departing from the scope of protection of this specification. Therefore, this specification is not limited to the examples and designs described herein, but is consistent with the widest scope of the principles and novel features disclosed herein.

Claims

1. A method for enforcing rules, comprising: Retrieve multiple rules to be executed, where each rule consists of a single condition or multiple conditions connected by logical relationships; For each rule that includes multiple conditions, the conditions included in the rule are sorted in descending order according to the number of times each repeated condition appears multiple times in the multiple rules included in the rule. When executing each rule among the plurality of rules, for each condition included in each rule, if the cache stores the execution result corresponding to that condition, the execution result is retrieved from the cache. The cache stores the execution results corresponding to each duplicate condition among the processed conditions, and the conditions processed in each rule are processed sequentially according to the order of the conditions. After all the rules have been executed, the execution results of each rule are obtained.

2. The method of claim 1, further comprising: When executing each of the multiple rules, for each condition included in each rule, if the cache does not store the condition execution result corresponding to that condition, the condition is executed to obtain the condition execution result corresponding to that condition. as well as The obtained conditional execution results are stored in the cache.

3. The method of claim 2, wherein, Storing the obtained conditional execution results into the cache includes: When the condition for the current execution is a repeated condition, the result of the condition execution is stored in the cache.

4. The method of claim 1, further comprising: For each rule, when the execution result corresponding to the current processing condition is obtained, the rule is executed again based on the execution result until the execution result of the rule corresponding to the current processing condition is obtained.

5. The method of claim 4, wherein, The rule continues to be executed based on the result of this condition until the execution result of the corresponding rule is obtained, including: In this rule, when the current processing condition is connected to other conditions through a logical AND relation, if the result of the condition is false, the result of the sub-rule corresponding to the sub-rule formed by the logical AND relation is determined to be false. In this rule, when the current processing condition is connected to other conditions via a logical OR relation, if the execution result of this condition is true, the execution result of the sub-rule corresponding to the sub-rule formed by the logical OR relation is determined to be true; and The execution result of the rule is determined based on the execution result of the sub-rule corresponding to the determined sub-rule.

6. The method of claim 5, wherein, The execution result of the rule corresponding to the determined sub-rule is determined based on the execution result of the sub-rule, including: When the subrule that yields the execution result of the subrule is the rule itself, the execution result of the subrule corresponding to the subrule is determined as the execution result of the rule itself.

7. The method of claim 1, wherein, After sorting the conditions included in the rule in descending order according to the frequency of occurrence of each repeated condition that appears multiple times in the plurality of rules, the method further includes: Sort the rules in ascending order based on the number of repeated conditions they contain.

8. The method of claim 1, wherein, Each rule is defined in the form of a string.

9. The method of claim 8, further comprising: Retrieve the multiple rules defined as strings; as well as Each condition in each rule is compiled into an executable language, so that the multiple rules are in a state of pending execution.

10. The method of claim 9, further comprising: In the Java execution environment, the multiple rules are compiled into a single class.

11. The method of claim 9 or 10, further comprising: After being compiled into an executable language, different class loaders are used to load the compiled rules.

12. A rule execution engine, comprising: The rule acquisition unit acquires multiple rules to be executed, wherein each rule consists of a single condition or multiple conditions connected by logical relationships; The condition sorting unit sorts the conditions of a rule in descending order according to the number of times each repeated condition appears multiple times in the multiple rules. The condition processing unit, when executing each rule among the plurality of rules, retrieves the condition execution result from the cache when the cache contains the corresponding condition execution result for each condition included in each rule. The cache stores the condition execution results corresponding to each duplicate condition among the processed conditions, and the conditions processed in each rule are processed sequentially according to the order of the conditions. The result obtaining unit obtains the rule execution result of each rule after the execution of the multiple rules is completed.

13. An electronic device comprising: At least one processor, a memory coupled to the at least one processor, and a computer program stored on the memory, wherein the at least one processor executes the computer program to implement the method as described in any one of claims 1-11.

14. A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method as described in any one of claims 1-11.

15. A computer program product comprising a computer program that, when executed by a processor, implements the method as described in any one of claims 1-11.

Citation Information

Patent Citations

  • Rule management system and method

    US20170337197A1

  • Business rule management system having hierarchical rule structure and representation method thereof

    WO2015137641A2