Adding rules at run time

352 views
Skip to first unread message

Carlo Alberto Catarinicchia

unread,
Jan 10, 2014, 9:50:49 AM1/10/14
to no...@googlegroups.com
If I have correctly understood, when we compile the nools file the rete graph get generated. 
What I would like to do is to add rules after the graph has been generated (as far as I know rete allows that).
My scenario is a server with nools running, and I would like the client to be able to add custom rules to it.
Is there a way to do it in Nools?

Carlo

Douglas Martin

unread,
Jan 10, 2014, 1:00:47 PM1/10/14
to no...@googlegroups.com
You can use the flow.addRule after compile...however the new rule will not take affect until you get a new session.

Carlo Alberto Catarinicchia

unread,
Jan 16, 2014, 9:14:53 AM1/16/14
to no...@googlegroups.com
ok, so that means that to have it in effect, I should retrieve all the (basic, i.e. not asserted by rules) facts, create a new session and assert the fact in the new session, right?

snow crash

unread,
Feb 9, 2014, 7:24:31 AM2/9/14
to no...@googlegroups.com
Hi,

If the new Rule to add uses a Class that is always defined in the existing flow, how should I reference it ?

I tried :

try{
var noolsSource = "rule 'Measurement id is 123' {"
   + "   when {"
   + "     m : Measurement m.measurementId == '123';"
   + "   }"
   + "   then {"
   + "       console.info('Found Measurement with id of 123');"
   + "       retract(m);"
   + "   }"
   + "}";
var options = { "name":"test"};
options.name = "test";
var compiledRule = nools.compile(noolsSource, options), Measurement = flow.getDefined("Measurement");
flow.addRule(compiledRule);
} catch (err) {
   console.log("Error:", err)
}

But I got :  Error: [Error: Invalid class Measurement for rule Measurement id is 123]
Message has been deleted

snow crash

unread,
Feb 9, 2014, 10:08:47 AM2/9/14
to no...@googlegroups.com
Then, if I recopy the Class definition in the new Rule, it says :

Error: [TypeError: Object [object Object] has no method 'addRule']

on the flow object returned by initial nools.compile() 
Reply all
Reply to author
Forward
0 new messages