I don't see how these two loops should result in different facts in WM unless there
are other rules besides the one you have shown.

Why do you expect more that one result from the first (!) version of
"recomm for slot 1"? Are there several recommendations with the same
maximum recommValue?

rule "filter products with category and brand for slot 1" isn't optimal. The
patterns should be rearranged for earliest possible blocking of evaluation.

rule "filter products with category and brand for slot 1"
        salience 20
        activation-group "productfilter slot 1"
        when
                Translog($pid : itemID, $uid : userID)
                Product(pid == $pid, brand != "", $price : netUnitPrice, $brand : brand)
                FilterCriteria(brands contains $brand)
                ProductCategory(pid == $pid, $cid : cid, $root : root)
                FilterCriteria(categories_slot1 contains $root) // stop here if the root needs filtering
                not Recommendation(pid == $pid, slot == 1, uid == $uid)
                Category(cid == $cid, $cname : cname) // just needed for the insert
        then
              insert(new Recommendation($pid, $price, $brand, $cname, $cid, (byte)1, $root, $uid));
        end


Regarding your rule "exclude products", it should probably be run before you insert any
Translog facts, with a separate fireAllRules() call. Then you don't need salience.

Or you can include the conditions in the Product pattern of
rule "filter products with category and brand for slot 1"

-W


On 3 December 2012 09:59, raffi <christian.koehler@s2008.tu-chemnitz.de> wrote:
Hi.

I localized the problem. The following lines lead to the described behavior:

/for (Translog tr : translog) {
        if (tr.getTransType() == 1 && !(tr.getUserID().compareTo("null") == 0)) {
                FactHandle tr_insert = ksession.insert(tr);
                ksession.fireAllRules();
                ksession.retract(tr_insert);
        }
}/

If I run the program with the changed lines
/for (Translog tr : translog) {
        if (tr.getTransType() == 1 && !(tr.getUserID().compareTo("null") == 0)) {
                ksession.insert(tr);
        }
}
ksession.fireAllRules();/

it doesn't work as I expect it. I didn't change the according rule
/rule "filter products with category and brand for slot 1"
        salience 20
        activation-group "productfilter slot 1"
        when
                Translog($pid : itemID, $uid : userID)
                Product(pid == $pid, brand != "", $price : netUnitPrice,
$brand : brand)
                ProductCategory(pid == $pid, $cid : cid, $root : root)
                Category(cid == $cid, $cname : cname)
                FilterCriteria(categories_slot1 contains $root)
                FilterCriteria(brands contains $brand)
                not Recommendation(pid == $pid, slot == 1, uid == $uid)
        then
                insert(new Recommendation($pid, $price, $brand, $cname, $cid, (byte)1,
$root, $uid));
end/

In the end I show all Recommendation-facts in the console using a query.
There should be at least 4, grouped by uid (userid). But with the corrected
lines I only get one Recommendation-fact.
/query "recomm for slot 1"
        $recomm_max     : Recommendation(slot == 1, $recomm_value : recommValue, $uid :
uid)
        not Recommendation(slot == 1, recommValue > $recomm_value, uid == $uid)
end/

The same applies for the query, without grouping by uid:
/query "recomm for slot 1"
        $recomm_max     : Recommendation(slot == 1)
end/

I chose the first (wrong) solution, with retracting the Translog-facts
directly after firing, because it is transaction data. For my test there are
only a few lines, but in the productive scenario there are at least 100.000
records to insert.

Regards...



--
View this message in context: http://drools.46999.n3.nabble.com/Different-results-with-same-fact-base-tp4021000p4021056.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users