Rule processing method, device, equipment and storage medium

By obtaining the rule output requirements and scenario adapter analysis rules, the problem of low rule conversion efficiency in the existing technology is solved, and flexible conversion and efficient processing of rules in different scenarios are realized.

CN112069214BActive Publication Date: 2025-01-10DOUYIN VISION CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010941802.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-09
Publication Date
2025-01-10
Estimated Expiration
2041-01-10

AI Technical Summary

Technical Problem

In the prior art, the efficiency of regular conversion is low, and manual conversion is required, which is inefficient.

Method used

By obtaining the rule output requirements, determining the scene adapter, analyzing the rules and calling the adapter for processing, the flexible conversion of rules in different scenarios is realized.

Benefits of technology

Improves the efficiency and accuracy of rule conversion and enhances the flexibility of rule output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112069214B_ABST
    Figure CN112069214B_ABST
Patent Text Reader

Abstract

The disclosed embodiments provide a rule processing method, apparatus, device and storage medium, the method comprising obtaining a rule output requirement, determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter; obtaining a rule to be processed and parsing the rule to obtain at least one element contained in the rule; processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule. The rule processing method, apparatus, device and storage medium provided by the disclosed embodiments can make specific conversions of the rule in the scene where it is used, improve the flexibility of rule output, and effectively improve the efficiency and accuracy of rule conversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular, to a rule processing method, apparatus, device, and storage medium. Background Art

[0002] With the continuous development of science and technology, various social and commercial activities are emerging in an endless stream, and rule-based automated processing capabilities are becoming increasingly important. In some scenarios, staff can configure specific rules to determine whether the target object meets the conditions, thereby achieving operations on the target object. For example, when judging whether a user is eligible to participate in an activity, certain rules can be formed based on reference indicators such as the user's age and risk tolerance, so that registered users can be screened to obtain qualified users.

[0003] Currently, most rules are saved in the form of expressions. When rules need to be converted, they can only be converted into corresponding output results manually, which is inefficient. Summary of the invention

[0004] The embodiments of the present disclosure provide a rule processing method, apparatus, device and storage medium to overcome the technical problem of low efficiency of rule conversion.

[0005] In a first aspect, an embodiment of the present disclosure provides a rule processing method, including:

[0006] Obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter;

[0007] Obtaining a rule to be processed and parsing the rule to obtain at least one element included in the rule;

[0008] The at least one element is processed by the first scene adapter to obtain an output result corresponding to the rule.

[0009] In a second aspect, an embodiment of the present disclosure provides a rule processing device, including: a business logic module, a rule engine, and at least one scenario adapter;

[0010] The business logic module is used to obtain a rule output requirement and determine a first scenario adapter corresponding to the rule output requirement from the at least one scenario adapter;

[0011] The rule engine is used to obtain the rule to be processed and parse the rule to obtain at least one element contained in the rule, call the first scene adapter to process the at least one element, and obtain the output result corresponding to the rule.

[0012] In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a memory and at least one processor;

[0013] The memory stores computer-executable instructions;

[0014] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the rule processing method described in the first aspect and various possible designs of the first aspect.

[0015] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the rule processing method described in the first aspect and various possible designs of the first aspect is implemented.

[0016] The rule processing method, apparatus, device and storage medium provided by the embodiments of the present disclosure can obtain rule output requirements, determine a first scene adapter corresponding to the rule output requirements from at least one scene adapter, obtain the rules to be processed and parse the rules to obtain at least one element contained in the rules, process the at least one element through the first scene adapter to obtain an output result corresponding to the rule, so that the rules can be specifically converted in the scenarios where they are used, thereby improving the flexibility of rule output and effectively improving the efficiency and accuracy of rule conversion. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0018] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present disclosure;

[0019] Figure 2 A flowchart of a rule processing method provided by an embodiment of the present disclosure;

[0020] Figure 3 A flowchart of another rule processing method provided by an embodiment of the present disclosure;

[0021] Figure 4 A schematic diagram of a syntax tree provided in an embodiment of the present disclosure;

[0022] Figure 5 A schematic diagram of a syntax tree corresponding to a specific rule provided in an embodiment of the present disclosure;

[0023] Figure 6 A schematic diagram of the implementation principle of a rule evaluator provided in an embodiment of the present disclosure;

[0024] Figure 7 A schematic diagram of the implementation principle of a natural language translator provided in an embodiment of the present disclosure;

[0025] Figure 8 A schematic diagram of the implementation principle of a query statement converter provided in an embodiment of the present disclosure;

[0026] Fig. 9 A schematic diagram of the implementation principle of a condition checker provided in an embodiment of the present disclosure;

[0027] Fig.10 A structural block diagram of a rule processing device provided in an embodiment of the present disclosure;

[0028] Fig.11 A structural block diagram of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0029] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0030] The technical solution provided by the embodiments of the present disclosure can be applied to any field where rules can be set. The rules can be any type of rules, for example, access rules set for a group, process rules designed for an activity, constraint rules designed for certain users, etc.

[0031] In actual applications, rules may need to have different expressive capabilities in different scenarios: when being read by staff, the rules need to be converted into natural language form; when judging whether a user meets the requirements of the rules, calculation capabilities based on context parameters need to be provided; when querying all people who meet the rules, the rules need to be converted into specific query statements.

[0032] In order to solve this problem, the embodiments of the present disclosure can construct a scene adapter corresponding to each scene for multiple scenes, obtain the rules to be processed through a rule engine with multi-scene adaptation function, and call the scene adapter corresponding to the current scene for processing, so as to convert the rules into corresponding output results, thereby improving the flexibility and efficiency of rule output.

[0033] Figure 1 A schematic diagram of an application scenario provided by an embodiment of the present disclosure. Figure 1 As shown, staff members, such as those responsible for operations, can enter user conditions that meet group requirements, such as users entering the group must be older than a certain age, etc. Based on the content entered by the staff, rules can be created, and the rules can be expressed by reference expressions. Assuming that the content entered by the staff is "X attribute is greater than 1 and Y attribute is less than 4", the content can be converted into the reference expression "x>1&&y<4".

[0034] By passing the benchmark expression and the scenario adapter corresponding to the current scenario to the rule engine, the benchmark expression can be converted into an output result that conforms to the current scenario.

[0035] In the first scenario, rule operations with given parameters can be implemented. Specifically, the values ​​of x and y can be given to determine the output value corresponding to the rule. If the output value is true, it means that the x and y values ​​meet the rule. If the output value is false, it means that the x and y values ​​do not meet the rule. For example, if the x attribute corresponding to a user is 2 and the y attribute is 5, after inputting x=2 and y=5, since the rule is x>1&&y<4, the output value is false, indicating that the user does not meet the requirements of the group.

[0036] In the second scenario, the rule can be converted into a query statement. Specifically, when it is necessary to search for users that meet the rule requirements in the database, the rule can be converted into a corresponding query statement, for example, "x>1&&y<4" can be converted into "x>1and y<4" that meets the database query requirements.

[0037] In the third scenario, the rules can be converted into natural language. Specifically, when the rules of a group need to be displayed to the staff, the rules can be converted into natural language, for example, "x>1&&y<4" can be converted into "x attribute is greater than 1 and y attribute is less than 4", and the staff can read the rules in natural language.

[0038] It should be noted that the rules described in the embodiments of the present disclosure may refer to any form of rules and are not limited to rules with only true and false results. If an expression has practical meaning, then the expression can be considered as a rule. For example, if an expression is a+b=c, where a represents age, b represents the number of monthly logins, and c represents the credit value, then the expression can correspond to a rule, and the rule can indicate that the user's credit value can be equal to the sum of the user's age and the number of monthly logins.

[0039] Of course, the technical solutions provided by the embodiments of the present disclosure can also be applied to other scenarios besides the above scenarios. Some embodiments of the present disclosure are described in detail below in conjunction with the accompanying drawings. In the case where there is no conflict between the embodiments, the following embodiments and the features in the embodiments can be combined with each other.

[0040] Figure 2 A schematic diagram of a flow chart of a rule processing method provided by an embodiment of the present disclosure. The method of this embodiment can be applied to any device with a data processing function, such as a server or a processing terminal.

[0041] like Figure 2 As shown, the rule processing method may include:

[0042] Step 201: Obtain a rule output requirement, and determine a first scenario adapter corresponding to the rule output requirement from at least one scenario adapter.

[0043] In the embodiments of the present disclosure, in order to implement the scene adaptation function of the rule, at least one scene adapter may be provided, and different rule output requirements may correspond to different scene adapters.

[0044] The rule output requirement is used to convert the rule into a certain result and output it, for example, to calculate the output value corresponding to the rule given the value of the variable in the rule, or to convert the rule into a certain language, etc. The rule output requirement can be obtained in many ways.

[0045] In one example, the rule output requirement can be triggered by a staff member. Optionally, an interface for obtaining the rule output requirement can be displayed. When the staff member has a need to use a rule, the rule output requirement can be input on the interface. For example, when it is necessary to determine whether a user's condition information complies with a rule, the user's condition information can be input and a query button can be clicked. When the rule needs to be converted into natural language, a button for viewing the rule can be clicked.

[0046] In another example, the rule output requirement can be triggered at a fixed time. For example, at a preset time, a rule output requirement for converting the rule into a query statement of the database is automatically generated, so that the user who currently meets the rule is queried from the database at a fixed time.

[0047] In another example, the rule output requirement may be automatically triggered when certain conditions are met. For example, it may be set that when the number of users in a group reaches an upper limit, a rule output requirement for determining whether each user in the group meets the rule requirement is automatically generated.

[0048] Optionally, obtaining the rule output requirement may be implemented by a business logic module. After obtaining the rule output requirement, the business logic module may determine the corresponding first scenario adapter according to the rule output requirement, and trigger the rule engine to call the scenario adapter to convert and output the rule.

[0049] Step 202: Obtain a rule to be processed and parse the rule to obtain at least one element included in the rule.

[0050] The rules to be processed may be stored locally or in other locations. The obtained rules to be processed may be expressed in many forms. Optionally, the rules may be expressed in the form of expressions, or in the form of codes such as script statements, or in the form of rule trees, linked lists, etc.

[0051] The rule may include at least one element. The at least one element may include one or more parts obtained by splitting the rule in any manner. For example, when the rule is represented by an expression, the element may include any one of a variable, a number, an operator, a bracket, a sub-expression, or a combination of any number thereof.

[0052] For example, assuming that the rule is an expression x>1&&y<4, after parsing the rule, the elements x,>,1,&&,y,<,4 can be obtained. Alternatively, the elements x>1,&&,y<4 can also be obtained by other parsing methods. The embodiments of the present disclosure are not limited to this.

[0053] There are many ways to obtain and parse the rules to be processed. Optionally, the rules can be accessed by the business logic module. After obtaining the rule output requirements, the business logic module can pass the rules to the rule engine, which is responsible for parsing the rules.

[0054] Step 203: Process the at least one element through the first scene adapter to obtain an output result corresponding to the rule.

[0055] After obtaining at least one element of the rule, for each element, the element can be processed by the first scene adapter to obtain a result corresponding to the element. After processing at least one element, an output result corresponding to the rule can be obtained.

[0056] For the same element, different scene adapters may correspond to different processing methods, thereby obtaining different processing results.

[0057] For example, assuming the rule is the expression x>1&&y<4, after parsing the rule, we can get the elements x,>,1,&&,y,<,4. One of the scene adapters can translate x,>,1,&&,y,<,4 into age,greater than,1,and,purchasing power,less than,4, respectively. The output result corresponding to the rule is: age is greater than 1 and purchasing power is less than 4, realizing the translation of rules into natural language, which is convenient for staff to view.

[0058] Another scene adapter can convert x, >, 1, &&, y, <, 4 into x, >, 1, and, y, <, 4 respectively, so that the corresponding output result is: x>1and y<4. This output result is suitable for database query and can be directly input into the database to realize the query of data that meets the rule requirements.

[0059] In actual applications, the processing of elements can be realized by calling the scene adapter through the rule engine. Specifically, the rule output requirements can be obtained through the business logic module, and the current scenario can be determined according to the rule output requirements, for example, whether to convert the rules into natural language or into database query statements. The business logic module can inform the rule engine which scene adapter needs to be called, and then the rule engine can call the scene adapter corresponding to the current scene to determine the output result corresponding to the rule. The output result can be the natural language or query statement corresponding to the rule, or it can also be any other result related to the rule. The output result can be transmitted to the scene adapter by the rule engine, and then fed back to the business logic module by the scene adapter.

[0060] Furthermore, the business logic module can also be used to implement interaction with users or other devices. Optionally, the business logic module can provide an interface for triggering rule output requirements, and the staff or user can trigger the rule output requirements on the interface. After obtaining the output results corresponding to the rules, the output results can be displayed to the staff or user, or sent to other devices.

[0061] The rule processing method provided in this embodiment can obtain rule output requirements, determine the first scene adapter corresponding to the rule output requirements from at least one scene adapter, obtain the rule to be processed and parse the rule to obtain at least one element contained in the rule, and process the at least one element through the first scene adapter to obtain the output result corresponding to the rule, so that the rule can be specifically converted in the scenario where it is used, thereby improving the flexibility of rule output and effectively improving the efficiency and accuracy of rule conversion.

[0062] Based on the technical solution provided in the above embodiment, optionally, before obtaining the rule output requirements, the method may further include: obtaining user condition information that meets the group requirements; and determining the rules corresponding to the group according to the user condition information. The user condition information that meets the group requirements may be input by a staff member, or may be obtained from other platforms. The rules to be processed obtained by the rule engine may be the rules corresponding to the group, so that the operation of the group can be efficiently realized and the automatic operation and maintenance capability of the group can be improved.

[0063] Furthermore, when there are multiple groups, when the business logic module obtains the rule output requirement, it can determine the current group to be processed according to the rule output requirement, and determine the corresponding rules according to the group, so that the rule engine can process the rules corresponding to the group, realizing rule processing in multi-group situations and further improving the flexibility of rule processing.

[0064] Figure 3 This is a flow chart of another rule processing method provided by an embodiment of the present disclosure. This embodiment is based on the technical solution provided by the above embodiment, and implements the processing of rules through a syntax tree. Figure 3 As shown, the method includes:

[0065] Step 301: Obtain a rule output requirement, and determine a first scenario adapter corresponding to the rule output requirement from at least one scenario adapter.

[0066] The specific implementation principle and process of step 301 in this embodiment can be found in the above-mentioned embodiment and will not be described again here.

[0067] Step 302: Obtain the rules to be processed, and parse the rules to obtain a syntax tree.

[0068] In this embodiment, step 302 can be used to obtain the rule to be processed and parse the rule to obtain at least one element included in the rule.

[0069] The syntax tree obtained by parsing the rule may be any type of syntax tree, such as an Abstract Syntax Tree (AST). The at least one element includes a node in the syntax tree.

[0070] Figure 4 A schematic diagram of a syntax tree provided by an embodiment of the present disclosure. Figure 4 As shown, the syntax tree is in the shape of a tree. The ellipse in the figure can represent the node of the tree. If there are two branches under a node, then the node can be a binary node. The node can be used as an element of the rule, and each node can be processed by the scene adapter to obtain the output result corresponding to the rule.

[0071] Step 303: parse the syntax tree through a rule engine. Every time a node is parsed, call the function corresponding to the type of the node in the first scenario adapter to obtain the output result of the node; after all nodes of the syntax tree are parsed, obtain the output result corresponding to the rule.

[0072] In this embodiment, step 303 can be used to process the at least one element through the first scene adapter to obtain an output result corresponding to the rule.

[0073] The rule processing method provided in this embodiment first converts the rules into a syntax tree, which can be used to express the rules intuitively and effectively. Then, based on the syntax tree, the scenario adapter is called to process each node in the tree, and finally the output result corresponding to the rule is obtained, which effectively improves the efficiency of rule processing and is less prone to errors.

[0074] The method described in the embodiments of the present disclosure can be implemented in any language. For example, it can be implemented in the Go language. The Go language provides a specific implementation scheme for parsing expressions into syntax trees. Based on this, the embodiments of the present disclosure can abstract a layer of multi-scenario adaptation rule engine and build at least one scenario adapter so that the expression can be converted specifically in the corresponding scenario. Optionally, the functions of the rule engine can be implemented through the following code examples.

[0075]

[0076]

[0077] First, the base expression and syntax tree corresponding to the rule are defined through lines 1 to 4. Line 5 calls the corresponding scene adapter through the Accept function, where the first visitor in Accept (visitor Visitor) is used to represent the called scene adapter, and the second Visitor defines the type of the scene adapter. Each scene adapter can be implemented based on the Visitor interface.

[0078] Starting from line 6, the specific method of calling the scene adapter is implemented through the Visitor interface: when parsing to a binary node, the visitBinary function in the scene adapter is called, and the visitBinary function is used to implement the processing of the binary node; when parsing to an identifier, the visitIdent function in the scene adapter is called for processing; when parsing to a basic type value, the visitBasicLit function is called for processing.

[0079] In the above code example, the ellipsis in line 22 indicates that other possible function definitions are omitted. Based on the code example provided in this embodiment, other functions can be flexibly expanded according to actual needs. The Parse function in the last line is used to obtain a syntax tree according to the benchmark expression.

[0080] Figure 5 A schematic diagram of a syntax tree corresponding to a specific rule provided in an embodiment of the present disclosure. Figure 5 As shown, the syntax tree may correspond to the rule of x>1&&y<4. In actual work, recursion may be started from the top node of the syntax tree, and parsing may be started from the bottom node. When a node is parsed, a corresponding function is called to process it.

[0081] Specifically, you can first parse the node in the lower left corner to get x, which is a variable. Variables can be represented by identifiers. When parsing to variables, you can call the visitIdent function in the scene adapter for processing. The node to the right of x is 1, which is a constant. Constants can be represented by basic type values. You can call the visitBasicLit function in the scene adapter for processing. When parsing to the first node in the second row, the node is a binary node, including the operator >, and you can call the visitBinary function in the scene adapter for processing.

[0082] Each scene adapter can contain visitBinary, visitIdent, visitBasicLit functions, which are used to process the corresponding types of nodes. However, the processing logic of visitBinary, visitIdent, visitBasicLit functions is different in different scene adapters, and the output results for the same node are also different.

[0083] For example, for node x, the visitIdent function needs to be called for processing. If it is a scene adapter for evaluation, then under this scene adapter, the visitIdent function is used to assign a value to x according to the context parameter. If it is a scene adapter for translation, then under this scene adapter, the visitIdent function is used to translate x into corresponding text such as age.

[0084] Since different scenario adapters have different function processing logics, for the same node, the output results obtained through different scenario adapters are different. Therefore, different processing of the same node can be achieved through the functions in the scenario adapter. Regardless of the scenario, the work done by the rule engine can be the same. When a certain type of node is parsed, the corresponding function is called for processing, which effectively simplifies the processing logic of the rule engine and improves the applicability of the rule engine.

[0085] In combination with the above principles, some specific examples of scene adapters are given below. It is understandable that those skilled in the art can adjust the following scene adapters based on the embodiments provided by the present disclosure to obtain other scene adapters.

[0086] Optionally, the scenario adapter may include any one or more of a rule evaluator, a query statement converter, a natural language translator, and a condition checker. These scenario adapters can be adapted to various application scenarios to meet the conversion requirements of rules in different scenarios.

[0087] Correspondingly, obtaining the rule output requirement and determining the first scene adapter corresponding to the rule output requirement from at least one scene adapter may include any one of the following: if the obtained rule output requirement is used to indicate that the output value of the rule is calculated according to the input condition information, then the first scene adapter is determined to be the rule evaluator, and the input condition information is sent to the rule evaluator; or, if the obtained rule output requirement is used to indicate that the rule is converted into a query statement, then the first scene adapter is determined to be the query statement converter, and the query statement is used to query the data that conforms to the rule in the database; or, if the obtained rule output requirement is used to indicate that the rule is converted into a natural language, then the first scene adapter is determined to be the natural language translator; or, if the obtained rule output requirement is used to indicate that the constraints of the remaining variables are calculated given the values ​​of some variables in the rule, then the first scene adapter is determined to be the condition checker, and the values ​​of the some variables are sent to the condition checker.

[0088] By the above method, the first scene adapter corresponding to the rule output requirement can be quickly determined, and the rule engine can be instructed to call the first scene adapter to process the rule. For ease of description, the embodiment of the disclosure is described with the rule to be processed being x>1&&y<4.

[0089] In a first optional implementation manner, the first scenario adapter is a rule evaluator.

[0090] If the first scene adapter is the rule evaluator, the processing of the at least one element may include: for each node, if the node includes a variable, assigning a value to the variable according to the acquired input condition information; if the node includes a constant, returning the constant; if the node is a binary node and includes an operator, calculating the processing result corresponding to the binary node according to the operator.

[0091] Figure 6 A schematic diagram of the implementation principle of a rule evaluator provided in an embodiment of the present disclosure. Figure 6 As shown, the rule x>1&&y<4 is parsed into a syntax tree. Starting from the lower left corner, each time a node is parsed, the first scene adapter is called once to process the node through the corresponding function.

[0092] Specifically, first parse the x in the lower left corner, and then call the visitIdent function in the first scene adapter. Since the current first scene adapter is a rule evaluator, the visitIdent function can obtain the value corresponding to x through the input condition information, assign x, and feed the result back to the rule engine. For example, the input condition information is x=0, y=3. Then x will be assigned a value of 0.

[0093] Then, parse the 1 on the right, 1 is a constant, and call the visitBasicLit function in the adapter. In the rule evaluator, the visitBasicLit function can directly return the constant in the node to the rule engine without any additional work. Then continue to parse nodes y and 4 to complete the assignment of y.

[0094] After parsing the last row of nodes, you can start parsing the previous row of nodes. First, parse the leftmost binary node, call the visitBinary function, and input the operator > and 0 and 1 under the two branches into the visitBinary function. The visitBinary function performs operations based on the operator. Since 0>1 is false, the output result corresponding to the binary node is false. Similarly, after parsing the binary node on the right, the visitBinary function can be used to process the binary node. Since 3<4, the output result corresponding to the binary node is true.

[0095] Finally, the binary node in the first row is parsed again, and the visitBinary function is called again for processing. Since the result of false&&true is false, the final output result is false. In this way, the rule output value corresponding to the input condition of x=0, y=3 is obtained. The output value of false indicates that the input condition does not meet the requirements of the rule.

[0096] pass Figure 6 The method shown can realize the rule evaluation of given parameters, which can facilitate the staff or the system to query whether the conditions of a certain user meet the requirements of the rules, and then determine whether to add the user to the corresponding group, thereby realizing rapid judgment of user conditions and providing convenience for the staff.

[0097] In addition, Figure 6Based on the solution shown, optionally, the input condition information can be implemented through Json variables. By extracting the Json variable field, the input value corresponding to each variable in the rule can be determined, thereby improving the efficiency of assigning values ​​to the variables.

[0098] In a second optional implementation manner, the first scene adapter may be a natural language translator.

[0099] If the first scene adapter is the natural language translator, the processing of the at least one element may include: for each node, converting the node into corresponding text, so as to obtain the natural language corresponding to the rule after multiple nodes of the syntax tree are processed.

[0100] Figure 7 The following is a schematic diagram of the implementation principle of a natural language translator provided in an embodiment of the present disclosure. Figure 7 As shown, after obtaining the syntax tree corresponding to the rule x>1&&y<4, starting from the lower left corner, each time a node is parsed, the natural language translator is called once, and the node is processed by the corresponding function in the natural language translator. Among them, the function in the natural language translator can translate each node into the corresponding text, thereby realizing the conversion from rules to natural language. The natural language described in the embodiment of the present disclosure can refer to any language such as Chinese, English, Russian, etc. It is understandable that in order to achieve simple expression, English letters or numbers, etc. can be included in Chinese characters.

[0101] Specifically, first parse the x in the lower left corner, and then call the visitIdent function in the natural language translator. The visitIdent function can translate x into age and return it to the rule engine.

[0102] Then, the nodes 1, y and 4 may be further parsed and translated to obtain the corresponding text: 1, purchasing power, 4. In another optional manner, the nodes 1 and 4 are also translated into one and four.

[0103] After parsing the last row of nodes, you can start parsing the previous row of nodes. First, parse the leftmost binary node, call the visitBinary function, and input the operator > and the ages and 1 under the two branches into the visitBinary function. The visitBinary function translates the binary node and obtains the text: Age is greater than 1. Similarly, translate the binary node in the second row and obtain the text: Purchasing power is less than 4.

[0104] Finally, the binary node in the first line is parsed again, and the visitBinary function is called to process. Since && is translated as and, the final text obtained is: age is greater than 1 and purchasing power is less than 4, which is the output result of the rule.

[0105] Optionally, the natural language translator may store the correspondence between each variable, operator, constant and text, so that each node can be translated into the corresponding text according to the correspondence. Alternatively, the correspondence may be stored in other modules, and the natural language translator may implement the translation of the node by interacting with the other modules.

[0106] pass Figure 7 The method shown can translate the rules into natural language, which can be easily understood by non-R&D personnel and convenient for staff or users to view, thus providing convenience for staff and users.

[0107] In a third optional implementation, the first scenario adapter may be a query statement converter.

[0108] If the first scene adapter is the query statement converter, the processing of the at least one element may include: for each node, converting the node into a corresponding query field, so as to obtain the query statement corresponding to the rule after multiple nodes of the syntax tree are processed.

[0109] Figure 8 The following is a schematic diagram of the implementation principle of a query statement converter provided by an embodiment of the present disclosure. Figure 8 As shown, after obtaining the syntax tree corresponding to the rule x>1&&y<4, starting from the lower left corner, each time a node is parsed, the query statement converter is called once. The function in the query statement converter can convert each node into a corresponding query field, thereby realizing the conversion from rule to query statement.

[0110] The specific processing method is similar to that of the natural language translator. The nodes in the syntax tree are parsed from left to right and from bottom to top. When an identifier is parsed, the visitIdent function in the query statement converter is called. When a basic type value is parsed, the visitBasicLit function is called. When a binary node is parsed, the visitBinary function is called to obtain the corresponding query statement.

[0111] The query statement may be a query statement applied to any database. Optionally, the database may be a SQL (Structured Query Language) database.

[0112] In the SQL database, the query fields corresponding to x, 1, y, 4, >, < are still x, 1, y, 4, >, <, and the query field corresponding to the operator && is and. Therefore, the final query statement can be: x>0and y<4, as the output result of the rule.

[0113] Optionally, the query statement converter may store the correspondence between various variables, operators, constants and query fields, so that each node can be translated into a corresponding query field according to the correspondence. Alternatively, the correspondence may be stored in other modules, and the query statement converter may implement the conversion operation on the node by interacting with the other modules.

[0114] pass Figure 8 The method shown can realize converting the rules into query statements. After conversion into query statements, the query statements can be output to the database, so that data that meets the rule requirements can be searched in the database according to the query statements, thereby realizing automatic query of the database and improving the efficiency and accuracy of data processing.

[0115] In a fourth optional implementation, the first scene adapter may be a condition checker.

[0116] If the first scene adapter is the conditional checker, the processing of the at least one element may include: for each node, if the node includes a variable, assigning a value to the variable, or converting the variable into a corresponding text; if the node includes a constant, returning the constant; if the node is a binary node and includes an operator, calculating the processing result corresponding to the binary node according to the operator.

[0117] The specific processing principle of the conditional checker is similar to that of the rule evaluator, except that when a node includes a variable, it needs to be processed based on whether the value of the variable is given in the rule output requirement.

[0118] Optionally, if the node includes a variable, assign a value to the variable, or convert the variable into corresponding text, including: if the node includes a variable, determine whether a value corresponding to the variable is given in the rule output requirement; if so, assign a value to the variable; if not, convert the variable into corresponding text.

[0119] Assuming that the rule output requirement is to find the constraint conditions of y given the value of x, then in the processing process, x is assigned a value, and y is translated into text, and the final output result is the constraint conditions of y. For example, if the rule is x>0&&y<4, given x=1, the output result is purchasing power>4.

[0120] In order to better reflect the constraint relationship between various variables, the embodiment of the present disclosure provides another rule to be processed: x+y>3z. A possible application is that in this rule, x can represent age, y can represent the number of monthly logins, and z represents the user's level. This rule indicates that the sum of the user's age and the number of logins must be greater than 3 times the level to meet the requirements and enter the corresponding group.

[0121] Fig. 9 The following is a schematic diagram of the implementation principle of a condition checker provided in an embodiment of the present disclosure. Fig. 9 As shown, after obtaining the syntax tree corresponding to the rule x+y>3z, starting from the lower left corner, each time a node is parsed, the condition checker is called once to process the node through the corresponding function.

[0122] Assume that the given variable values ​​are x = 25, z = 10. When processing the syntax tree, first parse to the x in the lower left corner, and then call the visitIdent function in the condition checker. The visitIdent function can assign x to 5 and feed it back to the rule engine.

[0123] Then, the node y on the right is parsed and the visitIdent function is called. Since y has not been assigned a value, the text corresponding to y is returned: the number of monthly logins. Then, nodes z and 3 are processed again, and the results returned are 10 and 3 respectively.

[0124] After parsing the last row of nodes, you can start parsing the previous row of nodes. First, parse the leftmost binary node and call the visitBinary function. According to the operator + and the 25 and monthly login times in the two branches, you can get the corresponding result of 25 + monthly login times. After parsing the binary node on the right, according to the operator * and the 10 and 3 in the two branches, you can get the corresponding result of 10*3=30.

[0125] Finally, the binary node in the first row is parsed again, and the visitBinary function is called again for processing. At this time, the constraint relationship has become 25 + monthly login times > 30, so the final output result can be that the monthly login times are greater than 5. In this way, the constraint condition y is obtained given the input conditions of x = 25 and z = 10, indicating that when the user's age is 25 and the level is 10, the monthly login times must be at least 5 to meet the group requirements.

[0126] pass Fig. 9 The method shown can realize the constraints of the remaining variables by given the values ​​of some variables, which is convenient for staff or users to view. It can also push relevant messages to users based on the constraints, such as prompting users how many monthly login times they need to reach before they can join the group, thereby improving the flexibility of using rules.

[0127] The above gives the specific implementation principles of each scene adapter. In practical applications, the rule engine can call the scene adapter to implement the processing of the rules. Multiple functions can be set in the scene adapter to process different types of nodes respectively. On this basis, the scene adapter also supports function extension functions, and the business logic module or the rule engine defines new functions and implements the extension of functions in the scene adapter. In addition, other scene adapters can also be further extended.

[0128] Corresponding to the rule processing method provided in the above embodiment, the embodiment of the present disclosure also provides a rule processing device. Fig.10 This is a structural block diagram of a rule processing device provided by an embodiment of the present disclosure. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. Fig.10 The device may include: a business logic module 1001, a rule engine 1002 and at least one scenario adapter 1003.

[0129] The business logic module 1001 is used to obtain a rule output requirement and determine a first scenario adapter corresponding to the rule output requirement from the at least one scenario adapter 1003;

[0130] The rule engine 1002 is used to obtain the rule to be processed and parse the rule to obtain at least one element included in the rule, call the first scene adapter to process the at least one element, and obtain the output result corresponding to the rule.

[0131] In one embodiment of the present disclosure, when the rule engine 1002 obtains a rule to be processed and parses the rule to obtain at least one element included in the rule, the following steps are performed:

[0132] Obtaining rules to be processed, and parsing the rules to obtain a syntax tree;

[0133] The at least one element includes a node in the syntax tree.

[0134] In one embodiment of the present disclosure, when the rule engine 1002 calls the first scene adapter to process the at least one element and obtains the output result corresponding to the rule, it includes:

[0135] The syntax tree is parsed by a rule engine, and each time a node is parsed, a function corresponding to the type of the node in the first scenario adapter is called to obtain an output result of the node;

[0136] After all nodes of the syntax tree are parsed, the output result corresponding to the rule is obtained.

[0137] In one embodiment of the present disclosure, for the same node, different output results are obtained through different scene adapters.

[0138] In one embodiment of the present disclosure, the at least one scenario adapter 1003 includes at least one of the following: a rule evaluator, a query statement converter, a natural language translator, and a condition checker.

[0139] In one embodiment of the present disclosure, the business logic module 1001 is specifically used to perform any of the following:

[0140] If the obtained rule output requirement is used to indicate that the output value of the rule is calculated according to the input condition information, determining that the first scenario adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or,

[0141] If the obtained rule output requirement is used to indicate that the rule is converted into a query statement, then the first scenario adapter is determined to be the query statement converter, and the query statement is used to query the database for data that meets the rule; or,

[0142] If the obtained rule output requirement is used to indicate that the rule is converted into a natural language, determining that the first scenario adapter is the natural language translator; or,

[0143] If the obtained rule output requirement is used to indicate the constraint conditions for calculating the remaining variables given the values ​​of some variables in the rule, the first scene adapter is determined to be the condition checker, and the values ​​of the some variables are sent to the condition checker.

[0144] In one embodiment of the present disclosure, if the first scene adapter is the rule evaluator, then when the first scene adapter processes the at least one element, it is specifically configured to:

[0145] For each node, if the node includes a variable, assign a value to the variable according to the acquired input condition information;

[0146] If the node includes a constant, returning the constant;

[0147] If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

[0148] In one embodiment of the present disclosure, if the first scenario adapter is the query statement converter, then when the first scenario adapter processes the at least one element, it is specifically used to:

[0149] For each node, the node is converted into a corresponding query field, so as to obtain a query statement corresponding to the rule after a plurality of nodes of the syntax tree are processed.

[0150] In one embodiment of the present disclosure, if the first scene adapter is the natural language translator, then when the first scene adapter processes the at least one element, it is specifically configured to:

[0151] For each node, the node is converted into corresponding text, so as to obtain the natural language corresponding to the rule after the multiple nodes of the syntax tree are processed.

[0152] In one embodiment of the present disclosure, if the first scene adapter is the condition checker, then when the first scene adapter processes the at least one element, it is specifically configured to:

[0153] For each node, if the node includes a variable, assign a value to the variable, or convert the variable into a corresponding text;

[0154] If the node includes a constant, returning the constant;

[0155] If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

[0156] In one embodiment of the present disclosure, if the node includes a variable, the first scene adapter, when assigning a value to the variable or converting the variable into a corresponding text, is specifically used to:

[0157] Determine whether a value corresponding to the variable is given in the rule output requirement;

[0158] If so, assign a value to the variable; if not, convert the variable to the corresponding text.

[0159] In one embodiment of the present disclosure, the business logic module 1001 is further used to:

[0160] Before obtaining the rule output requirements, obtain the user condition information that meets the group requirements;

[0161] Determining a rule corresponding to the group according to the user condition information;

[0162] The rules to be processed are rules corresponding to the group.

[0163] The device provided in this embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effect are similar, and this embodiment will not be repeated here.

[0164] Fig.11 This is a structural block diagram of an electronic device provided by an embodiment of the present disclosure. Fig.11 The electronic device 1100 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.11 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0165] like Fig.11 As shown, the electronic device 1100 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1102 or a program loaded from a storage device 1108 to a random access memory (RAM) 1103. Various programs and data required for the operation of the electronic device 1100 are also stored in the RAM 1103. The processing device 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.

[0166] Typically, the following devices may be connected to the I / O interface 1105: input devices 1106 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 1107 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1108 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 11011. The communication devices 11011 may allow the electronic device 1100 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.11 The electronic device 1100 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0167] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 11011, or installed from the storage device 1108, or installed from the ROM 1102. When the computer program is executed by the processing device 1101, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0168] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0169] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0170] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.

[0171] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0172] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0173] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, limit the unit itself.

[0174] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0175] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0176] In a first aspect, according to one or more embodiments of the present disclosure, a rule processing method is provided, including:

[0177] Obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter;

[0178] Obtaining a rule to be processed and parsing the rule to obtain at least one element included in the rule;

[0179] The at least one element is processed by the first scene adapter to obtain an output result corresponding to the rule.

[0180] According to one or more embodiments of the present disclosure, obtaining a rule to be processed and parsing the rule to obtain at least one element contained in the rule includes:

[0181] Obtaining rules to be processed, and parsing the rules to obtain a syntax tree;

[0182] The at least one element includes a node in the syntax tree.

[0183] According to one or more embodiments of the present disclosure, processing the at least one element by the first scene adapter to obtain an output result corresponding to the rule includes:

[0184] The syntax tree is parsed by a rule engine, and each time a node is parsed, a function corresponding to the type of the node in the first scenario adapter is called to obtain an output result of the node;

[0185] After all nodes of the syntax tree are parsed, the output result corresponding to the rule is obtained.

[0186] According to one or more embodiments of the present disclosure, for the same node, different output results may be obtained through different scene adapters.

[0187] According to one or more embodiments of the present disclosure, the at least one scenario adapter includes at least one of the following: a rule evaluator, a query statement converter, a natural language translator, and a condition checker.

[0188] According to one or more embodiments of the present disclosure, obtaining a rule output requirement and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter includes any of the following:

[0189] If the obtained rule output requirement is used to indicate that the output value of the rule is calculated according to the input condition information, determining that the first scenario adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or,

[0190] If the obtained rule output requirement is used to indicate that the rule is converted into a query statement, then the first scenario adapter is determined to be the query statement converter, and the query statement is used to query the database for data that meets the rule; or,

[0191] If the obtained rule output requirement is used to indicate that the rule is converted into a natural language, determining that the first scenario adapter is the natural language translator; or,

[0192] If the obtained rule output requirement is used to indicate the constraint conditions for calculating the remaining variables given the values ​​of some variables in the rule, the first scene adapter is determined to be the condition checker, and the values ​​of the some variables are sent to the condition checker.

[0193] According to one or more embodiments of the present disclosure, if the first scene adapter is the rule evaluator, the processing of the at least one element includes:

[0194] For each node, if the node includes a variable, assign a value to the variable according to the acquired input condition information;

[0195] If the node includes a constant, returning the constant;

[0196] If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

[0197] According to one or more embodiments of the present disclosure, if the first scene adapter is the query statement converter, the processing of the at least one element includes:

[0198] For each node, the node is converted into a corresponding query field, so as to obtain a query statement corresponding to the rule after a plurality of nodes of the syntax tree are processed.

[0199] According to one or more embodiments of the present disclosure, if the first scene adapter is the natural language translator, the processing of the at least one element includes:

[0200] For each node, the node is converted into corresponding text, so as to obtain the natural language corresponding to the rule after the multiple nodes of the syntax tree are processed.

[0201] According to one or more embodiments of the present disclosure, if the first scene adapter is the condition checker, the processing of the at least one element includes:

[0202] For each node, if the node includes a variable, assign a value to the variable, or convert the variable into a corresponding text;

[0203] If the node includes a constant, returning the constant;

[0204] If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

[0205] According to one or more embodiments of the present disclosure, if the node includes a variable, assigning a value to the variable, or converting the variable into a corresponding text, includes:

[0206] If the node includes a variable, determining whether a value corresponding to the variable is given in the rule output requirement;

[0207] If so, assign a value to the variable; if not, convert the variable to the corresponding text.

[0208] According to one or more embodiments of the present disclosure, before obtaining the rule output requirement, the method further includes:

[0209] Get user condition information that meets group requirements;

[0210] Determining a rule corresponding to the group according to the user condition information;

[0211] The rules to be processed are rules corresponding to the group.

[0212] In a second aspect, according to one or more embodiments of the present disclosure, a rule processing device is provided, comprising: a business logic module, a rule engine and at least one scenario adapter.

[0213] The business logic module is used to obtain a rule output requirement and determine a first scenario adapter corresponding to the rule output requirement from the at least one scenario adapter;

[0214] The rule engine is used to obtain the rule to be processed and parse the rule to obtain at least one element contained in the rule, call the first scene adapter to process the at least one element, and obtain the output result corresponding to the rule.

[0215] According to one or more embodiments of the present disclosure, when the rule engine obtains a rule to be processed and parses the rule to obtain at least one element contained in the rule, the process includes:

[0216] Obtaining rules to be processed, and parsing the rules to obtain a syntax tree;

[0217] The at least one element includes a node in the syntax tree.

[0218] According to one or more embodiments of the present disclosure, when the rule engine calls the first scene adapter to process the at least one element and obtains the output result corresponding to the rule, it includes:

[0219] The syntax tree is parsed by a rule engine, and each time a node is parsed, a function corresponding to the type of the node in the first scenario adapter is called to obtain an output result of the node;

[0220] After all nodes of the syntax tree are parsed, the output result corresponding to the rule is obtained.

[0221] According to one or more embodiments of the present disclosure, for the same node, different output results may be obtained through different scene adapters.

[0222] According to one or more embodiments of the present disclosure, the at least one scenario adapter includes at least one of the following: a rule evaluator, a query statement converter, a natural language translator, and a condition checker.

[0223] According to one or more embodiments of the present disclosure, the business logic module is specifically used to perform any of the following:

[0224] If the obtained rule output requirement is used to indicate that the output value of the rule is calculated according to the input condition information, determining that the first scenario adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or,

[0225] If the obtained rule output requirement is used to indicate that the rule is converted into a query statement, then the first scenario adapter is determined to be the query statement converter, and the query statement is used to query the database for data that meets the rule; or,

[0226] If the obtained rule output requirement is used to indicate that the rule is converted into a natural language, determining that the first scenario adapter is the natural language translator; or,

[0227] If the obtained rule output requirement is used to indicate the constraint conditions for calculating the remaining variables given the values ​​of some variables in the rule, the first scene adapter is determined to be the condition checker, and the values ​​of the some variables are sent to the condition checker.

[0228] According to one or more embodiments of the present disclosure, if the first scene adapter is the rule evaluator, then when the first scene adapter processes the at least one element, it is specifically configured to:

[0229] For each node, if the node includes a variable, assign a value to the variable according to the acquired input condition information;

[0230] If the node includes a constant, returning the constant;

[0231] If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

[0232] According to one or more embodiments of the present disclosure, if the first scene adapter is the query statement converter, then when the first scene adapter processes the at least one element, it is specifically used to:

[0233] For each node, the node is converted into a corresponding query field, so as to obtain a query statement corresponding to the rule after a plurality of nodes of the syntax tree are processed.

[0234] According to one or more embodiments of the present disclosure, if the first scene adapter is the natural language translator, then when the first scene adapter processes the at least one element, it is specifically configured to:

[0235] For each node, the node is converted into corresponding text, so as to obtain the natural language corresponding to the rule after the multiple nodes of the syntax tree are processed.

[0236] According to one or more embodiments of the present disclosure, if the first scene adapter is the condition checker, then when the first scene adapter processes the at least one element, it is specifically configured to:

[0237] For each node, if the node includes a variable, assign a value to the variable, or convert the variable into a corresponding text;

[0238] If the node includes a constant, returning the constant;

[0239] If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

[0240] According to one or more embodiments of the present disclosure, if the node includes a variable, the first scene adapter, when assigning a value to the variable or converting the variable into a corresponding text, is specifically used to:

[0241] Determine whether a value corresponding to the variable is given in the rule output requirement;

[0242] If so, assign a value to the variable; if not, convert the variable to the corresponding text.

[0243] According to one or more embodiments of the present disclosure, the business logic module is further used to:

[0244] Before obtaining the rule output requirements, obtain the user condition information that meets the group requirements;

[0245] Determining a rule corresponding to the group according to the user condition information;

[0246] The rules to be processed are rules corresponding to the group.

[0247] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, including: a memory and at least one processor;

[0248] The memory stores computer-executable instructions;

[0249] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the rule processing method described in the first aspect and various possible designs of the first aspect.

[0250] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the rule processing method described in the first aspect and various possible designs of the first aspect is implemented.

[0251] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.

[0252] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0253] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A rule processing method, characterized in that: The method comprises: Obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter; Obtaining a rule to be processed and parsing the rule to obtain at least one element included in the rule; Processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule; The obtaining of the rule output requirement and determining the first scene adapter corresponding to the rule output requirement from at least one scene adapter include any one of the following: If the obtained rule output requirement is used to indicate that the output value of the rule is calculated according to the input condition information, determining that the first scenario adapter is a rule evaluator, and sending the input condition information to the rule evaluator; or, If the obtained rule output requirement is used to indicate that the rule is converted into a query statement, then the first scenario adapter is determined to be a query statement converter, and the query statement is used to search for data that meets the rule in the database; or, If the obtained rule output requirement is used to indicate that the rule is converted into a natural language, then determining that the first scenario adapter is a natural language translator; or, If the obtained rule output requirement is used to indicate the constraint conditions for calculating the remaining variables given the values ​​of some variables in the rule, the first scenario adapter is determined to be a condition checker, and the values ​​of the some variables are sent to the condition checker.

2. The method according to claim 1, characterized in that Obtaining a rule to be processed and parsing the rule to obtain at least one element contained in the rule, including: Obtaining rules to be processed, and parsing the rules to obtain a syntax tree; The at least one element includes a node in the syntax tree.

3. The method according to claim 2, characterized in that Processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule includes: The syntax tree is parsed by a rule engine, and each time a node is parsed, a function corresponding to the type of the node in the first scenario adapter is called to obtain an output result of the node; After all nodes of the syntax tree are parsed, the output result corresponding to the rule is obtained.

4. The method according to claim 3, characterized in that For the same node, different output results are obtained through different scene adapters.

5. The method according to claim 2, characterized in that: The at least one scenario adapter includes at least one of the following: a rule evaluator, a query statement converter, a natural language translator, and a condition checker.

6. The method according to claim 5, characterized in that If the first scene adapter is the rule evaluator, the processing of the at least one element includes: For each node, if the node includes a variable, assign a value to the variable according to the acquired input condition information; If the node includes a constant, returning the constant; If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

7. The method according to claim 5, characterized in that If the first scene adapter is the query statement converter, the processing of the at least one element includes: For each node, the node is converted into a corresponding query field, so as to obtain a query statement corresponding to the rule after a plurality of nodes of the syntax tree are processed.

8. The method according to claim 5, characterized in that If the first scene adapter is the natural language translator, the processing of the at least one element includes: For each node, the node is converted into corresponding text, so as to obtain the natural language corresponding to the rule after the multiple nodes of the syntax tree are processed.

9. The method according to claim 5, characterized in that If the first scene adapter is the condition checker, the processing of the at least one element includes: For each node, if the node includes a variable, assign a value to the variable, or convert the variable into a corresponding text; If the node includes a constant, returning the constant; If the node is a binary node and includes an operator, a processing result corresponding to the binary node is calculated according to the operator.

10. The method according to claim 9, characterized in that If the node includes a variable, assign a value to the variable, or convert the variable into a corresponding text, including: If the node includes a variable, determining whether a value corresponding to the variable is given in the rule output requirement; If so, assign a value to the variable; if not, convert the variable to the corresponding text.

11. The method according to any one of claims 1 to 10, characterized in that: Before obtaining the rule output requirements, it also includes: Get user condition information that meets group requirements; Determine a rule corresponding to the group according to the user condition information; The rules to be processed are rules corresponding to the group.

12. A rule conversion device, characterized in that: include: Business logic module, rule engine and at least one scenario adapter; The business logic module is used to obtain a rule output requirement and determine a first scenario adapter corresponding to the rule output requirement from the at least one scenario adapter; The rule engine is used to obtain a rule to be processed and parse the rule to obtain at least one element included in the rule, and call the first scene adapter to process the at least one element to obtain an output result corresponding to the rule; The business logic module is specifically used for: wherein, the obtaining of the rule output requirement and determining the first scene adapter corresponding to the rule output requirement from at least one scene adapter include any one of the following: If the obtained rule output requirement is used to indicate that the output value of the rule is calculated according to the input condition information, determining that the first scenario adapter is a rule evaluator, and sending the input condition information to the rule evaluator; or, If the obtained rule output requirement is used to indicate that the rule is converted into a query statement, then the first scenario adapter is determined to be a query statement converter, and the query statement is used to search for data that meets the rule in the database; or, If the obtained rule output requirement is used to indicate that the rule is converted into a natural language, then determining that the first scenario adapter is a natural language translator; or, If the obtained rule output requirement is used to indicate the constraint conditions for calculating the remaining variables given the values ​​of some variables in the rule, the first scenario adapter is determined to be a condition checker, and the values ​​of the some variables are sent to the condition checker.

13. An electronic device, characterized in that: include: memory and at least one processor; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the rule processing method according to any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the rule processing method according to any one of claims 1 to 11 is implemented.

Citation Information

Patent Citations

  • Service rule matching processing method and device and processing equipment

    CN108628947A

  • Complex data matching method and medium

    CN111176656A