First of all, query results are pointers to internal data structures, and as such they are transient things. You're intended to consume them immediately. In the code above I see you calling Rete.run()
and asserting a number of facts before iterating through a previously-executed query's results. Don't do that! After running a query, you should immediately extract the results you need into a collection of some kind (a List
or Map
) and then pass that collection around as needed.
Secondly, we would need to see the *.clp
file to diagnose this, but I don't think we should -- I'd rather help you to do that yourself. One of four things must be going wrong here:
- The way you're using the query result is breaking things;
- The facts you think are being asserted here aren't correct;
- The rules aren't producing the results you expect;
- The query
all-analysis
doesn't return the results you expect.
What you need to do is disprove each of these in turn until you find the problem. First, modify the program so that query results are only used immediately after use, and definitely don't assert facts as you iterate through them!
Second, use a Jess facility (like the save-facts
function) to dump the contents of working memory after you assert the new facts here and check them.
Third, use save-facts
again after the run()
, again, to check that the answers you're looking for actually exist.
Finally, if your final query still doesn't give the right results, then it must be incorrect, so have a closer look at it!
Good luck tracking down your problem.