JESS vs DROOLS : Backward chaining -
i'm trying replace jess drools backward chaining rule engine in our project. looking simple examples how backward chaining done drools. interestingly, there's 1 same example on every site (which don't how it's bc let's forget now).
very trivial example of bc in jess:
//q fact template slot named 'n' //when there's q n==8 print //i need q n==8 fire rule insert myself! (deftemplate q (slot n)) (do-backward-chaining q) (defrule printq (q (n 8)) => (printout t "n eight! yeah!" crlf)) (defrule ineedn8 (need-q (n 8)) => (assert (q (n 8)))) (reset) (run 1) //fires printq , prints console...
equivalent in drools:
package com.example; declare q n : int end rule "print q" when q(n == 8) system.out.println("n 8 drools!"); end //i'm lost here! help!
how can achieve same behaviour drools?
in drools, general idea of bc use queries. in addition rule "print q" need:
query noq( int $num ) goal(num==$num) , not q(num == $num) end rule goal when goal( $n: num ) noq($n;) q q = new q($n); insert( q ); end rule go when insert( new goal( 8 ) ); end
there no way instruct drools detect missing fact itself; have provide goal , queries "bridge gap".
Comments
Post a Comment