0

I am having a serious trouble with the rule engine Jess. The problem that I am facing is with the Conditional Element Accumulate. I am trying to write a rule which gives me a list of words - according to some criteria - from my working memory but it shows me all the phases of the list - first an empty list then a list with one element and it goes on- which it does so by firing again and again the same rule. But I know and sure that the working memory does not change while this rule fires.

And also strangely I wrote the same rule hours ago and it was giving, as a result, only one list which has more than one elements.

Do you have any suggestions on what I am doing wrong?

Please help! Here is the code :

(defrule show-me
  (declare  (salience -11)
           (no-loop TRUE))
  ?my-list <- (accumulate (bind ?list (new java.util.ArrayList)) ;initializer
                          (?list add ?sWord) ; action 
                          ?list ;result
                          (ourObject (sourceWord ?sWord) ; CE
                                     {complementType == COMPLEMENTO-OGGETTO-PARTITIVO}))
=>
  (printout t "complementType" (?my-list toString) crlf))

And this is the result that I am getting :

complementType[ un  ,  po  ,  di  ,  acqua  ,  tua  ]
complementType[ un  ,  po  ,  acqua  ,  tua  ]
complementType[ un  ,  acqua  ,  tua  ]
complementType[ acqua  ,  tua  ]
complementType[ acqua  ]
complementType[]

And I need only this :

complementType[ un  ,  po  ,  di  ,  acqua  ,  tua  ]

p.s. Sorry for the code appearance but it did not permit me to paste it as it is.

laune
  • 31,114
  • 3
  • 29
  • 42
Kadir GUNEL
  • 97
  • 1
  • 4

1 Answers1

0

Most probably you are inserting ourObject facts while the engine is running. One way would be to call run in one thread (which blocks) and then insert facts in another thread. This will create activations immediately, which will then be executed in reverse order, since conflict resolution prefers newer activations over older ones.

If you execute either of these two insertion variants. the rule fires as expected, once.

;;(deffacts facts
;;  (ourObject (sourceWord un)(type X))
;;  (ourObject (sourceWord po)(type X))
;;  (ourObject (sourceWord di)(type X))
;;  (ourObject (sourceWord acqua)(type X)))

(reset)

(assert (ourObject (sourceWord un)(type X)))
(assert (ourObject (sourceWord po)(type X)))
(assert (ourObject (sourceWord di)(type X)))
(assert (ourObject (sourceWord acqua)(type X)))

(run)
laune
  • 31,114
  • 3
  • 29
  • 42
  • Hello, thank you for your help (again). I was suspicious about something bizarre is going. Now, after you wrote, I checked the .clp file and I did some error testing on that file. Since I am writing this program with Java I need to import some classes via using the import key. And shockingly even though I convert the imported packages to comments -;- I can still have facts in the working memory which is really strange because I have different rule engine objects and each object has different .clp script. Do you have any idea ? Am I doing something wrong? – Kadir GUNEL Aug 27 '14 at 20:53
  • Yes, you are right. First I am doing some changes on the existing facts then I want to get some of them by using the CE accumulate. But what do you mean by calling the run in one thread and insert facts in another? How can I do it? – Kadir GUNEL Aug 27 '14 at 22:23
  • Not seeing any of that code, your verbal descriptions don't paint a clear picture for me. But I hope that the accumulate question has been resolved. I don't really see when and how you insert facts and when and how you call run. - Calling run in one thread and inserting in another thread: this should be pretty straightforward, although I don't think you should do it if you can make do without. – laune Aug 28 '14 at 16:20