I'm not sure what the initial set of facts is,butI'm assuming that you
have any number of potentially matching quadruplets
Translog - Product - ProductCategory - Category.
For good measure, I add
declare Superiors
cname: String
superiors: Set<String>
end
for defining, for each category, the more important categories: you'll
need to insert three static facts.
Doing away with all this non-declarative salience and flow you can now
make do with two rules:
rule "insert recommendation"
when
$tr: Translog($trpid : pid)
$p: Product(pid == $trpid, $pid : pid, $price : price, $brand : brand)
$pcat: ProductCategory(pid == $pid, $cid : cid)
$cat: Category(cid == $cid, cname == "pets", $cname : cname)
not ( Recommendation( $xname: cname )
and
Superiors( cname == $cname, superiors contains $xname ) )
then
insert(new Recommendation($pid, $price, $brand, $cname));
end
rule "remove low priorities"
when
$recomm: Recommendation( $cname: cname )
exists( Recommendation( $xname: cname )
and
Superiors( cname == $cname, superiors contains $xname ) )
then
retract($recomm)
end
And you may add a low-salience background rule for extracting the results.
rule "show recomms"
salience -999
when
$recomm : Recommendation()
then
System.out.println($recomm);
end
Untested!
-W
(Who eats "pets"????)
On 01/10/2012, raffi <christian.koehler(a)s2008.tu-chemnitz.de> wrote:
Hi,
I am novice in Drools. Up to my following problem nearly everything worked
fine for me.
In my case I thought mixing the two group mentioned is the right way, and
it
could be the right way if I use it in a correct way. The problem is that I
don't get a result.
...
rule "pets"
salience 20
ruleflow-group "pets"
activation-group "categories"
when
$tr : Translog($trpid : pid)
$p : Product(pid == $trpid, $pid : pid, $price : price, $brand :
brand)
$pcat : ProductCategory(pid == $pid, $cid : cid)
$cat : Category(cid == $cid, cname == "pets", $cname : cname)
then
insert(new Recommendation($pid, $price, $brand, $cname));
end
rule "remove everything except pets"
salience 19
ruleflow-group "pets"
when
$recomm : Recommendation((cname == "food") || (cname ==
"vegetable") ||
(cname == "drinks"))
then
retract($recomm)
end
rule "food"
salience 16
ruleflow-group "food"
activation-group "categories"
when
$tr : Translog($trpid : pid)
$p : Product(pid == $trpid, $pid : pid, $price : price, $brand :
brand)
$pcat : ProductCategory(pid == $pid, $cid : cid)
$cat : Category(cid == $cid, cname == "food", $cname : cname)
then
insert(new Recommendation($pid, $price, $brand, $cname));
end
rule "remove everything except food"
salience 15
ruleflow-group "food"
when
$recomm : Recommendation((cname == "vegetable") || (cname ==
"drinks"))
then
retract($recomm)
end
...
The idea is that I firstly add a new object (Recommendation) to my working
memory. After that I check if there are already existing
Recommendation-objects. Such objects that are from a less important
category
should now be removed. The priority attribute is the /cname/ (category
name). So in the end there can be more Recommendation objects of one
category but never of different categories.
I request the result in the following way (perhaps this is incorrect):
rule "show recomms"
salience 5
when
$recomm : Recommendation()
then
System.out.println($recomm);
end
So the result is an empty console, but with my test data there should be
two
Recommendation objects in my working memory after terminating.
--
View this message in context:
http://drools.46999.n3.nabble.com/mixing-activation-group-and-ruleflow-gr...
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