Anyway, I can experiment nicely with my hack, and this would be a good
starting point for investigating what kind of support users might need.
Given the definition of a rule set:
new RuleSet( "com.sample", "car" )
.add(new BasicPattern( "car", Car.class ) )
.addSplit( "colour == 'red', price < 2000, horsepower >= 150, abs
== true" );
and Car facts
new Car( "HotRod 1", "red", 1200, 160, true );
new Car( "HotRod 2", "red", 1100, 140, true );
new Car( "HotRod 3", "black", 3000, 100, false );
You might add evaluation rules such as the ones below, likely examples
for what users might require:
rule "success, or near miss"
when
$c: Collector( "car"; failureCount <= 1 )
then
System.out.println( "Candidate for the car I want: " + $c.get(
"car" ) );
$c.missing();
end
------------------------------
Candidate for the car I want: Car [id = HotRod 1, colour=red,
price=1200, horsepower=160, abs=true]
Candidate for the car I want: Car [id = HotRod 2, colour=red,
price=1100, horsepower=140, abs=true]
missed: horsepower >= 150 in Car, values: getHorsepower() = 140
-------------------------------
rule "no chance"
when
$c: Collector( "car"; successCount == 0 )
then
System.out.println( "Absolutely not: " + $c.get( "car" ) );
$c.missing();
end
-------------------------------
Absolutely not: Car [id = HotRod 3, colour=black, price=3000,
horsepower=100, abs=false]
missed: colour == 'red' in Car, values: getColour() = black
missed: price < 2000 in Car, values: getPrice() = 3000
missed: horsepower >= 150 in Car, values: getHorsepower() = 100
missed: abs == true in Car, values: isAbs() = false
-------------------------------
rule "collect good offers"
when
accumulate( $c: Collector( "car"; failureCount <= 1 ), $list:
collectList( $c.get("car") ) )
then
System.out.println( "Summary:" );
for( Object object: $list ) System.out.println( (Car)object );
end
-------------------------------
Summary:
Car [id = HotRod 2, colour=red, price=1100, horsepower=140, abs=true]
Car [id = HotRod 1, colour=red, price=1200, horsepower=160, abs=true]
-------------------------------
On 04/02/2013, Davide Sottara <dsotty(a)gmail.com> wrote:
Hi Wolfgang,
We're more on the same page than it might seem... :)
The new - experimental - syntax was reviewed several times to make sure it
was semantically
equivalent (and thus replaceable) to an appropriate set of rules extending
each other
(see the links I posted previously), which in this case would be exactly
the
ones you recommended.
It is just meant to be more compact - possibly facilitating its generation
by builders or templates -
but at the same time it supports a built-in implementation.
It is however more general than this use case, which could use some extra
automation as far as the
management of the evaluations is concerned.
Or, none at all, letting users adopt whatever solution is more appropriate.
You suggested a more general CollectorFact, I used the more granular
Fulfill/Viol...
from a certain perspective they're equivalent, and definitely not the only
option :)
Davide
--
View this message in context:
http://drools.46999.n3.nabble.com/rules-users-How-to-track-constraint-tru...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users