define facts in the js file

260 views
Skip to first unread message

abderrahmen gharsallah

unread,
Mar 29, 2015, 2:25:16 PM3/29/15
to no...@googlegroups.com
I didn't make it to define my facts in the js file can any one help me here is a simple example and i keep getting : invalid class

var nools = require ('nools');
var ruleFilePath = __dirname + "/rules/helloworld-v1.nools";
var flow = nools.compile(ruleFilePath,
                       { name : "hello" ,
                       //class should be available to the rules
                       define : {House : House },
  scope: {
test: test,
test2:test2
  }
                     });
var userid=10;
var boxid=101;
var zwave = 14;

var Trucker1 = new Trucker(userid, boxid, zwave);

  var session1 = flow.getSession(Trucker1)

session1.match();

var Trucker = function(userid, boxid, zwave){
         this.userid = userid; 
         this.boxid = boxid;
         this.zwave = zwave;
     }

     
function test () {
// body...
console.log("function test1 executed");

}
function test2 () {
// body...

console.log("test2 executed ");

}



and in the dsl file:


 
//if message is undefined regular expression
rule Hello {
    when {
        h :House h.userid==10; 
   h :House h.boxid==101; 
    }
    then {
test();
    }
}

rule test {
    when {
        m : Message m.text =~ /^hello\sworld$/;
        h :House h.userid==10; 
   h :House h.zwave==14; 
    }
    then {
test2();
    }
}

Reply all
Reply to author
Forward
0 new messages