On 29 July 2010 13:24, Ana Rossello Busquet <a...@fotonik.dtu.dk> wrote:

> 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.
>
> 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.
>
This sounds like you plan to duplicate your information: once in a Jess
fact, and then in an object of your ontology. If this is just to achieve
persistency, OK; otherwise, why?

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.
>
> Indeed, by all means. The "user" is just another fact, with attributes.

> I have another question relating execution of rules. If a fact in my
> working memory changes, does jess fire the appropriate rules?
>
That's the whole idea :-)


> 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()?
>
> This depends when and how the fact is modified. If this occurs on the right
hand side of a rule that's being fired, it's obvious that you don't have to,
since the engine is still running.

If facts are added, modified, retracted from a Java application, you have
two choices:
(a) while(1){ change WW; run(); }
(b) Call engine.runUntilHalt() in one thread, and change WM in another
thread.

A final remark, which has been said before, by better men ;-)
Ontologies as you indicate by
(object (is-a 
http://www.simple-ontology.owl#Light<http://www.simple-ontology.owl/#Light>)
(http://www.simple-ontology.owl#hasState
?sl&:(eq<http://www.simple-ontology.owl/#hasState?sl&:%28eq>?sl
"Off")))
don't make for very good perfomance in Rete based reasoning systems, and
writing rules for them is a drag. Typically, Jess (and similar systems) work
best with JavaBean-like structures, where you can refer to sets of
attributes in a single pattern. Here, a Light would have, for instance, a
String id, a boolean state, another boolean inOrder, etc.

Cheers
-W

Reply via email to