The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

gggg (4) [Avatar] Offline
#1
hi

I need to create a shadow fact without making a new object of my java bean class (as in the book example).
how can i do this please.
Thanks
ejfried (326) [Avatar] Offline
#2
Re: shadaw facts
You don't need to create a new instance, but you do need an instance from somewhere. Once you have the instance in a Jess variable, just pass it as an argument to (definstance) or (add). Alternatively, of course, you can do it from Java code using the jess.Rete class's APIs.
gggg (4) [Avatar] Offline
#3
Re: shadaw facts
Thank you
can you please provide an example with code on how to call the java bean methods without using new (new object). as I have passed my instance using definstance but couldn't call the methods.
ejfried (326) [Avatar] Offline
#4
Re: shadaw facts
Don't know what you mean, "couldn't call the methods" in this case. Can you show me an example of what you tried to do, even though it didn't work?
gggg (4) [Avatar] Offline
#5
Re: shadaw facts
I am trying to change a java bean class attribute (data member) using jess (for the same object instance of the class)

1. i tried to call the setter method of the attribute from jess (but i didn't know how)
2. i tried to change the attribute value using modify but it work only when i use constant but it dosent increase the ask slot(the bean attribute)

the code I used to add 1 to the ask attribute
the class: questines
the attribute: ask

(defrule ask_questine
?fact <- (questines (ask ?m))
=>
(modify ?fact (ask (+ ?m 1)))
)
it goes in a loop
ejfried (326) [Avatar] Offline
#6
Re: shadaw facts
It goes into a loop because the LHS of the rule still matches after the modify. Modern versions of Jess (i.e., Jess 7 and up) have the "no-loop" declaration for rules, which deals nicely with this kind of problem; just add it to your rule:

(defrule ask_questine
(declare (no-loop TRUE))
?fact <- (questines (ask ?m))
...
gggg (4) [Avatar] Offline
#7
Re: shadaw facts
Thank you, it worked.

I have another question regarding rules
i am using shadow facts that when changed from my program a rule will fire to assert fact. (this is working fine).
these facts are used in the rhs in many rules to provide user with recommendation.
the problem is that the recommendation rule fire several times.