Summary of the invention
Inefficient problem for the solution rule coupling the invention provides a kind of rule matching method and device of realizing rule-based engine.
The invention provides a kind of rule matching method of realizing rule-based engine, described method comprises,
Receive the event that needs coupling, described event comprises at least one property value;
Judge whether to exist the default index entry of arbitrary rule to be matched and the coupling of the property value in the described event;
If so, then determine the corresponding target of the index entry rule to be matched of coupling;
The rule condition of described target rule to be matched and the property value in the described event are mated.
Preferably, describedly judge whether to exist before the default index entry of arbitrary rule to be matched and the property value in the described event mate, also comprise:
Sort according to the index entry set that default ordering rule is preset arbitrary described rule;
According to the order of each index entry after the ordering, the priority of each index entry in the index entry set is set.
Preferably, the described default index entry of arbitrary described rule the set according to default ordering rule sorts, and is specially;
The index entry of arbitrary relation of equality is set to the first priority;
With in the set of described index entry except other index entries of the index entry that is set to the first priority, sort according to the preset order rule;
Accordingly, described according to the order of each index entry after the ordering, the priority of each index entry in the index entry set is set, be specially:
According to the order of each index entry after the ordering, the priority except other index entries of the index entry that is set to the first priority is set in the index entry set.
Preferably, the described index entry and the property value in the described event that exist arbitrary rule to be matched to preset of judging whether mates, and is specially:
The quantity of supposing described rule to be matched is N, and then the index entry quantity of n rule to be matched is Mn, and described n is the natural number that is not more than N;
If the index entry quantity Mn of n rule equals 1, then judge an index entry coupling that whether has a property value and described n rule in the described event.
Preferably, the described index entry and the property value in the described event that exist arbitrary rule to be matched to preset of judging whether mates, and is specially:
Suppose that described regular quantity to be matched is N, then the index entry quantity of n rule to be matched is Mn, and described n is the natural number that is not more than N;
If the index entry quantity Mn of n rule, then judges the first priority index item coupling that whether has a property value and described n rule in the described event greater than 1;
If, then according to the corresponding relation of the first priority index item and the second priority index item, determine the second priority index item of described n rule, and judge whether have a property value and described the second priority index item coupling in the described event, the rest may be inferred, until judge whether to exist property value in the described event and the Mn priority index item coupling of described n rule.
The present invention also provides a kind of rule match device of realizing rule-based engine, and described device comprises:
Receiver module is used for receiving the event that needs coupling, and described event comprises at least one property value;
Judge module is used for judging whether to exist the property value of the default index entry of arbitrary rule to be matched and described event to mate;
The first determination module is used in the result of described judge module determining the corresponding target of the index entry rule to be matched of mating when being;
Matching module is used for the rule condition of described target rule to be matched and the property value of described event are mated.
Preferably, described device also comprises:
Order module is used for sorting according to the index entry set that default ordering rule is preset arbitrary described rule;
First arranges module, is used for the order according to each index entry after the ordering, and the priority of each index entry in the index entry set is set.
Preferably, described order module comprises:
Second arranges module, and the index entry that is used for arbitrary relation of equality is set to the first priority;
The ordering submodule, other index entries for described index entry being gathered except the index entry that is set to the first priority sort according to the preset order rule;
Accordingly, described first arranges module, specifically is used for:
According to the order of each index entry after the ordering in the described ordering submodule, the priority except other index entries of the index entry that is set to the first priority is set in the index entry set.
Preferably, described judge module comprises:
Obtain submodule, the quantity that is used for obtaining described rule to be matched is N, and the index entry quantity of n rule to be matched is Mn, and described n is the natural number that is not more than N;
Whether first judges submodule, is used under the index entry quantity Mn of n rule equals 1 situation, judge to exist a property value and a described n regular index entry to mate in the described event.
Preferably, described judge module comprises:
Obtain submodule, the quantity that is used for obtaining described rule to be matched is N, and the index entry quantity of n rule to be matched is Mn, and described n is the natural number that is not more than N;
The second judge module, be used for index entry quantity Mn n rule greater than 1 situation under, judge whether exist a property value and described n regular the first priority index item to mate in the described event;
The 3rd judges submodule, be used for the described second result who judges submodule when being, corresponding relation according to the first priority index item and the second priority index item, determine the second priority index item of described n rule, and judge whether have a property value and described the second priority index item coupling in the described event, the rest may be inferred, until judge whether to exist property value in the described event and the Mn priority index item coupling of described n rule.
Compared with prior art, the present invention at first receives the event that needs coupling, and described event comprises at least one property value; Judge whether to exist the default index entry of arbitrary rule to be matched and the coupling of the property value in the described event; If so, then determine the corresponding target of the index entry rule to be matched of coupling; The rule condition of described target rule to be matched and the property value in the described event are mated.The present invention utilizes index to need the screening of the rule of coupling, so that when the needs rule match, reduced the quantity that needs the rule of coupling, has improved the performance of regulation engine and the efficient of rule match.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present application, the technical scheme in the embodiment of the present application is clearly and completely described, obviously, described embodiment only is the application's part embodiment, rather than whole embodiment.Based on the embodiment among the application, those of ordinary skills are not making the every other embodiment that obtains under the creative work prerequisite, all belong to the scope of the application's protection.
Embodiment one,
With reference to figure 1, Fig. 1 is a kind of process flow diagram of realizing the rule matching method embodiment one of rule-based engine provided by the invention, and present embodiment specifically can comprise:
Step 101, reception need the event of coupling, and described event comprises at least one property value.
In this area, regulation engine is triggered by the reception event, and then calls corresponding rule and event is mated according to the event that receives, if the match is successful, then triggers all operations that this rule that the match is successful can trigger.Present embodiment has mainly solved the event how basis receives, and matches the rule corresponding with this event in the list of rules of storage strictly all rules.
In the present embodiment, the event that at first receive to need coupling, event can be understood as " operation of being identified by control ", and said event can comprise a property value herein, also can comprise a plurality of property values, any one property value of described event can be complementary with arbitrary rule condition of rule.For example, any one event can be " red eye is bright ", and " red eye is bright " is a property value of this event at this moment, can be complementary with the rule condition of arbitrary rule; Any one event also can be " red eye is bright; greensignal light is also bright simultaneously ", wherein, " red eye is bright " " greensignal light is also bright " is respectively the property value of this event, and the property value of above-mentioned two events also can be complementary with two rule conditions of arbitrary rule.
In the practical operation, receiving needs the mode of match event a lot, belongs to prior art, so do not repeat them here, the mode that receives simultaneously the event that needs coupling does not affect the enforcement of present embodiment.
Step 102, judge whether to exist the default index entry of arbitrary rule to be matched and the property value in the described event to mate, if so, then enter step 103.
In the present embodiment, each rule to be matched comprises some rule conditions, for example, if " red eye is bright; greensignal light is also bright simultaneously, then can trigger the A program and automatically move " is a rule, wherein, " red eye is bright " and " greensignal light is also bright " is respectively rule condition wherein, the operation that " triggering the A program moves automatically " is triggered when all being matched to merit for this regular rule condition.The rule condition that index entry arranges condition that meets of each rule to be matched is set to index entry at first in advance, for example, " red eye is bright " can be set to index entry.Secondly, the property value of the event that receives and the index entry of setting are complementary, for example, if the arbitrary property value in the event that receives is " red eye is bright ", this property value can the match is successful with " red eye is bright " this rule condition that is set to index entry so, in a word, if the property value in the event can mate with any one regular all set index entry, then enter step 103.
Concrete, index entry arranges condition can be the rule condition of " relation of equality ", for example, if a rule condition of certain rule is " age equals 20 ", then can be set to this regular index entry by " age equals 20 " this rule condition.
In the practical operation, each rule to be matched can arrange an index entry, also a plurality of index entries can be set.
Concrete, according to the index entry that condition setting is set of " relation of equality " during for " age equals 20 ", if a property value in the event that receives also is " age equals 20 ", so, " age equals 20 " as the event attribute value can be complementary with " age equals 20 " as index entry.
It should be noted that, in the practical operation, usually the first priority index item of rule index item is set to have " relation of equality " rule condition, and other priority index items except the first priority can be set to have the rule condition of " relation of equality " or " not waiting relation ".
The if there is no default index entry and the coupling of the property value in the described event of arbitrary rule to be matched, the then rule that is not complementary with the event of reception of explanation.
The corresponding target of the index entry rule to be matched of step 103, definite coupling.
In the present embodiment, the rule for the treatment of that all index entries are all mated all is used as target rule to be matched, for example, if the index entry of a rule is " age is greater than 18 ", another regular index entry is " age equals 20 " simultaneously, and a property value of the event that receives is " age is greater than 18 ", all can mate as " age is greater than 18 " of a property value of this event and " age is greater than 18 " and " age equals 20 " as the index entry of two rules respectively so, above-mentioned two rules that all index entries have been mated in explanation all are used as target rule to be matched, are used for the further coupling of the rule condition of subsequent step.
Step 104, the rule condition of described target rule to be matched and the property value in the described event are mated.
In the present embodiment, the rule condition of the target rule to be matched determined and property value in the event that receives are mated.
In the practical operation, present embodiment can be complementary the strictly all rules condition of the target rule to be matched determined and all properties value in the event that receives, if the match is successful fully, this target rule to be matched and the event matches success that receives is described, otherwise it fails to match.
In the practical operation, present embodiment also can be complementary other property values except the property value that the match is successful except in index entry other rule conditions partly that the match is successful and the event that receives of target rule to be matched, if the match is successful, this target rule to be matched and the event matches success that receives then are described, otherwise it fails to match.For example, the rule condition of supposing a rule is " red eye is bright " and " greensignal light is also bright ", if with above-mentioned " red eye is bright " this rule condition as index entry, a property value in the event that receives also is in the situation of " red eye is bright ", the match is successful can to determine the property value of event of " red eye is bright " this rule condition that is used as index entry of above-mentioned rule and reception, want to reach the purpose that above-mentioned rule is matched to merit this moment, only needs other property values with the rule of " greensignal light the is also bright " index that the match is successful except " red eye is bright " and the event that receives the match is successful to get final product.
Present embodiment at first receives the event that needs coupling, and described event comprises at least one property value, and next judges whether to exist the default index entry of arbitrary rule to be matched and the coupling of the property value in the described event; If so, then determine the corresponding target of the index entry rule to be matched of coupling, at last the rule condition of described target rule to be matched and the property value in the described event are mated.Compared with prior art, present embodiment utilizes index to need the screening of the rule of coupling, so that when the needs rule match, reduced the quantity that needs the rule of coupling, has improved the performance of regulation engine and the efficient of rule match.
Embodiment two,
With reference to figure 2, Fig. 2 is a kind of process flow diagram of realizing the rule matching method embodiment two of rule-based engine provided by the invention, because the step 201 among the embodiment two is identical with step 101, step 103~104 among the embodiment one with step 205~206, so no longer it is given unnecessary details in the present embodiment.
Present embodiment specifically can comprise:
Step 201, reception need the event of coupling, and described event comprises at least one property value.
Step 202, according to default ordering rule to arbitrary described rule default index entry set sort.
In the present embodiment, each regular index entry is set at first, the index entry that each is regular is respectively as its corresponding index entry set, next arranges the ordering rule with the index entry ordering, at last, according to the ordering rule that sets in advance, the index entry set that each rule is corresponding is sorted.
Concrete, the clooating sequence that sets in advance can be that the rule index item of " equaling relation " is set to high priority.For example, the rule condition of supposing a rule is " age equals 20 " and " height is greater than 170 ", then can be according to " equaling relation " for the index entry of high priority arrange condition, " age equals 20 " this rule condition that " equals relation " is set to index entry.
Step 203, according to the order of each index entry after the ordering, the priority of each index entry in the index entry set is set.
In the present embodiment, according to the ordering rule that is used for ordering that sets in advance to index entry set sort, according to the order of the index entry after the ordering, index entry is carried out the priority setting.
Concrete, the index entry that is arranged in the anterior locations of index entry order can be set to higher priority.For example, the set of the index entry of a rule comprises A, B, C and four index entries of D, and it is rear according to default ordering rule ordering to be the order of B, C, A, D, and priority orders is B>C>A>D so.
Concrete, the B index entry in the index entry set of above-mentioned rule is the first priority index item, the first priority index item can be the rule condition of " relation of equality ", introduces in detail in the step 102 in embodiment one, does not repeat them here.C, A in simultaneously this index entry set and D index entry be respectively second and third, the level Four index entry, they can be the rule condition of " relation of equality ", also can be the rule condition of " unequal " relation, for example, if a rule condition of certain rule is " age is greater than 20 ", then also " age is greater than 20 " can be set to second and third or level Four index entry of this rule.
Step 204, judge whether to exist the default index entry of arbitrary rule to be matched and the property value in the described event to mate, if so, then enter step 205.
In the present embodiment, the quantity of supposing rule to be matched is N, and then the index entry quantity of n rule to be matched is Mn, and this n is the natural number that is not more than N;
If the index entry quantity Mn of n rule equals 1, then judge an index entry coupling that whether has a property value and this n rule in the event that receives, if exist, then enter step 205.
If the index entry quantity Mn of n rule is greater than 1, then judge the first priority index item coupling that whether has a property value and described n rule in the event that receives, if exist, then according to the corresponding relation of the first priority index item and the second priority index item, determine the second priority index item of this n rule, and judge whether have a property value and described the second priority index item coupling in the event that receives, the rest may be inferred, until judge whether to exist a property value in the event of reception and the Mn priority index item coupling of described n rule.
It should be noted that N, n and Mn in the present embodiment all get natural number.
The below is take the rule of n=5, Mn=2 as example:
Reference table 1, table 2, table 1 are the corresponding table of index entry and the index entry of the second priority of the first priority of the 5th rule, and table 2 is the index entry of the second priority of the 5th rule and the corresponding table of rule sign.
The property value of supposing the event that regulation engine receives is " age equals 20 " " height is greater than 170 " and " undergraduate course educational background ".At first, by the processing of regulation engine, can be complementary as " age equals 20 " of the first priority and " age equals 20 " as a property value of the event that receives.Secondly, reference table 1, by the corresponding relation of the first priority index item and the second priority index item, the second priority index item corresponding to the first priority index item definite and that the match is successful.Again, in the event that judge to receive except with the first priority index item property value that the match is successful other property values whether have with the second priority index and be complementary mutually, just in time be complementary with the second priority index item " height is greater than 170 " of this rule for " height is greater than 170 " property value in the event of regulation engine reception this moment.At last, reference table 2 by the corresponding relation of the second priority index item with rule sign, is determined the rule sign corresponding with the second priority index item that the match is successful, and then is convenient to the definite of rule that the complete quilt in the subsequent step mates.
Table 1
The first priority index item |
The second priority index item |
Age equals 20 |
Height is greater than 170 |
Table 2
The second priority index item |
The rule sign |
Height is greater than 170 |
The 5th rule |
Wherein, for convenience's sake, only listed and can embody thought of the present invention and can realize minimum data of the present invention in table 1 and the table 2, in actual applications, those skilled in the art can expand data according to the version of table 1 and table 2.
Also need to prove, relate to the example of concrete data in the embodiment of the invention, all arrange in order to make things convenient for those skilled in the art to understand the present invention, these data can not be considered to being restriction of the present invention.
The corresponding target of the index entry rule to be matched of step 205, definite coupling.
Step 206, the rule condition of described target rule to be matched and the property value in the described event are mated.
Present embodiment sorts index entry, and the index after the utilization ordering needs the screening of the rule of coupling, so that when the needs rule match, reduced the quantity that needs the rule of coupling, has improved the performance of regulation engine and the efficient of rule match.
Embodiment three,
With reference to figure 3, Fig. 3 is a kind of structure drawing of device of realizing the rule match device embodiment three of rule-based engine provided by the invention, and present embodiment specifically can comprise:
Receiver module 301 is used for receiving the event that needs coupling, and described event comprises at least one property value;
Order module 302 is used for sorting according to the index entry set that default ordering rule is preset arbitrary described rule;
With reference to figure 4, Fig. 4 is the structural drawing of order module 302, and order module 302 specifically comprises:
Second arranges module 401, and the index entry that is used for arbitrary relation of equality is set to the first priority;
Ordering submodule 402, other index entries for described index entry being gathered except the index entry that is set to the first priority sort according to the preset order rule;
First arranges module 303, is used for the order according to each index entry after the ordering, and the priority of each index entry in the index entry set is set.
When described order module 302 adopts the structure of Fig. 4 to realize, described first arranges module 303 is used for order according to each index entry after described ordering submodule 402 orderings, and the priority except other index entries of the index entry that is set to the first priority is set in the index entry set.
Judge module 304 is used for judging whether to exist the property value of the default index entry of arbitrary rule to be matched and described event to mate;
With reference to figure 5, judge module 304 structural drawing that Fig. 5 equals at 1 o'clock for regular index entry quantity, described judge module 304 specifically comprises:
Obtaining submodule 501, is N for the quantity of obtaining described rule to be matched, and the index entry quantity of n rule to be matched is Mn;
Whether first judges submodule 502, is used under the index entry quantity Mn of n rule equals 1 situation, judge to exist a property value and a described n regular index entry to mate in the described event.
With reference to figure 6, Fig. 6 be the index entry quantity of rule greater than 1 o'clock judge module 304 structural drawing, described judge module 304 specifically comprises:
Obtaining submodule 501, is N for the quantity of obtaining described rule to be matched, and the index entry quantity of n rule to be matched is Mn;
The second judge module 601, be used for index entry quantity Mn n rule greater than 1 situation under, judge whether exist a property value and described n regular the first priority index item to mate in the described event;
The 3rd judges submodule 602, be used for the described second result who judges submodule when being, corresponding relation according to the first priority index item and the second priority index item, determine the second priority index item of described n rule, and judge whether have a property value and described the second priority index item coupling in the described event, the rest may be inferred, until judge whether to exist property value in the described event and the Mn priority index item coupling of described n rule.
The first determination module 305 is used in the result of described judge module determining the corresponding target of the index entry rule to be matched of mating when being;
Matching module 306 is used for the rule condition of described target rule to be matched and the property value of described event are mated.
Index after the present embodiment utilization ordering needs the screening of the rule of coupling, so that when the needs rule match, reduced the quantity that needs the rule of coupling, has improved the performance of regulation engine and the efficient of rule match.
For device embodiment, because it corresponds essentially to embodiment of the method, so relevant part gets final product referring to the part explanation of embodiment of the method.Device embodiment described above only is schematic, wherein said unit as the separating component explanation can or can not be physically to separate also, the parts that show as the unit can be or can not be physical locations also, namely can be positioned at a place, perhaps also can be distributed on a plurality of network element.Can select according to the actual needs wherein some or all of module to realize the purpose of present embodiment scheme.Those of ordinary skills namely can understand and implement in the situation of not paying creative work.
Need to prove, in this article, relational terms such as the first and second grades only is used for an entity or operation are made a distinction with another entity or operation, and not necessarily requires or hint and have the relation of any this reality or sequentially between these entities or the operation.And, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thereby not only comprise those key elements so that comprise process, method, article or the equipment of a series of key elements, but also comprise other key elements of clearly not listing, or also be included as the intrinsic key element of this process, method, article or equipment.Do not having in the situation of more restrictions, the key element that is limited by statement " comprising ... ", and be not precluded within process, method, article or the equipment that comprises described key element and also have other identical element.
More than rule matching method and the device of the rule-based engine of realization that the embodiment of the invention is provided be described in detail, used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.