Re: JESS: How to use a Userfunction returning boolean in a LHS of a Jess rule
"Ana Rossello Busquet" <[email protected]>
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <25743_1280406371_o6TCOAaN027018_401DFAA0C5795B4AAB1B80DD400C39AD21016E72F7@WINEXCHANGE4.win.dtu.dk> |
Hi,
First of all thanks for your replies.
I am designing a java application for energy management. I have an ontology, which I use to save information about the devices (what commands a device has, what is its state (on, off, open close, etc.) among other information. Then I want to design some rules implementing some energy management strategy.
A simple example:
If there is enough sun light and the light is on,
Then turn off the light.
Turn off the light: Two things have to be done here: 1- change the working memory of jess (change the state of the light to off) and 2- call a java function that modifies my ontology (change the state of the light to off) and a command will be sent to the light to turn it off.
Another example (this is how I wanted to use the call to the function):
If there is enough sun light and the light is on and userWantstoSave(),
Then turn off the light.
userWantstoSave() would be my java function returning a Boolean. This function simply represents if the user wants these rule to turn off the light or not. However, for what you are saying I should put this Boolean in a fact and then change the fact whenever it is necessary.
In my last email I use this rule:
(defrule trueFunction
"True Function"
(test (returnTrue))
=>
((System.out) println "True"))
I used this as an example as I thought it would be better to keep it as simple as possible.
I have another question relating execution of rules. If a fact in my working memory changes, does jess fire the appropriate rules?
For example I have the following two rules:
(defrule Rule-1
(object (is-a http://www.simple-ontology.owl#Light) (http://www.simple-ontology.owl#hasState ?sl&:(eq ?sl "On")))
=>
((System.out) println "The light is On"))
(defrule Rule-2
(object (is-a http://www.simple-ontology.owl#Light) (http://www.simple-ontology.owl#hasState ?sl&:(eq ?sl "Off")))
=>
((System.out) println "The light is Off"))
And my java code is:
Rete engine = new Rete();
engine.addUserpackage(new JessTabFunctions());
engine.executeCommand("(load-project file:/M:/MyJessTest/osgi.myjesstest.test/simple-owl.pprj)");
Batch.batch("myrules.clp", engine);
engine.run();
engine.executeCommand(" (slot-replace$ http://www.simple-ontology.owl#light1 http://www.simple-ontology.owl#hasState 1 1 On)");
//calling run again
engine.run();
light1 has initial state Off. When I run my java application, in the console I can see that the message "the light is Off" is printed as it should be. Then I change the state of light1 to On. However, the message "the light is On" does not get printed unless I call engine.run() for second time. Does this means that everytime I modify I fact from the working memory I have to also do engine.run()?
Thanks!
Ana