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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -