Domanda

In Drools, is it possible to combine rules in a DRL file somehow once they are defined. For example, if I have two rules like this:

rule A
 // definition
end

rule B
 // definition
end

Is it possible to have another rule that achieves logic like: A or B?

È stato utile?

Soluzione

Two rules A and B are the logical equivalent of A or B (not xor).

You cannot refer to another rule, but you can define queries and call two (or more) queries within the same LHS condition.

However, the overall pattern of your logic might make an entirely different approach more advisable, where matches of different rules are made tangible by insertion as derived facts, known as truth maintenance.

rule A when ... then
  insertLogical( new Fired( "A" ) );
end
rule B when ... then
  insertLogical( new Fired( "B" ) );
end
rule AorB when
  Fired( rule == "A" || rule == "B" ) // other patterns for other combinations, e.g. &&
then
   ...
end

More details would be necessary for precise advice.

Altri suggerimenti

You can also look at activation-group, which will fire one rule and cancel the others.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top