CN112069214A - Rule processing method, device, equipment and storage medium - Google Patents

Rule processing method, device, equipment and storage medium Download PDF

Info

Publication number
CN112069214A
CN112069214A CN202010941802.8A CN202010941802A CN112069214A CN 112069214 A CN112069214 A CN 112069214A CN 202010941802 A CN202010941802 A CN 202010941802A CN 112069214 A CN112069214 A CN 112069214A
Authority
CN
China
Prior art keywords
rule
node
adapter
scene
output
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010941802.8A
Other languages
Chinese (zh)
Inventor
胡炼
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202010941802.8A priority Critical patent/CN112069214A/en
Publication of CN112069214A publication Critical patent/CN112069214A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24564Applying rules; Deductive queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/243Natural language query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computational Linguistics (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Artificial Intelligence (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • General Health & Medical Sciences (AREA)
  • Machine Translation (AREA)

Abstract

The embodiment of the disclosure provides a rule processing method, a rule processing device and a storage medium, wherein the method comprises the steps of obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter; acquiring a rule to be processed and analyzing the rule to obtain at least one element contained in the rule; and processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule. The rule processing method, the rule processing device, the rule processing equipment and the rule processing storage medium provided by the embodiment of the disclosure can make specific conversion on the used scene of the rule, thereby improving the flexibility of rule output and effectively improving the efficiency and accuracy of rule conversion.

Description

Rule processing method, device, equipment and storage medium
Technical Field
The disclosed embodiments relate to the field of computer technologies, and in particular, to a rule processing method, apparatus, device, and storage medium.
Background
With the continuous development of science and technology, various social and business activities are in endless, and the rule-based automatic processing capability is more and more important. In some scenarios, a worker may configure a specific rule, and may determine whether a target object satisfies a condition according to the rule, thereby implementing an operation on the target object. For example, when determining whether a user is qualified to participate in a certain activity, a certain rule may be formed according to reference indicators such as the age and risk tolerance of the user, so that the registered user may be screened to obtain a qualified user.
Currently, rules are mostly stored in the form of expressions. When the rules need to be converted, the rules can be converted into corresponding output results only by manpower, and the efficiency is low.
Disclosure of Invention
The embodiment of the disclosure provides a rule processing method, a rule processing device, a rule processing apparatus and a storage medium, so as to overcome the technical problem of low rule conversion efficiency.
In a first aspect, an embodiment of the present disclosure provides a rule processing method, including:
acquiring a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter;
acquiring a rule to be processed and analyzing the rule to obtain at least one element contained in the rule;
and processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule.
In a second aspect, an embodiment of the present disclosure provides a rule processing apparatus, including: the system comprises a business logic module, a rule engine and at least one scene adapter;
the business logic module is used for acquiring a rule output requirement and determining a first scene adapter corresponding to the rule output requirement from the at least one scene adapter;
the rule engine is used for acquiring a rule to be processed, analyzing the rule to obtain at least one element contained in the rule, and calling the first scene adapter to process the at least one element to obtain an output result corresponding to the rule.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a memory and at least one processor;
the memory stores computer-executable instructions;
the at least one processor executes computer-executable instructions stored by the memory to cause the at least one processor to perform the rule processing method as set forth in the first aspect above and in various possible designs of the first aspect.
In a fourth aspect, the present disclosure provides a computer-readable storage medium, in which computer-executable instructions are stored, and when a processor executes the computer-executable instructions, the rule processing method according to the first aspect and various possible designs of the first aspect are implemented.
The rule processing method, the rule processing device, the rule processing equipment and the storage medium provided by the embodiment of the disclosure can acquire a rule output requirement, determine a first scene adapter corresponding to the rule output requirement from at least one scene adapter, acquire a rule to be processed and analyze 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 an output result corresponding to the rule, so that the rule can perform specific conversion in a used scene, the flexibility of rule output is improved, and the efficiency and the accuracy of rule conversion are effectively improved.
Drawings
In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present disclosure, and for those skilled in the art, other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a schematic view of an application scenario provided in the embodiment of the present disclosure;
fig. 2 is a schematic flow chart of a rule processing method according to an embodiment of the present disclosure;
fig. 3 is a schematic flow chart of another rule processing method provided in the embodiment of the present disclosure;
FIG. 4 is a diagram of a syntax tree provided by an embodiment of the present disclosure;
fig. 5 is a schematic diagram of a syntax tree corresponding to a specific rule provided in the embodiment of the present disclosure;
FIG. 6 is a schematic diagram illustrating an implementation principle of a rule evaluator provided in an embodiment of the present disclosure;
FIG. 7 is a schematic diagram illustrating an implementation principle of a natural language translator according to an embodiment of the present disclosure;
fig. 8 is a schematic diagram illustrating an implementation principle of a query statement converter according to an embodiment of the present disclosure;
fig. 9 is a schematic diagram illustrating an implementation principle of a condition checker according to an embodiment of the present disclosure;
fig. 10 is a block diagram of a rule processing apparatus according to an embodiment of the present disclosure;
fig. 11 is a block diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are some, but not all embodiments of the present disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments disclosed herein without making any creative effort, shall fall within the protection scope of the present disclosure.
The technical scheme provided by the embodiment of the disclosure can be applied to the field of any settable rule. The rules may be any type of rules, such as admission rules set for a group, flow rules designed for an activity, constraint rules designed for certain users, and so on.
In practical applications, rules may need to have different performance capabilities in different scenarios: when the rule is read by a worker, the rule needs to be converted into a natural language form; when judging whether a certain user meets the requirement of a rule, the computing power based on the context parameters needs to be provided; when querying all people who meet the rules, the rules need to be converted into specific query statements.
In order to solve the problem, in the embodiment of the present disclosure, a scene adapter corresponding to each scene may be constructed for a plurality of scenes, a rule to be processed is obtained through a rule engine having a multi-scene adaptation function, and the scene adapter corresponding to the current scene is called to perform processing, so that the rule is converted into a corresponding output result, and flexibility and efficiency of rule output are improved.
Fig. 1 is a schematic view of an application scenario provided in the embodiment of the present disclosure. As shown in fig. 1, a worker, for example, a person in charge of operation, may input a user condition that meets a group requirement, for example, a user entering the group needs to be older than a certain age, and the like. Based on the content of the worker input, rules may be created, which may be represented by reference expressions. Assuming that the content input by the staff member is "X attribute is greater than 1and Y attribute is less than 4", the content may be converted into the reference expression "X > 1& & Y < 4".
The conversion of the reference expression into an output result conforming to the current scene can be achieved by passing the reference expression and the scene adapter corresponding to the current scene to the rules engine.
In the first scenario, a regular operation of a given parameter may be implemented. Specifically, given the values of x and y, the output value corresponding to the rule may be determined. If the output value is true, the x and y values are in accordance with the rule, and if the output value is false, the x and y values are in accordance with the rule. For example, if the x attribute corresponding to a certain user is 2 and the y attribute is 5, after x is 2 and y is 5 are input, the rule is x > 1& & y < 4, so that the output value is false, which indicates that the user does not meet the requirements of the group.
In a second scenario, the conversion of rules into query statements may be implemented. Specifically, when a user meeting the requirements of the rules needs to be queried in the database, the rules can be converted into corresponding query statements, e.g., "x > 1& & y < 4" is converted into "x > 1and y < 4" that meet the requirements of the database query.
In a third scenario, conversion of rules to natural language may be implemented. Specifically, when a certain group of rules needs to be displayed to the staff, the rules may be converted into natural language, for example, "x > 1& & y < 4" is converted into "x attribute is greater than 1and y attribute is less than 4", and the staff may read the rules in natural language.
It should be noted that the rule described in the embodiment of the present disclosure may refer to any form of rule, and is not limited to the rule with the result of only true and false. An expression may be considered a rule if it has a practical meaning. For example, if an expression a + b ═ c, where a represents age, b represents monthly login times, and c represents credit, then the expression may correspond to a rule that may indicate that the user's credit may be equal to the sum of the user's age and monthly login times.
Of course, the technical solution provided by the embodiment of the present disclosure may also be applied to other scenarios besides the above scenarios. Some embodiments of the disclosure are described in detail below with reference to the accompanying drawings. The features of the embodiments and examples described below may be combined with each other without conflict between the embodiments.
Fig. 2 is a schematic flowchart of a rule processing method according to an embodiment of the present disclosure. The method of the present embodiment can be applied to any device having a data processing function, such as a server or a processing terminal. As shown in fig. 2, the rule processing method may include:
step 201, obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter.
In the embodiment 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.
The rule output requirement is used for converting the rule into a certain result and outputting the result, for example, given the value of a variable in the rule, calculating an output value corresponding to the rule, converting the rule into a certain language, and the like. The rule output requirements may be obtained in a number of ways.
In one example, the rule output requirements may be triggered by a human operator. Optionally, an interface for obtaining the rule output requirement may be displayed. When the staff member has the requirement of using the rule, the rule output requirement can be input on the interface. For example, when it is required to determine whether the condition information of a certain user meets the rule, the condition information of the user may be input and a query button may be clicked. When the rule needs to be converted into natural language, the button to view the rule can be clicked.
In another example, the rule output requirements may be triggered periodically. For example, at preset intervals, a rule output requirement for converting a rule into a query statement of a database is automatically generated, so that users who currently meet the rule are queried from the database at regular intervals.
In yet another example, the rule output requirement may be automatically triggered when certain conditions are met. For example, when the number of users in the group reaches an upper limit, a rule output requirement for judging whether each user in the group meets the rule requirement or not can be automatically generated.
Optionally, the rule output obtaining requirement may be implemented by a service logic module. After the business logic module obtains the rule output requirement, the corresponding first scene adapter can be determined according to the rule output requirement, and the rule engine is triggered to call the scene adapter to realize the conversion and output of the rule.
Step 202, obtaining a rule to be processed and analyzing the rule to obtain at least one element contained in the rule.
Wherein the pending rules may be stored locally or elsewhere. The expression form of the acquired rule to be processed can be various. Optionally, the rule may be represented in the form of an expression, or may also be represented in the form of a code such as a script statement, or may also be represented in the form of a rule tree, a linked list, or the like.
At least one element may be included in the rule. The at least one element may include one or more parts that are split in any manner from the rule. For example, where a rule is represented by an expression, the element may comprise any one of a variable, a number, an operator, a bracket, a sub-expression, or may comprise a combination of any number of items therein.
For example, assuming that the rule is the expression x > 1& & y < 4, the elements x, >, 1, &, y, <, 4 can be obtained after parsing the rule. Alternatively, the elements x > 1, &andy < 4 can be obtained by other analytic means. The disclosed embodiments are not so limited.
The acquisition and analysis mode of the rule to be processed can be various. Alternatively, the rules may be accessed by the business logic module. After the business logic module obtains the rule output requirement, the rule can be transmitted to a rule engine, and the rule engine is responsible for analyzing the rule.
Step 203, processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule.
After at least one element of a rule is obtained, for each element, the element may be processed by the first scene adapter to obtain a result corresponding to the element, and after at least one element is processed, an output result corresponding to the rule may be obtained.
For the same element, different scene adapters can correspond to different processing modes, so that different processing results are obtained.
For example, assuming that the rule is the expression x > 1& & y < 4, the parsing of the rule can obtain the elements x, >, 1, &, y, <, 4, wherein a scene adapter can translate x, >, 1, &, y, <, 4 into age, greater than, 1, and purchase capability, less than, 4, respectively, so that the rule corresponds to the output result: the age is greater than 1and the purchasing power is less than 4, so that the translation from the rule to the natural language is realized, and the staff can conveniently check the translation.
Another scene adapter may convert x, >, 1, &, y, <, 4 to x, >, 1, and, y, <, 4, respectively, resulting in corresponding output results as: x is more than 1and y is less than 4, the output result is suitable for database query, and can be directly input into the database to realize the query of the data meeting the rule requirements.
In practical application, the processing of the elements can be realized by calling the scene adapter through the rule engine. Specifically, the rule output requirement may be obtained by the service logic module, and the current scenario, for example, whether the rule is converted into a natural language or a database query statement, may be determined according to the rule output requirement. The business logic module may notify the rule engine which scene adapter needs to be called, and then the rule engine may call the scene adapter corresponding to the current scene to determine the output result corresponding to the rule. The output result may be a natural language corresponding to the rule, a query statement, or 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 service logic module by the scene adapter.
Further, the business logic module may also be used to enable interaction with users or other devices. Optionally, the service logic module may provide an interface for triggering a rule output requirement, a worker or a user triggers the rule output requirement on the interface, and after an output result corresponding to the rule is obtained, the output result may be displayed to the worker or the user, or sent to other devices.
The rule processing method provided by this embodiment may obtain a rule output requirement, determine a first scene adapter corresponding to the rule output requirement from at least one scene adapter, obtain a rule to be processed, analyze the rule to obtain at least one element included in the rule, and process the at least one element through the first scene adapter to obtain an output result corresponding to the rule, so that the rule can perform specific conversion in a scene where the rule is used, thereby improving flexibility of rule output and effectively improving efficiency and accuracy of rule conversion.
On the basis of the technical solution provided by the above embodiment, optionally, before acquiring the rule output requirement, the method may further include: acquiring user condition information meeting group requirements; and determining a rule corresponding to the group according to the user condition information. The user condition information meeting the group requirement can be input by a worker, or can be acquired from other platforms. The rule to be processed acquired by the rule engine can be a rule corresponding to the group, so that the operation on the group can be efficiently realized, and the automatic operation and maintenance capability of the group is improved.
Further, when a plurality of groups exist, the service logic module may determine the current group to be processed according to the rule output requirement when acquiring the rule output requirement, and determine the corresponding rule according to the group, so that the rule engine may process the rule corresponding to the group, thereby implementing rule processing under the condition of multiple groups, and further improving flexibility of rule processing.
Fig. 3 is a schematic flow chart of another rule processing method according to the embodiment of the present disclosure. The present embodiment is based on the technical solutions provided by the above embodiments, and implements the processing of rules through syntax trees. As shown in fig. 3, the method includes:
step 301, obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter.
For the specific implementation principle and process of step 301 in this embodiment, reference may be made to the foregoing embodiments, which are not described herein again.
Step 302, obtaining the rule to be processed, and analyzing the rule to obtain a syntax tree.
In this embodiment, step 302 may be utilized to obtain a rule to be processed and analyze the rule to obtain at least one element included in the rule.
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 comprises a node in the syntax tree.
Fig. 4 is a schematic diagram of a syntax tree according to an embodiment of the disclosure. As shown in fig. 4, the syntax tree is presented in the shape of a tree. The ellipses in the figure may represent nodes of a tree, which may be binary nodes if there are two branches under a node. The nodes can be used as elements of the rule, and each node is processed through the scene adapter to obtain an output result corresponding to the rule.
Step 303, analyzing the syntax tree through a rule engine, and calling a function corresponding to the type of the node in the first scene adapter to obtain an output result of the node when each node is analyzed; and obtaining an output result corresponding to the rule after all the nodes of the grammar tree are analyzed.
In this embodiment, the step 303 may be implemented to process the at least one element through the first scene adapter, so as to obtain an output result corresponding to the rule.
According to the rule processing method provided by the embodiment, the rule is converted into the syntax tree, the syntax tree can be used for visually and effectively expressing the rule, the scene adapter is called according to the syntax tree to process each node in the tree, and finally the output result corresponding to the rule is obtained, so that the rule processing efficiency is effectively improved, and errors are not easy to occur.
The methods described in the embodiments of the present disclosure may be implemented in any language. This may be done, for example, in the go language. The go language provides a concrete implementation scheme for analyzing the expression into the syntax tree, and the embodiment of the disclosure can abstract a layer of rule engine with multi-scene adaptation on the basis, and construct at least one scene adapter, so that the expression can be specifically converted in the corresponding scene. Alternatively, the functions of the rules engine may be implemented by the following code examples.
Figure BDA0002673894900000081
Figure BDA0002673894900000091
Wherein, the reference expression and syntax tree corresponding to the rule are defined through the lines 1 to 4. Line 5 calls the corresponding scene adapter through an Accept function, where a first of the Accept (director visitors) is used to represent the called scene adapter, and a second visitors defines the type of the scene adapter. Various scene adapters may be implemented based on the Visitor interface.
Starting from line 6, the concrete way of calling the scene adapter is realized through the Visitor interface: when the binary node is analyzed, a visitBoard function in the scene adapter is called, and the visitBoard function is used for processing the binary node; when the identifier is analyzed, a visitIdent function in the scene adapter is called for processing; when the basic type value is analyzed, a visitBasiclit function is called for processing.
In the above code example, the ellipsis in the 22 nd row indicates that other possible function definitions are omitted, and other functions can be flexibly extended according to actual needs on the basis of the code example provided by the present embodiment. And the Parse function of the last line is used for obtaining the syntax tree according to the reference expression.
Fig. 5 is a schematic diagram of a syntax tree corresponding to a specific rule according to an embodiment of the present disclosure. As shown in FIG. 5, the syntax tree may correspond to the rule of x > 1& & y < 4. During actual work, the operation can be performed by starting recursion from the top node of the syntax tree to the lowest node, and when a certain node is resolved, a corresponding function is called to process the node.
Specifically, the node at the lower left corner may be analyzed first, x is obtained, and x is a variable, the variable may be represented by an identifier, and when the variable is analyzed, a visitIdent function in the scene adapter may be called to perform processing. The node on the right side of x is 1, 1 is a constant, the constant can be represented by a basic type value, and a visitbasicLit function in the scene adapter can be called for processing. When the first node of the second row is resolved, the node is a binary node and comprises an operator >, and a visitBrany function in the scene adapter can be called for processing.
Each scene adapter may include functions visitbinitial, visitIdent, visitbasicLit, which are used to process nodes of corresponding types, respectively. However, in different scene adapters, the processing logic of the visitbinitial, visitIdent, visitbasicillit functions is different, and the output results obtained for the same node are also different.
For example, for node x, the visitIdent function needs to be called for processing. If the context adapter is used for evaluation, then the visitIdent function is used for assigning the value of x according to the context parameter under the context adapter. If the context adapter is used for translation, then the visitIdent function is used for translating x into corresponding characters such as age under the context adapter.
Because different scene adapters have different function processing logics, for the same node, the output results obtained by different scene adapters are different, so that different processing on the same node can be realized through the function in the scene adapters, the work of the rule engine can be the same in any scene, and the corresponding function is called to process when the node of a certain type is analyzed, the processing logic of the rule engine is effectively simplified, and the applicability of the rule engine is improved.
Some specific examples of scene adapters are given below in conjunction with the principles described above. It is understood that a person skilled in the art may adjust the scene adapter described below on the basis of the embodiments provided in the present disclosure, so as to obtain additional scene adapters.
Optionally, the scene adapter may include: any one or more of a rule evaluator, a query statement converter, a natural language translator, a condition checker. The scene adapters can be adapted to various different application scenes, and the conversion requirements of the rules under different scenes are met.
Correspondingly, obtaining a rule output requirement, and determining a 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 request is used for indicating that the output value of the rule is calculated according to the input condition information, determining that the first scene adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or, if the obtained rule output request is used for indicating that the rule is converted into a query statement, determining that the first scene adapter is the query statement converter, wherein the query statement is used for querying data meeting the rule in a database; or, if the obtained rule output request is used for indicating that the rule is converted into a natural language, determining that the first scene adapter is the natural language translator; or, if the obtained rule output request is used for indicating that the values of a part of variables in the given rule are used for calculating the constraint conditions of the rest of variables, determining that the first scene adapter is the condition checker, and sending the values of the part of variables to the condition checker.
Through the method, the corresponding first scene adapter can be quickly determined according to the rule output requirement, and the rule engine is instructed to call the first scene adapter to realize the processing of the rule. For ease of description, the disclosed embodiments are illustrated with the rule to be processed being x > 1& & y < 4.
In a first alternative implementation, the first scenario adapter is a rule evaluator.
If the first scenario adapter is the rule evaluator, the processing the at least one element may include: for each node, if the node comprises a variable, assigning a value to the variable according to the acquired input condition information; if the node comprises the constant, returning the constant; and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
Fig. 6 is a schematic diagram illustrating an implementation principle of a rule evaluator provided in the embodiment of the present disclosure. As shown in FIG. 6, the rule x > 1& & y < 4 is parsed into a syntax tree. And calling the first scene adapter once from the lower left corner and processing the node through the corresponding function every time a node is analyzed.
Specifically, the x at the lower left corner is analyzed, then the visitIdent function in the first scene adapter is called, and because the current first scene adapter is a rule evaluator, the visitIdent function can acquire a value corresponding to x through input condition information, assign the value to x, and feed the result back to the rule engine. For example, the input condition information is x-0 and y-3. Then x is assigned a value of 0.
Then, the 1and 1 on the right side are analyzed to be constants, the visitbasicLit function in the adapter is called, and in the rule evaluator, the visitbasicLit function can directly return the constants in the nodes to the rule engine without any extra work. Nodes y and 4 may then continue to be resolved, completing the assignment to y.
After the last row of nodes is analyzed, the previous row of nodes can be analyzed, firstly, the leftmost binary node is analyzed, the visitBoard function is called, the operational character > and 0and 1 under the two branches are input into the visitBoard function, the visitBoard function carries out operation according to the operational character, and the output result corresponding to the binary node is false because 0 > 1 is false. Similarly, after the right binary node is analyzed, the visitBinary node can be processed by the visitBinary function, and the output result corresponding to the binary node is true because 3 is less than 4.
And finally, analyzing the binary node of the first row, and continuing to call the visitBank function for processing, wherein the result of the false & & true is false, so that the final output result is false. Thus, the rule output values corresponding to the input condition of x-0 and y-3 are obtained, and the output value is false, which indicates that the input condition does not meet the requirement of the rule.
Through the mode shown in fig. 6, the rule evaluation of the given parameter can be realized, and a worker or a system can conveniently inquire whether the condition of a certain user meets the requirement of the rule, so that whether the user is added into a corresponding group can be determined, the condition of the user can be quickly judged, and convenience is provided for the worker.
In addition, on the basis of the scheme shown in fig. 6, optionally, the input condition information may be implemented by a Json variable, and input values corresponding to the variables in the rule may be determined by performing Json variable field extraction, so that the efficiency of assigning the variables is improved.
In a second alternative implementation, the first scenario adapter may be a natural language translator.
If the first scene adapter is the natural language translator, the processing the at least one element may include: and for each node, converting the node into a corresponding character so as to obtain the natural language corresponding to the rule after the plurality of nodes of the grammar tree are processed.
Fig. 7 is a schematic diagram illustrating an implementation principle of a natural language translator according to an embodiment of the present disclosure. As shown in fig. 7, after the syntax tree corresponding to the rule x > 1& & y < 4 is obtained, a natural language translator is called once every time a node is resolved from the lower left corner, and the node is processed by a corresponding function in the natural language translator. The function in the natural language translator can translate each node into corresponding characters, so that conversion from rules to natural languages is achieved. The natural language in the embodiment of the disclosure can refer to any language such as Chinese, English, Russian and the like. It is understood that, in order to realize simple expression, the Chinese characters may be provided with English letters or numbers.
Specifically, the x in the lower left corner is resolved, then the visitIdent function in the natural language translator is called, and the visitIdent function can translate x into age and return the age to the rule engine.
Then, the nodes 1, y and 4 can be continuously analyzed, and the corresponding characters are obtained through translation: 1. purchase capability, 4. In other alternatives, nodes 1and 4 are also translated as one and four.
After the last row of nodes is analyzed, the previous row of nodes can be analyzed, firstly, the leftmost binary node is analyzed, the visitBoard function is called, the operational character > and the age sum 1 under the two branches are input into the visitBoard function, and the visitBoard function translates the binary node to obtain characters: the age is greater than 1. Similarly, translating the binary node of the second row to obtain the characters: the purchasing power is less than 4.
Finally, the binary node of the first row is analyzed again, the visitBoard function is called continuously for processing, and the finally obtained characters are as follows because & & translation is yes: age greater than 1and purchasing power less than 4 as an output of the rule.
Optionally, the natural language translator may store a correspondence between each variable, operator, constant and character, so that each node may be translated into a corresponding character according to the correspondence. Alternatively, the correspondence may be stored in other modules, and the natural language translator may translate the node by interacting with the other modules.
Through the mode shown in fig. 7, the rules can be translated into the natural language, so that non-research and development personnel can easily understand the rules, the checking by the staff or the user is facilitated, and convenience is provided for the staff and the user.
In a third alternative implementation, the first scenario adapter may be a query statement converter.
If the first scenario adapter is the query statement converter, the processing the at least one element may include: and for each node, converting the node into a corresponding query field so as to obtain a query statement corresponding to the rule after the plurality of nodes of the syntax tree are processed.
Fig. 8 is a schematic diagram illustrating an implementation principle of a query statement converter according to an embodiment of the present disclosure. As shown in fig. 8, after the syntax tree corresponding to the rule x > 1& & y < 4 is obtained, from the lower left corner, a query statement converter is called once every time a node is parsed, and a function in the query statement converter can convert each node into a corresponding query field, thereby realizing conversion from the rule to the query statement.
The specific processing method is similar to that of a natural language translator, the nodes in the syntax tree are analyzed from left to right and from bottom to top, the visitIdent function in the query statement converter is called when the identifiers are analyzed, the visitBasiclit function is called when the basic type values are analyzed, and the visitBasary function is called when the binary nodes are analyzed, so that the corresponding query statement is obtained.
The query statement may be a query statement applied to any database. Optionally, the database may be an SQL (Structured Query Language) database.
In the SQL database, the query fields corresponding to x, 1, y, 4, >, < are still x, 1, y, 4, >, <, and the operator & & corresponding query field is and, therefore, the resulting query statement may be: x > 0and y < 4 as output results of the rule.
Optionally, the query statement converter may store a correspondence between each variable, operator, constant and query field, so that each node may be translated into a corresponding query field according to the correspondence. Alternatively, the correspondence may be stored in another module, and the query statement converter may implement conversion operation on the node by interacting with the another module.
By the method shown in fig. 8, the rules can be converted into query statements, and the query statements can be output to the database after being converted into the query statements, so that data meeting the requirements of the rules can be searched in the database according to the query statements, automatic query of the database is realized, and the efficiency and accuracy of data processing are improved.
In a fourth optional implementation manner, the first scenario adapter may be a condition checker.
If the first scene adapter is the condition checker, the processing the at least one element may include: for each node, if the node comprises a variable, assigning a value to the variable, or converting the variable into a corresponding character; if the node comprises the constant, returning the constant; and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
The specific processing principle of the conditional checker is similar to that of the rule evaluator, except that when the node includes a variable, processing is required according to whether the value of the variable is given in the rule output requirement.
Optionally, if the node includes a variable, assigning a value to the variable, or converting the variable into a corresponding word, including: if the node comprises a variable, judging whether a value corresponding to the variable is given in the rule output requirement or not; if yes, assigning a value to the variable; if not, the variable is converted into the corresponding character.
Assuming that the rule output requirement is given a value of x, and a constraint condition of y is solved, the value of x is assigned in the processing process, y is translated into words, and the final output result is the constraint condition of y. For example, the rule is x > 0& & y < 4, and given x ═ 1, the output obtained is a purchase capability > 4.
In order to better reflect the constraint relationship between the variables, the disclosed embodiment gives another rule to be processed: x + y > 3 z. One possible application is that in the rule, x may represent age, y may represent monthly login times, and z represents user rating. The rule shows that the sum of the age of the user and the login times is required to be more than 3 times of the grade until the user can enter the corresponding group according to the requirement.
Fig. 9 is a schematic diagram illustrating an implementation principle of a condition checker according to an embodiment of the present disclosure. As shown in fig. 9, after the syntax tree corresponding to the rule x + y > 3z is obtained, from the lower left corner, a condition checker is called once every time a node is resolved, and the node is processed through a corresponding function.
Let x be 25 and z be 10 for a given variable value. When a syntax tree is processed, firstly, x at the lower left corner is analyzed, then a visitIdent function in the condition checker is called, and the visitIdent function can assign x to 5 and feed back the value to the rule engine.
Then, the right node y is analyzed again, the visitIdent function is called, and because y is not assigned, the characters corresponding to y are returned: monthly login times. The processing continues again for nodes z and 3, returning results of 10 and 3, respectively.
After the last row of nodes is analyzed, the previous row of nodes can be analyzed, firstly, the leftmost binary node is analyzed, the visitBrany function is called, and according to the operational character + and the 25-month and month login times under the two branches, the corresponding result which is the 25+ month login times can be obtained. After the binary node on the right side is resolved, a corresponding result of 10 × 3 to 30 can be obtained according to the operator × and 10 and 3 under the two branches.
And finally, analyzing the binary node in the first row, and continuing to call the visitBank function for processing, wherein the constraint relation is changed to 25+ month login times larger than 30, so that the final output result can be that the month login times are larger than 5. Thus, the constraint condition of y under the input condition of x being 25 and z being 10 is obtained, which means that when the age of the user is 25 and the grade is 10, the requirement of the group can be met only by ensuring that the monthly login number is 5 at least.
Through the mode shown in fig. 9, the constraint conditions of the other variables can be solved according to the values of the given partial variables, so that the constraint conditions are convenient for the staff or the user to check, related messages can be pushed to the user according to the constraint conditions, for example, the user is prompted how many times of monthly login are required to join the group, and the flexibility of the use rule is improved.
The specific implementation principle of each scene adapter is given above, and in practical application, the rule engine can call the scene adapters to implement processing of the rules. A plurality of functions can be arranged in the scene adapter to respectively process different types of nodes. On the basis, the scene adapter also supports a function extension function, a business logic module or a rule engine defines a new function and realizes the extension of the function in the scene adapter. In addition to this, other scene adapters may be further extended.
Corresponding to the rule processing method provided by the above embodiment, the embodiment of the present disclosure further provides a rule processing apparatus. Fig. 10 is a block diagram of a rule processing apparatus according to an embodiment of the present disclosure. For ease of illustration, only portions that are relevant to embodiments of the present disclosure are shown. Referring to fig. 10, the apparatus may include: a business logic module 1001, a rules engine 1002, and at least one scenario adapter 1003.
The service logic module 1001 is configured to obtain a rule output requirement, and determine a first scene adapter corresponding to the rule output requirement from the at least one scene adapter 1003;
the rule engine 1002 is configured to obtain a rule to be processed, analyze the rule to obtain at least one element included in the rule, and invoke the first scene adapter to process the at least one element to obtain an output result corresponding to the rule.
In an embodiment of the present disclosure, when obtaining a rule to be processed and analyzing the rule to obtain at least one element included in the rule, the rule engine 1002 includes:
acquiring a rule to be processed, and analyzing the rule to obtain a syntax tree;
wherein the at least one element comprises a node in the syntax tree.
In an embodiment of the present disclosure, when the rule engine 1002 invokes the first scenario adapter to process the at least one element to obtain an output result corresponding to the rule, the method includes:
analyzing the syntax tree through a rule engine, and calling a function corresponding to the type of the node in the first scene adapter to obtain an output result of the node when each node is analyzed;
and obtaining an output result corresponding to the rule after all the nodes of the grammar tree are analyzed.
In one embodiment of the present disclosure, the output results obtained by different scenario adapters are different for the same node.
In one embodiment of the present disclosure, the at least one scene adapter 1003 comprises at least one of: a rule evaluator, a query statement converter, a natural language translator and a condition checker.
In an embodiment of the present disclosure, the service logic module 1001 is specifically configured to execute any one of the following:
if the obtained rule output request is used for indicating that the output value of the rule is calculated according to the input condition information, determining that the first scene adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into a query statement, determining that the first scene adapter is the query statement converter, wherein the query statement is used for querying data meeting the rule in a database; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into the natural language, determining that the first scene adapter is the natural language translator; or the like, or, alternatively,
and if the acquired rule output request is used for indicating the values of partial variables in the given rule to calculate the constraint conditions of the other variables, determining that the first scene adapter is the condition checker, and sending the values of the partial variables to the condition checker.
In an embodiment of the present disclosure, if the first scenario adapter is the rule evaluator, the first scenario adapter is specifically configured to, when processing the at least one element:
for each node, if the node comprises a variable, assigning a value to the variable according to the acquired input condition information;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
In an embodiment of the present disclosure, if the first scene adapter is the query statement converter, when the first scene adapter processes the at least one element, the first scene adapter is specifically configured to:
and for each node, converting the node into a corresponding query field so as to obtain a query statement corresponding to the rule after the plurality of nodes of the syntax tree are processed.
In an embodiment of the present disclosure, if the first scenario adapter is the natural language translator, when the first scenario adapter processes the at least one element, the first scenario adapter is specifically configured to:
and for each node, converting the node into a corresponding character so as to obtain the natural language corresponding to the rule after the plurality of nodes of the grammar tree are processed.
In an embodiment of the present disclosure, if the first scene adapter is the condition checker, when the first scene adapter processes the at least one element, the first scene adapter is specifically configured to:
for each node, if the node comprises a variable, assigning a value to the variable, or converting the variable into a corresponding character;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
In an embodiment of the present disclosure, if the node includes a variable, the first scene adapter is specifically configured to, when assigning a value to the variable or converting the variable into a corresponding text:
judging whether a value corresponding to the variable is given in the rule output requirement or not;
if yes, assigning a value to the variable; if not, the variable is converted into the corresponding character.
In an embodiment of the present disclosure, the service logic module 1001 is further configured to:
before acquiring a rule output requirement, acquiring user condition information meeting a group requirement;
determining a rule corresponding to the group according to the user condition information;
wherein, the rule to be processed is the rule corresponding to the group.
The apparatus provided in this embodiment may be used to implement the technical solutions of the above method embodiments, and the implementation principles and technical effects are similar, which are not described herein again.
Fig. 11 is a block diagram of an electronic device according to an embodiment of the present disclosure. Referring to fig. 11, the electronic device 1100 may be a terminal device or a server. Among them, the terminal Device may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a Digital broadcast receiver, a Personal Digital Assistant (PDA), a tablet computer (PAD), a Portable Multimedia Player (PMP), a car terminal (e.g., car navigation terminal), etc., and a fixed terminal such as a Digital TV, a desktop computer, etc. The electronic device shown in fig. 11 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 11, the electronic device 1100 may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 1101, which may 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 means 1108 into a Random Access Memory (RAM) 1103. In the RAM 1103, various programs and data necessary for the operation of the electronic device 1100 are also stored. The processing device 1101, the ROM 1102, and the RAM 1103 are connected to each other by a bus 1104. An input/output (I/O) interface 1105 is also connected to bus 1104.
Generally, the following devices may be connected to the I/O interface 1105: input devices 1106 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 1107 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 1108, including, for example, magnetic tape, hard disk, etc.; and a communication device 11011. The communication means 11011 may allow the electronic device 1100 to communicate wirelessly or by wire with other devices to exchange data. While fig. 11 illustrates an electronic device 1100 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via the communication device 11011, or installed from the storage device 1108, or installed from the ROM 1102. The computer program, when executed by the processing device 1101, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to perform the methods shown in the above embodiments.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of Network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above 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 a chip (SOCs), Complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The 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, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
In a first aspect, according to one or more embodiments of the present disclosure, there is provided a rule processing method, including:
acquiring a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter;
acquiring a rule to be processed and analyzing the rule to obtain at least one element contained in the rule;
and processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule.
According to one or more embodiments of the present disclosure, acquiring a rule to be processed and analyzing the rule to obtain at least one element included in the rule, includes:
acquiring a rule to be processed, and analyzing the rule to obtain a syntax tree;
wherein the at least one element comprises a node in the syntax tree.
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:
analyzing the syntax tree through a rule engine, and calling a function corresponding to the type of the node in the first scene adapter to obtain an output result of the node when each node is analyzed;
and obtaining an output result corresponding to the rule after all the nodes of the grammar tree are analyzed.
According to one or more embodiments of the present disclosure, output results obtained by different scene adapters are different for the same node.
According to one or more embodiments of the present disclosure, the at least one scene adapter comprises at least one of: a rule evaluator, a query statement converter, a natural language translator and a condition checker.
According to one or more embodiments of the present disclosure, a rule output requirement is obtained, and a first scenario adapter corresponding to the rule output requirement is determined from at least one scenario adapter, where the method includes any one of:
if the obtained rule output request is used for indicating that the output value of the rule is calculated according to the input condition information, determining that the first scene adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into a query statement, determining that the first scene adapter is the query statement converter, wherein the query statement is used for querying data meeting the rule in a database; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into the natural language, determining that the first scene adapter is the natural language translator; or the like, or, alternatively,
and if the acquired rule output request is used for indicating the values of partial variables in the given rule to calculate the constraint conditions of the other variables, determining that the first scene adapter is the condition checker, and sending the values of the partial variables to the condition checker.
According to one or more embodiments of the present disclosure, if the first scenario adapter is the rule evaluator, the processing the at least one element includes:
for each node, if the node comprises a variable, assigning a value to the variable according to the acquired input condition information;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
According to one or more embodiments of the present disclosure, if the first scenario adapter is the query statement converter, the processing the at least one element includes:
and for each node, converting the node into a corresponding query field so as to obtain a query statement corresponding to the rule after the plurality of nodes of the syntax tree are processed.
According to one or more embodiments of the present disclosure, if the first scenario adapter is the natural language translator, the processing the at least one element includes:
and for each node, converting the node into a corresponding character so as to obtain the natural language corresponding to the rule after the plurality of nodes of the grammar tree are processed.
According to one or more embodiments of the present disclosure, if the first scene adapter is the condition checker, the processing the at least one element includes:
for each node, if the node comprises a variable, assigning a value to the variable, or converting the variable into a corresponding character;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
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 word, includes:
if the node comprises a variable, judging whether a value corresponding to the variable is given in the rule output requirement or not;
if yes, assigning a value to the variable; if not, the variable is converted into the corresponding character.
According to one or more embodiments of the present disclosure, before obtaining the rule output requirement, the method further includes: acquiring user condition information meeting group requirements;
determining a rule corresponding to the group according to the user condition information;
wherein, the rule to be processed is the rule corresponding to the group.
In a second aspect, according to one or more embodiments of the present disclosure, there is provided a rule processing apparatus including: a business logic module, a rules engine, and at least one scenario adapter.
The business logic module is used for acquiring a rule output requirement and determining a first scene adapter corresponding to the rule output requirement from the at least one scene adapter;
the rule engine is used for acquiring a rule to be processed, analyzing the rule to obtain at least one element contained in the rule, and calling the first scene adapter to process the at least one element to obtain an output result corresponding to the rule.
According to one or more embodiments of the present disclosure, when the rule engine acquires a rule to be processed and parses the rule to obtain at least one element included in the rule, the rule engine includes:
acquiring a rule to be processed, and analyzing the rule to obtain a syntax tree;
wherein the at least one element comprises a node in the syntax tree.
According to one or more embodiments of the present disclosure, when the rule engine invokes the first scene adapter to process the at least one element and obtain an output result corresponding to the rule, the rule engine includes:
analyzing the syntax tree through a rule engine, and calling a function corresponding to the type of the node in the first scene adapter to obtain an output result of the node when each node is analyzed;
and obtaining an output result corresponding to the rule after all the nodes of the grammar tree are analyzed.
According to one or more embodiments of the present disclosure, output results obtained by different scene adapters are different for the same node.
According to one or more embodiments of the present disclosure, the at least one scene adapter comprises at least one of: a rule evaluator, a query statement converter, a natural language translator and a condition checker.
According to one or more embodiments of the present disclosure, the business logic module is specifically configured to perform any one of the following:
if the obtained rule output request is used for indicating that the output value of the rule is calculated according to the input condition information, determining that the first scene adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into a query statement, determining that the first scene adapter is the query statement converter, wherein the query statement is used for querying data meeting the rule in a database; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into the natural language, determining that the first scene adapter is the natural language translator; or the like, or, alternatively,
and if the acquired rule output request is used for indicating the values of partial variables in the given rule to calculate the constraint conditions of the other variables, determining that the first scene adapter is the condition checker, and sending the values of the partial variables to the condition checker.
According to one or more embodiments of the present disclosure, if the first scenario adapter is the rule evaluator, the first scenario adapter is specifically configured to, when processing the at least one element:
for each node, if the node comprises a variable, assigning a value to the variable according to the acquired input condition information;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
According to one or more embodiments of the present disclosure, if the first scene adapter is the query statement converter, when the first scene adapter processes the at least one element, the first scene adapter is specifically configured to:
and for each node, converting the node into a corresponding query field so as to obtain a query statement corresponding to the rule after the plurality of nodes of the syntax tree are processed.
According to one or more embodiments of the present disclosure, if the first scenario adapter is the natural language translator, the first scenario adapter is specifically configured to, when processing the at least one element:
and for each node, converting the node into a corresponding character so as to obtain the natural language corresponding to the rule after the plurality of nodes of the grammar tree are processed.
According to one or more embodiments of the present disclosure, if the first scene adapter is the condition checker, when the first scene adapter processes the at least one element, the first scene adapter is specifically configured to:
for each node, if the node comprises a variable, assigning a value to the variable, or converting the variable into a corresponding character;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
According to one or more embodiments of the present disclosure, if the node includes a variable, the first scene adapter is specifically configured to, when assigning a value to the variable or converting the variable into a corresponding text:
judging whether a value corresponding to the variable is given in the rule output requirement or not;
if yes, assigning a value to the variable; if not, the variable is converted into the corresponding character.
In accordance with one or more embodiments of the present disclosure, the business logic module is further configured to:
before acquiring a rule output requirement, acquiring user condition information meeting a group requirement;
determining a rule corresponding to the group according to the user condition information;
wherein, the rule to be processed is the rule corresponding to the group.
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;
the memory stores computer-executable instructions;
the at least one processor executes computer-executable instructions stored by the memory to cause the at least one processor to perform the rule processing method as set forth in the first aspect above and in various possible designs of the first aspect.
In a fourth aspect, according to one or more embodiments of the present disclosure, there is provided a computer-readable storage medium having stored therein computer-executable instructions that, when executed by a processor, implement the rule processing method as set forth in the first aspect and various possible designs of the first aspect.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (15)

1. A method of rule processing, the method comprising:
acquiring a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter;
acquiring a rule to be processed and analyzing the rule to obtain at least one element contained in the rule;
and processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule.
2. The method of claim 1, wherein obtaining a rule to be processed and parsing the rule to obtain at least one element included in the rule comprises:
acquiring a rule to be processed, and analyzing the rule to obtain a syntax tree;
wherein the at least one element comprises a node in the syntax tree.
3. The method of claim 2, wherein processing the at least one element through the first scene adapter to obtain an output result corresponding to the rule comprises:
analyzing the syntax tree through a rule engine, and calling a function corresponding to the type of the node in the first scene adapter to obtain an output result of the node when each node is analyzed;
and obtaining an output result corresponding to the rule after all the nodes of the grammar tree are analyzed.
4. The method of claim 3, wherein the output results obtained by different scene adapters are different for the same node.
5. The method of claim 2, wherein the at least one scene adapter comprises at least one of: a rule evaluator, a query statement converter, a natural language translator and a condition checker.
6. The method according to claim 5, wherein obtaining a rule output requirement, and determining a first scene adapter corresponding to the rule output requirement from at least one scene adapter comprises any one of:
if the obtained rule output request is used for indicating that the output value of the rule is calculated according to the input condition information, determining that the first scene adapter is the rule evaluator, and sending the input condition information to the rule evaluator; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into a query statement, determining that the first scene adapter is the query statement converter, wherein the query statement is used for querying data meeting the rule in a database; or the like, or, alternatively,
if the obtained rule output request is used for indicating that the rule is converted into the natural language, determining that the first scene adapter is the natural language translator; or the like, or, alternatively,
and if the acquired rule output request is used for indicating the values of partial variables in the given rule to calculate the constraint conditions of the other variables, determining that the first scene adapter is the condition checker, and sending the values of the partial variables to the condition checker.
7. The method of claim 6, wherein said processing said at least one element if said first scenario adapter is said rule evaluator comprises:
for each node, if the node comprises a variable, assigning a value to the variable according to the acquired input condition information;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
8. The method of claim 6, wherein if the first scene adapter is the query statement converter, the processing the at least one element comprises:
and for each node, converting the node into a corresponding query field so as to obtain a query statement corresponding to the rule after the plurality of nodes of the syntax tree are processed.
9. The method of claim 6, wherein if the first scenario adapter is the natural language translator, the processing the at least one element comprises:
and for each node, converting the node into a corresponding character so as to obtain the natural language corresponding to the rule after the plurality of nodes of the grammar tree are processed.
10. The method of claim 6, wherein if the first scene adapter is the condition checker, the processing the at least one element comprises:
for each node, if the node comprises a variable, assigning a value to the variable, or converting the variable into a corresponding character;
if the node comprises the constant, returning the constant;
and if the node is a binary node and comprises an operator, calculating a processing result corresponding to the binary node according to the operator.
11. The method of claim 10, wherein assigning a value to a variable if the node includes the variable, or converting the variable into a corresponding word, comprises:
if the node comprises a variable, judging whether a value corresponding to the variable is given in the rule output requirement or not;
if yes, assigning a value to the variable; if not, the variable is converted into the corresponding character.
12. The method of any of claims 1-11, further comprising, prior to obtaining the rule output requirements:
acquiring user condition information meeting group requirements;
determining a rule corresponding to the group according to the user condition information;
wherein, the rule to be processed is the rule corresponding to the group.
13. A rule conversion apparatus, comprising: the system comprises a business logic module, a rule engine and at least one scene adapter;
the business logic module is used for acquiring a rule output requirement and determining a first scene adapter corresponding to the rule output requirement from the at least one scene adapter;
the rule engine is used for acquiring a rule to be processed, analyzing the rule to obtain at least one element contained in the rule, and calling the first scene adapter to process the at least one element to obtain an output result corresponding to the rule.
14. An electronic device, comprising: a memory and at least one processor;
the memory stores computer-executable instructions;
the at least one processor executing the computer-executable instructions stored by the memory causes the at least one processor to perform the rule processing method of any of claims 1 to 12.
15. A computer-readable storage medium having stored thereon computer-executable instructions which, when executed by a processor, implement the rule processing method of any one of claims 1 to 12.
CN202010941802.8A 2020-09-09 2020-09-09 Rule processing method, device, equipment and storage medium Pending CN112069214A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010941802.8A CN112069214A (en) 2020-09-09 2020-09-09 Rule processing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010941802.8A CN112069214A (en) 2020-09-09 2020-09-09 Rule processing method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112069214A true CN112069214A (en) 2020-12-11

Family

ID=73663116

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010941802.8A Pending CN112069214A (en) 2020-09-09 2020-09-09 Rule processing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112069214A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114780107A (en) * 2022-06-23 2022-07-22 北京宇信科技集团股份有限公司 Grammar analysis method, device and decision engine for rule running file

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282373A1 (en) * 2013-03-15 2014-09-18 Trinity Millennium Group, Inc. Automated business rule harvesting with abstract syntax tree transformation
CN108628947A (en) * 2018-04-02 2018-10-09 阿里巴巴集团控股有限公司 A kind of business rule matched processing method, device and processing equipment
CN111176656A (en) * 2019-12-09 2020-05-19 苏宁云计算有限公司 Complex data matching method and medium
CN111399818A (en) * 2020-03-17 2020-07-10 深圳市卡牛科技有限公司 Recommendation engine design method, recommendation engine design device, server and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282373A1 (en) * 2013-03-15 2014-09-18 Trinity Millennium Group, Inc. Automated business rule harvesting with abstract syntax tree transformation
CN108628947A (en) * 2018-04-02 2018-10-09 阿里巴巴集团控股有限公司 A kind of business rule matched processing method, device and processing equipment
CN111176656A (en) * 2019-12-09 2020-05-19 苏宁云计算有限公司 Complex data matching method and medium
CN111399818A (en) * 2020-03-17 2020-07-10 深圳市卡牛科技有限公司 Recommendation engine design method, recommendation engine design device, server and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114780107A (en) * 2022-06-23 2022-07-22 北京宇信科技集团股份有限公司 Grammar analysis method, device and decision engine for rule running file

Similar Documents

Publication Publication Date Title
CN114116065B (en) Method and device for acquiring topological graph data object and electronic equipment
CN111324342A (en) Method, device, medium and electronic equipment for generating interface layer code
CN111159220A (en) Method and apparatus for outputting structured query statement
CN110543297A (en) method and apparatus for generating source code
CN109101294B (en) Data acquisition method, plug-in, electronic equipment and storage medium
CN114035805A (en) Code conversion method, apparatus, medium, and device for pre-compiler
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN115221191A (en) Virtual column construction method based on data lake and data query method
CN114721656A (en) Interface structure extraction method, device, medium and electronic equipment
CN114816578A (en) Method, device and equipment for generating program configuration file based on configuration table
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN112069214A (en) Rule processing method, device, equipment and storage medium
CN108062401B (en) Application recommendation method and device and storage medium
CN116860286A (en) Page dynamic update method, device, electronic equipment and computer readable medium
CN111124541A (en) Configuration file generation method, device, equipment and medium
CN115808993A (en) Interaction method, interaction device, electronic equipment and computer readable medium
CN113138767B (en) Code language conversion method, device, electronic equipment and storage medium
CN114816382A (en) Method and device for processing page
CN113987118A (en) Corpus acquisition method, apparatus, device and storage medium
CN113760240B (en) Method and device for generating data model
CN111539200B (en) Method, device, medium and electronic equipment for generating rich text
CN113468342A (en) Data model construction method, device, equipment and medium based on knowledge graph
CN109669720B (en) Chain type asynchronous request processing method and device based on Promise and electronic equipment
CN113761588A (en) Data verification method and device, terminal equipment and storage medium
CN113835893B (en) Data processing method, device, equipment, storage medium and program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination