CN107220098B - Method and device for implementing rule engine - Google Patents

Method and device for implementing rule engine Download PDF

Info

Publication number
CN107220098B
CN107220098B CN201710448421.4A CN201710448421A CN107220098B CN 107220098 B CN107220098 B CN 107220098B CN 201710448421 A CN201710448421 A CN 201710448421A CN 107220098 B CN107220098 B CN 107220098B
Authority
CN
China
Prior art keywords
rule
input data
attribute
key attribute
value
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.)
Active
Application number
CN201710448421.4A
Other languages
Chinese (zh)
Other versions
CN107220098A (en
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 QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and 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 QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN201710448421.4A priority Critical patent/CN107220098B/en
Publication of CN107220098A publication Critical patent/CN107220098A/en
Application granted granted Critical
Publication of CN107220098B publication Critical patent/CN107220098B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a method and a device for realizing a rule engine, wherein the method comprises the following steps: receiving input data; matching the input data in a rule set of the rule engine, wherein the rule set comprises a plurality of rules, and the rules are configured based on a JSON format; and for the rule, if the input data comprises key attributes corresponding to the rule, performing rule verification on the input data according to the key attributes, and performing updating operation on the input data according to the rule, if the input data does not comprise the key attributes, extracting an object from the input data, acquiring an attribute value corresponding to the object by using a Java reflection mechanism, performing rule verification on the input data according to the object and the attribute value, and performing updating operation on the input data according to the rule. The invention can simplify the development process of the rule engine and improve the efficiency.

Description

Method and device for implementing rule engine
Technical Field
The invention relates to the technical field of computers and internet, in particular to a method and a device for realizing a rule engine.
Background
The rule engine is developed by an inference engine, is a component embedded in an application program, and is used for separating business decisions from application program codes and writing the business decisions by using a predefined semantic module. The workflow of the rules engine can be understood as: firstly, data input is accepted, then the business rules are explained, and finally business decisions are made according to the business rules.
For a service system, complex and variable service rules are difficult to decouple service codes without the support of a rule engine, and the service change cannot be responded in time. An existing rule engine, such as open source Drools (JBossRules, an open source business rule engine that is easy to access enterprise policies, easy to adjust, and easy to manage), is configured based on Xml (Extensible Markup Language) and a specific Drl file (file with extension name of dri), and the Drools rule configuration is not visually edited to a high degree and is mainly maintained by a background developer, so that the visual development and maintenance costs are high.
Disclosure of Invention
In order to simplify the development of the rule engine, embodiments of the present invention provide a method and an apparatus for implementing the rule engine.
According to one aspect of the present invention, there is provided a method for implementing a rule engine, including: receiving input data; matching the input data in a rule set of the rule engine, wherein the rule set comprises a plurality of rules, and the rules are configured based on a JSON format; and for the rule, if the input data comprises key attributes corresponding to the rule, performing rule verification on the input data according to the key attributes, and performing updating operation on the input data according to the rule, if the input data does not comprise the key attributes, extracting an object from the input data, acquiring an attribute value corresponding to the object by using a Java reflection mechanism, performing rule verification on the input data according to the object and the attribute value, and performing updating operation on the input data according to the rule.
Optionally, the rule includes a condition object and an execution object, and the method further includes: configuring the condition object and the execution object based on JSON format; the condition object comprises a JSON array formed by field item parameters, operation item parameters and value item parameters, and the execution object comprises a JSON array formed by field item parameters and setting value item parameters.
Optionally, the performing rule verification on the input data according to the key attribute includes: acquiring a rule with the highest priority according to the rule priority; aiming at the currently obtained rule, determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included by the condition object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and if the value corresponding to the key attribute of the input data is consistent with the value of the key attribute in the condition object, determining that the rule passes the verification.
Optionally, the updating the input data according to the rule includes: determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included in the execution object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and updating the value of the key attribute of the input data according to the value of the key attribute in the condition object.
Optionally, if the input data does not include the key attribute, the extracting an object from the input data and obtaining an attribute value corresponding to the object by using a Java reflection mechanism includes: analyzing the field item parameters into a format of an object/attribute, and acquiring the object from the input data; and extracting the object from the input data by using a Java reflection mechanism, and obtaining the attribute value of the object by using a Get/Set method of the object.
Optionally, the rules are cached in a distributed structure.
According to another aspect of the present invention, there is provided an apparatus for implementing a rule engine, including: an input data receiving unit for receiving input data; the rule matching unit is used for matching the input data in a rule set of the rule engine, wherein the rule set comprises a plurality of rules, and the rules are configured based on a JSON format; and the rule checking and executing unit is used for carrying out rule checking on the input data according to the key attribute and carrying out updating operation on the input data according to the rule if the input data comprises the key attribute corresponding to the rule for the rule, extracting an object from the input data if the input data does not comprise the key attribute, acquiring an attribute value corresponding to the object by using a Java reflection mechanism, carrying out rule checking on the input data according to the object and the attribute value, and carrying out updating operation on the input data according to the rule.
Optionally, the rule includes a condition object and an execution object, and the apparatus further includes: the object configuration unit is used for configuring the condition object and the execution object based on the JSON format; the condition object comprises a JSON array formed by field item parameters, operation item parameters and value item parameters, and the execution object comprises a JSON array formed by field item parameters and setting value item parameters.
Optionally, the rule checking and executing unit includes: the rule checking subunit is used for acquiring the rule with the highest priority according to the rule priority; aiming at the currently obtained rule, determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included by the condition object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and if the value corresponding to the key attribute of the input data is consistent with the value of the key attribute in the condition object, determining that the rule passes the verification.
Optionally, the rule checking and executing unit includes: the rule execution subunit is used for determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included in an execution object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and updating the value of the key attribute of the input data according to the value of the key attribute in the condition object.
Optionally, if the input data does not include the key attribute, the rule checking and executing unit includes: the reflection processing subunit is used for analyzing the field item parameters into a format of an object/attribute and acquiring the object from the input data; and extracting the object from the input data by using a Java reflection mechanism, and obtaining the attribute value of the object by using a Get/Set method of the object.
Preferably, the rules are cached in a distributed structure.
Therefore, the Rule engine is realized based on JSON and a reflection mechanism, and based on the Rule configuration of JSON, convenience is provided for the front-end visualization development of the Rule engine, so that the Rule engine is more convenient and clear to configure; the method is clear in the configuration of Rule and is simple and efficient in implementation. By adopting a lightweight data exchange language JSON and a Java reflection mechanism, the system can quickly respond to frequently-changed business rule adjustment through dynamic configuration, reduce development and operation and maintenance costs and improve system flexibility; and by adopting the distributed structure cache rule, the resource consumption caused by the analysis rule is reduced, and the running efficiency of the rule engine is improved. The rule engine implementation scheme provides quick response to the auditing strategies of related services such as videos, pictures and texts, greatly reduces the workload of auditing, and saves the auditing labor cost and development cost.
Drawings
FIG. 1 is a flow chart of a method for implementing a rules engine according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a class diagram of a rules engine in a rules engine according to another embodiment of the present invention;
FIG. 3 is a flow chart of a method for implementing a rules engine according to another embodiment of the present invention;
fig. 4 is a schematic structural diagram of an implementation apparatus of a rule engine according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Referring to fig. 1, a flowchart of an implementation method of a rule engine provided in an embodiment of the present invention is shown, where the method includes:
s101: receiving input data;
s102: matching input data in a rule set of a rule engine, wherein the rule set comprises a plurality of rules, and the rules are configured based on a JSON format;
s103: judging whether the input data comprises key attributes corresponding to the rules, if so, executing step S104, and if not, executing step S105;
s104: carrying out rule verification on the input data according to the key attributes, and carrying out updating operation on the input data according to the rules;
s105: extracting an object from input data, acquiring an attribute value corresponding to the object by using a Java reflection mechanism, carrying out rule verification on the input data according to the object and the attribute value, and carrying out updating operation on the input data according to the rule.
Therefore, the invention provides a quick and efficient implementation mode based on the scene that the auditing system frequently changes the service logic, adopts a lightweight data exchange language JSON (JavaScript Object Notation) and a Java reflection mechanism, facilitates the integration and visual development in the existing system, and is easy for developers and service personnel to maintain and use together. It is also mentioned above that all rule configuration of the present invention is based on JSON technology, JSON is a native format of JavaScript, which means that no special API or toolkit is needed to process JSON data in JavaScript, so front-end development is simplified.
In an alternative implementation, the input data refers to Map (String, Object) type data, the data format flexibly supports each type of data, and any type of data can be stored in the data format, so that the flexibility of the scheme is improved.
Those skilled in the art understand that the minimum unit of execution in the Rule engine is a Rule set (Rule), and a Rule set is composed of a plurality of rules (Rule). A Rule is composed of a Condition object (Condition) and multiple execution objects (actions).
In an alternative, rules are stored in a Memcached distributed structure, thereby increasing the execution efficiency of the rules engine.
In an alternative implementation, the rule includes a condition object and an execution object, and thus the configuration of the rule specifically includes: configuring a condition object and an execution object based on the JSON format; the condition object comprises a JSON array formed by field item parameters, operation item parameters and value item parameters, and the execution object comprises a JSON array formed by field item parameters and setting value item parameters.
In an optional manner, the performing a rule check on the input data according to the key attribute includes: acquiring a rule with the highest priority according to the rule priority; aiming at the currently obtained rule, determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included by the condition object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and if the value corresponding to the key attribute of the input data is consistent with the value of the key attribute in the condition object, determining that the rule is verified to be passed.
In an alternative, the updating the input data according to the rule includes: determining a key attribute format consisting of one parameter or a plurality of parameters according to various parameters included in an execution object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and updating the value of the key attribute of the input data according to the value of the key attribute in the condition object.
In an optional manner, if the input data does not include the key attribute corresponding to the rule, the specific step of processing by using the reflection mechanism includes: analyzing the field item parameters into a format of an object/attribute, and acquiring the object from input data; and extracting the object from the input data by using a Java reflection mechanism, and obtaining the attribute value of the object by using a Get/Set method of the object.
Therefore, in the new implementation scheme of the rule engine provided by the invention, the rule engine can be quickly integrated and implemented in the existing business system based on JSON and reflection technology and optionally based on the currently popular Spring framework. For a scene in which a business rule changes frequently and needs to take effect in time, for example, a review system needs to dynamically adjust a machine review related policy (including a task priority policy, a machine review result policy, a task flow policy, and the like) according to an operation policy, the rule engine can efficiently cope with the business rule, specifically, the rule engine can meet the requirements of most business scenes by using flexible input and output, and the rule can be efficiently executed by using a cache technology and a java reflection technology to realize efficient processing. Meanwhile, the visual configuration which is simple and easy to understand is convenient for developers and non-developers to use together.
Another embodiment of the present invention is described below in conjunction with fig. 2-3.
The implementation process of the rule engine mainly comprises the following three steps:
1. input data is prepared. In an optional manner of the embodiment of the present invention, the input data format is a Map (String, Object) type, and the data format flexibly supports various types of data. The total input is defined as a Map format, which has great flexibility and can store any type of data inside.
2. And checking the Rule, and judging whether the condition is met according to the value required by the input data acquisition Rule.
3. And executing the Action, if the rule is satisfied, executing the specific Action specified by the Action, and returning the result, otherwise, directly skipping.
The following describes embodiments of the present invention in terms of overall design of a rule engine, setting of condition objects and execution objects, and execution flows of the condition objects and the execution objects.
The minimum unit of execution in the Rule engine is Rule set RuleSet, and one Rule set is composed of a plurality of rules Rule. A Rule is composed of a Condition object and a plurality of Action execution objects. The execution of the rule set implements two strategies, one is to jump out if satisfied, and the other is to execute to the end. Additionally, rules in the rule set support prioritization.
The rule engine is additionally provided with Memcached distributed cache, so that the execution efficiency of the rule engine can be greatly improved. Referring to FIG. 2, a schematic diagram of a rules engine class diagram is shown. In fig. 2, the Rule engine includes a plurality of rulesets, each RuleSet includes a plurality of rules, one Rule is composed of a Condition object and a plurality of Action execution objects, one Condition is composed of a Condition item and a Condition group, and a RuleInputOutput is used to configure a parameter type corresponding to field in Conditon, so as to be applied when reflection is facilitated.
Referring to fig. 3, a flowchart of an implementation process of the rule engine in this embodiment is shown.
Fig. 3 includes the steps of:
s301: receiving input data;
s302: executing a rule set RuleSet;
s303: selecting a Rule according to the Rule priority and checking;
s304: performing a continton decision: obtaining an actual value of the object from the input data, comparing the actual value with the configuration value, if the actual value is matched with the configuration value, executing S305, and if not, returning to execute S303;
s305: and (4) performing action: updating the attribute according to Action configuration;
s306: judging the type of the rule set, and if the rule set type is satisfied, jumping out, and turning to S306; if the execution is finished, turning to S303;
s307: and finishing and outputting the result.
As mentioned above, the Conditon and Action are configured based on JSON, the JSON is a text format completely independent of languages, data access is simplified, and front-end development is facilitated.
For example, the format of Conditon is shown in Table 1.
TABLE 1
Figure GDA0002434140060000071
The groups attribute in Conditon corresponds to a ConditionGroup array, which may include ConditionGroup or ConditonItem.
The ConditonItem format is shown in table 2, for example.
TABLE 2
Figure GDA0002434140060000072
Figure GDA0002434140060000081
Action is a json array consisting of items, [ { Item0}, { Item } ], below.
The Item format is shown in Table 3.
TABLE 3
Figure GDA0002434140060000082
After the configuration of Conditon and Action is carried out, the configuration of Rule is completed, and then when input data is matched, matching is carried out according to the configuration of Conditon and Action.
The rule input data is in Map (String, Object) format, which is retrieved as a key into the Map according to the field attribute in the configuration.
For example, a field attribute, i.e. the field defined in the ConditionItem above, i.e. a certain condition KEY (KEY attribute) in the service rule configuration, e.g. a user ID (user identification), e.g. a complete piece of a rule may be such that: and if the user ID is 1, the video auditing result is passed. Then, the user ID 1 is ConditionItem, where "user ID" is field and "1" is value. The "video review result is passed" is Action, wherein the "video review result" is field, and the "pass" is value.
If a rule is directly hit, if Condtion is the case, the corresponding value is taken out, and logic judgment is carried out according to the configured operation type op and the configured value; and the Action sets a value corresponding to the current key according to the configuration.
If not, the field attribute is analyzed into a format of object name and attribute name, the object is obtained from the input data according to the object name, and the attribute value corresponding to the Get/Set is removed by using a java reflection mechanism.
The principle of the format of resolving into object name attribute name is as follows: also as the rule above, "User ID is 1, then the video review result is passed" for example, since the User ID is to be determined, the User information is input into the rule engine, and the User is defined as the User object, which includes the ID attribute. Put ("User", new User ()), i.e. one Map data containing key "User" and Value as User object.
The principle of removing the attribute value corresponding to Get/Set by using the java reflection mechanism is as follows: each attribute in the Java object has a corresponding Get/Set method, wherein Get is an acquisition value, and Set is a setting value. The reflection mechanism is a bottom API provided by Java, and can be dynamically called according to the method name and a specific object, so that the specific attribute of the object is obtained or modified.
This is explained below as a specific example.
As mentioned above, a rule may be understood to consist of Conditon and Action, and for a rule (current rule), a hit and a rule hit or miss, which is not the case for a miss, are for KEY (KEY attribute) in the input data Map.
For example: the Map data input is:
Figure GDA0002434140060000091
the KEY is "KEY 1"/"User. id"/"User", and the User corresponds to a Java object.
If a rule Conditon at this point is (contains only one conditontem): { "groups" [ { "field": user. id "," op ": ═ value": 3"} ]," op ": or" }
When the input data is executed in the Condtion part of the rule, field, here "user.id" is first taken from Conditon and this field is used as key to find the input value in the input data. Id's Key exists in the input data as a result of matching, the fetched value is 2, and since there is a directly configured Key, the id value is not reflected from the object User at this time either.
If the input data is modified to:
Figure GDA0002434140060000101
the inner keys are only two: "key 1"/"User", again the above rule, is executed using the field: the "user.id" is used as a key to search the input data, and the corresponding value cannot be directly found, at this time, the field is analyzed into a format of "object name. attribute", and the object name is used as a key to input data to find the corresponding object. The column above is to take "User" as a key to find, thereby obtaining a User object, and then obtain the value of id from the object according to reflection.
The same is true for the principle of Action execution, for example, the Action part of the above rule is: "field", "user. name", "value", "zhang" etc. ], the complete meaning of this rule is "modify its name to zhang three if the user ID is 3".
When the method is executed, field name is taken as integral key to be searched in Map data, if the value is existed, the original value is directly covered (the value is simply assigned to Map), the key User name is not existed in the input data of the example, so the format of object name attribute is analyzed, the object name User is used as key to be searched in Map, an object is found at this time, and then the name attribute of the object is set to be three by using a reflection mechanism.
Therefore, in the embodiment of the invention, the Rule engine is realized based on JSON and a reflection mechanism, and the Rule configuration based on JSON provides convenience for the front-end visualization development of the Rule engine, so that the Rule engine is more convenient and clear to configure; the method is clear in the configuration of Rule and is simple and efficient in implementation. The dynamic configuration can quickly respond to the frequently changed business rule adjustment, the development and operation and maintenance cost is reduced, and the system flexibility is improved; and by adopting a rule caching strategy, the resource consumption caused by rule analysis is reduced, and the operating efficiency of a rule engine is improved. The rule engine implementation scheme provides quick response to the auditing strategies of related services such as videos, pictures and texts, greatly reduces the workload of auditing, and saves the auditing labor cost and development cost.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the illustrated order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments of the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are exemplary embodiments and that no single embodiment is necessarily required by the inventive embodiments.
Fig. 4 is a schematic structural diagram of an apparatus according to an embodiment of the present invention. The device includes:
an input data receiving unit 401 for receiving input data;
a rule matching unit 402, configured to match the input data in a rule set of the rule engine, where the rule set includes a plurality of rules and the rules are configured based on a JSON format;
a rule checking and executing unit 403, configured to, for the rule, if the input data includes a key attribute corresponding to the rule, perform rule checking on the input data according to the key attribute, and perform an update operation on the input data according to the rule, if the input data does not include the key attribute, extract an object from the input data, acquire an attribute value corresponding to the object by using a Java reflection mechanism, perform rule checking on the input data according to the object and the attribute value, and perform an update operation on the input data according to the rule.
Optionally, the rule includes a condition object and an execution object, and the apparatus further includes:
an object configuration unit 404, configured to configure the conditional object and the execution object based on the JSON format; the condition object comprises a JSON array formed by field item parameters, operation item parameters and value item parameters, and the execution object comprises a JSON array formed by field item parameters and setting value item parameters.
Optionally, the rule checking and executing unit 403 includes:
a rule checking subunit 4031, configured to obtain a rule with the highest priority according to the rule priority; aiming at the currently obtained rule, determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included by the condition object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and if the value corresponding to the key attribute of the input data is consistent with the value of the key attribute in the condition object, determining that the rule passes the verification.
Optionally, the rule checking and executing unit 403 includes:
a rule execution subunit 4032, configured to determine, according to each parameter included in an execution object in the rule, a key attribute format formed by one parameter or multiple parameters; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and updating the value of the key attribute of the input data according to the value of the key attribute in the condition object.
Optionally, if the input data does not include the key attribute, the rule checking and executing unit 403 includes:
a reflection processing subunit 4033, configured to analyze the field item parameter as a format of an object/attribute, and acquire an object from the input data; and extracting the object from the input data by using a Java reflection mechanism, and obtaining the attribute value of the object by using a Get/Set method of the object.
Optionally, the rules are cached in a distributed structure.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While alternative embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including alternative embodiments and all such alterations and modifications as fall within the true scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The method and the device for implementing the rule engine provided by the invention are described in detail, and the principle and the implementation mode of the invention are explained by applying specific examples, and the description of the embodiments is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (12)

1. A method for implementing a rules engine, comprising:
receiving input data;
matching the input data in a rule set of the rule engine, wherein the rule set comprises a plurality of rules, and the rules are configured based on a JSON format;
for the rule, if the input data comprises a key attribute corresponding to the rule, performing rule verification on the input data according to the key attribute, and performing updating operation on the input data according to the rule,
if the input data does not include the key attribute, extracting an object from the input data, acquiring an attribute value corresponding to the object by using a Java reflection mechanism, performing rule verification on the input data according to the object and the attribute value, and performing updating operation on the input data according to a rule; wherein the extracting of the object from the input data comprises: and analyzing the field item parameters into the format of the object/attribute, and acquiring the object from the input data, wherein the rule comprises the field item parameters.
2. The method of claim 1, wherein the rule comprises a condition object and an execution object, the method further comprising:
configuring the conditional object and the execution object based on the JSON format; the condition object comprises a JSON array formed by field item parameters, operation item parameters and value item parameters, and the execution object comprises a JSON array formed by field item parameters and setting value item parameters.
3. The method of claim 2, wherein the rule checking the input data according to the key attribute comprises:
acquiring a rule with the highest priority according to the rule priority;
aiming at the currently obtained rule, determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included by the condition object in the rule;
analyzing the input data, and extracting key attributes corresponding to the key attribute format;
and if the value corresponding to the key attribute of the input data is consistent with the value of the key attribute in the condition object, determining that the rule passes the verification.
4. The method of claim 2, wherein the updating the input data according to the rule comprises:
determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included in the execution object in the rule;
analyzing the input data, and extracting key attributes corresponding to the key attribute format;
and updating the value of the key attribute of the input data according to the value of the key attribute in the condition object.
5. The method according to claim 2, wherein if the key attribute is not included in the input data, the obtaining the attribute value corresponding to the object by using the Java reflection mechanism comprises:
and extracting the object from the input data by using a Java reflection mechanism, and obtaining the attribute value of the object by using a Get/Set method of the object.
6. The method of any of claims 1-5, wherein the rules are cached in a distributed structure.
7. An apparatus for implementing a rules engine, comprising:
an input data receiving unit for receiving input data;
the rule matching unit is used for matching the input data in a rule set of the rule engine, wherein the rule set comprises a plurality of rules, and the rules are configured based on a JSON format;
a rule checking and executing unit, configured to, for the rule, if the input data includes a key attribute corresponding to the rule, perform rule checking on the input data according to the key attribute, and perform an update operation on the input data according to the rule, if the input data does not include the key attribute, extract an object from the input data, acquire an attribute value corresponding to the object by using a Java reflection mechanism, perform rule checking on the input data according to the object and the attribute value, and perform an update operation on the input data according to the rule; wherein, the rule checking and executing unit comprises:
and the reflection processing subunit is used for analyzing the field item parameters into the format of the object/attribute and acquiring the object from the input data, wherein the rule comprises the field item parameters.
8. The apparatus of claim 7, wherein the rule comprises a condition object and an execution object, the apparatus further comprising:
the object configuration unit is used for configuring the condition object and the execution object based on the JSON format; the condition object comprises a JSON array formed by field item parameters, operation item parameters and value item parameters, and the execution object comprises a JSON array formed by field item parameters and setting value item parameters.
9. The apparatus of claim 8, wherein the rule check and execution unit comprises:
the rule checking subunit is used for acquiring the rule with the highest priority according to the rule priority; aiming at the currently obtained rule, determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included by the condition object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and if the value corresponding to the key attribute of the input data is consistent with the value of the key attribute in the condition object, determining that the rule passes the verification.
10. The apparatus of claim 8, wherein the rule check and execution unit comprises:
the rule execution subunit is used for determining a key attribute format consisting of one parameter or a plurality of parameters according to each parameter included in an execution object in the rule; analyzing the input data, and extracting key attributes corresponding to the key attribute format; and updating the value of the key attribute of the input data according to the value of the key attribute in the condition object.
11. The apparatus of claim 8, wherein if the key attribute is not included in the input data, the reflection processing subunit is further configured to extract the object from the input data by using a Java reflection mechanism, and obtain an attribute value of the object by using a Get/Set method of the object.
12. The apparatus of any of claims 7-11, wherein the rules are cached in a distributed structure.
CN201710448421.4A 2017-06-14 2017-06-14 Method and device for implementing rule engine Active CN107220098B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710448421.4A CN107220098B (en) 2017-06-14 2017-06-14 Method and device for implementing rule engine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710448421.4A CN107220098B (en) 2017-06-14 2017-06-14 Method and device for implementing rule engine

Publications (2)

Publication Number Publication Date
CN107220098A CN107220098A (en) 2017-09-29
CN107220098B true CN107220098B (en) 2020-06-19

Family

ID=59948559

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710448421.4A Active CN107220098B (en) 2017-06-14 2017-06-14 Method and device for implementing rule engine

Country Status (1)

Country Link
CN (1) CN107220098B (en)

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107844291A (en) * 2017-10-23 2018-03-27 丹露成都网络技术有限公司 A kind of regular verification framework of high scalability
CN108628947B (en) * 2018-04-02 2022-07-15 创新先进技术有限公司 Business rule matching processing method, device and processing equipment
CN108920222B (en) * 2018-07-12 2021-12-03 北京京东金融科技控股有限公司 Business processing method and device based on rule engine
CN109271261B (en) * 2018-08-29 2022-03-11 中国建设银行股份有限公司 Event unified processing method, device and storage medium
CN109344170B (en) * 2018-09-04 2022-04-12 创新先进技术有限公司 Stream data processing method, system, electronic device and readable storage medium
CN110019651A (en) * 2019-03-01 2019-07-16 广州亚美信息科技有限公司 A kind of streaming regulation engine and business data processing method
CN111722863A (en) * 2020-06-23 2020-09-29 上海冰鉴信息科技有限公司 Method and device for updating wind control model
CN113377419B (en) * 2021-05-31 2024-07-26 同盾科技有限公司 Service processing method and device, readable storage medium and electronic equipment
CN113384899B (en) * 2021-07-05 2022-10-04 在线途游(北京)科技有限公司 Rule-based operation method and system
CN113535146A (en) * 2021-07-14 2021-10-22 浙江集享电子商务有限公司 Rule checking method and device, electronic device and storage medium
CN114238415B (en) * 2021-12-24 2024-06-25 四川新网银行股份有限公司 Method, system and medium for controlling real-time rule engine based on Flink

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20150019491A (en) * 2013-08-14 2015-02-25 광운대학교 산학협력단 Rule engine and implementation method of web-based process complaints forecasting and countermeasures derived system using user-driven case-based reasoning engine
CN106372778A (en) * 2016-08-23 2017-02-01 江苏亿科达科技发展有限公司 Vehicle scheduling system and method based on dynamic rule engine

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20150019491A (en) * 2013-08-14 2015-02-25 광운대학교 산학협력단 Rule engine and implementation method of web-based process complaints forecasting and countermeasures derived system using user-driven case-based reasoning engine
CN106372778A (en) * 2016-08-23 2017-02-01 江苏亿科达科技发展有限公司 Vehicle scheduling system and method based on dynamic rule engine

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
"中小型企业中业务规则管理系统开发与应用研究";刘超;《万方数据》;20110531;第3.2.2节,第3.4节 *
"银行下一代交互式系统中规则引擎平台的设计与实现";费腾;《中国优秀硕士学位论文全文数据库 信息科技辑》;20140315(第03期);第3.2节,第4.1-4.2节 *

Also Published As

Publication number Publication date
CN107220098A (en) 2017-09-29

Similar Documents

Publication Publication Date Title
CN107220098B (en) Method and device for implementing rule engine
US10664660B2 (en) Method and device for extracting entity relation based on deep learning, and server
US12001514B2 (en) Image classification modeling while maintaining data privacy compliance
US20190196672A1 (en) Visual effects system for "big data" analysis workflow editors, distribution platforms, execution engines, and management systems comprising same
JP5819995B2 (en) Machine learning method to identify independent tasks for parallel layout in web browser
US20220004705A1 (en) Personalization of content suggestions for document creation
CN104025068B (en) The Conflict solving of the CSS definition from multiple sources
US20160313874A1 (en) Visual effects system for "big data" analysis workflow editors, distribution platforms, execution engines, and management systems comprising same
US20200372088A1 (en) Recommending web api's and associated endpoints
US11263062B2 (en) API mashup exploration and recommendation
CN105183850A (en) Information querying method and device based on artificial intelligence
Ullah et al. Clone detection in 5G-enabled social IoT system using graph semantics and deep learning model
CN105683957B (en) Stylesheet speculative preloading
US11544467B2 (en) Systems and methods for identification of repetitive language in document using linguistic analysis and correction thereof
CN112612943A (en) Asynchronous processing framework-based data crawling method with automatic testing function
KR101372942B1 (en) Social media contents sharing apparatus and method
KR101157453B1 (en) System development apparatus and method for personalized service using contet-based recommendation method
Aranda-Corral et al. Reconciling knowledge in social tagging web services
CN111368206A (en) Service recommendation method, device, server and storage medium
US9189249B2 (en) Method for automatically defining icons
US20240176732A1 (en) Advanced application of model operations in energy
JP5600826B1 (en) Unstructured data processing system, unstructured data processing method and program
US20240202458A1 (en) Generating prompt recommendations for natural language processing tasks
Kapitsaki Creating and utilizing section-level Web service tags in service replaceability
JP2010501927A (en) Information terminal equipped with content search system

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
GR01 Patent grant
GR01 Patent grant