Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Errors in running Jess expert system .clp file

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to Jess the rule based system in Java and need some assistance if possible. I am trying to run an program in Jess the expert system which analyses risk of developing a particular disease. There are no compilation issues with my .clp file, but when the program runs it does not fully complete. Users are asked questions and answers are stored in Jess, but no calculations are performed and results are not displayed to users yet.

I am currently trying to get Jess to store the bmi value derived from the entered height and weight by a user, but I get an error displayed in the console. I will display some code below if anyone can help;

some of the clp file code:



I have coded (watch all) into the .clp file to list all activations etc on the console for disgnostics.

The error code on the console screen:




In the error code above the slot 'user bmi' is at first asserted correctly to value of 29 but just after Jess reports an error in executing bmi to the value of the binded variable ?bmi.
Why is binding a value then assigning it to a slot not working?
I need the bmi stored in the user bmi slot so that corresponding rules can be fired which match the bmi value. An example of one of my current defrules is;




This current program I am working on is heavily adapted from a .clp file from the book 'Jess in Action' named Taxes.clp

Any help in getting my program to display the results to users will be appreciated.
 
Lalith Phigera
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have since solved the issue I posted above and worked out a method to store the calculated bmi in a slot. I omitted the bind and directly asserted the bmi calculation into the relavant slot. See code below;



I am still though unable to run the program completely. I get no errors but a lot of rules I want to fire do not do so. I have seperated my file into different defmodules namely startup, interview, calculate and report. All the desired rules fire in defmodules startup and interview but not in calculate and report? I need the appropriate rules to fire in calculate and report defmodules for users to get outputted results. The rules are meant to fire according to the facts asserted via user answers.
I have copied the entire .clp file I am working with below if anyone can help to get the program to run fully, thanks you.





If anyone needs the console code from running the file above with (watch all) activated, I can post this code.

I'm aware that many of the user facts have not been asserted in the above .clp code, such as user alcohol, disease, etc. I ommitted their assertion as I am planning to use the answer slot 'text' direct fact data.

User facts could otherwise be asserted as so;



The following is a list of all the facts in Jess MAIN module when the .clp file is run:



Once again I now need the relavant rules to fire in the calculate and report defmodules so results can be outputted to a user, what to I need to improve or change in the code?
The code in the above file is still work in progress and I am aware that maybe many changes to the code is necessary.

Many thanks for any help.



 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The immediate reason why none of the "calculate" or "report" rules fire is that every one of them matches an "analysis" pattern on the left-hand-side, but no code anywhere asserts any "analysis" facts; therefore none of those rules are ever activated.

I do see where a lot of rules in those modules attempt to call an (undefined) function named "analysis", like this:



Maybe that last line should be



That wouldn't quite fix the logic though, because as I said, it looks every rule that creates an analysis fact requires one to previously exist, and none do. Also, you'd have to have bound "?t" on the rule left-hand-side first; the syntax you were using is a pattern-matching syntax valid only on rule left-hand-sides. Also note that in a few places you use a syntax like (analysis {total + 1}); that's also not allowed on right-hand-sides.
 
Lalith Phigera
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ernest,

Many thanks for your reply, I have since been able to get rules to activate in the interview, calculate and report defmodules. This is progress but the output I want for users is still not being displayed. Rules do activate but only some fire. I do not understand why serveral of the rules list 'activation' but do not fire? such as in the 'watch all' code below.



I have tried to take on our comments in your reply and have edited by code.

If I briefly tell you what I want the program to do this might lead to a better understanding. I want answers read from a user to be utalised in rules to output a basic analysis. I want to analysis symptoms of a user such as 'jaundice' to give a likelihood of developing cirrhosis. The idea of the program is basic enough, for each rule that fires a number is added to a total signifying the importance of having a paticular symptom. Additionally for each symptom or risk factor the user has, a short text is added to a list (for example "You have the liver disease symptom of jaundice.") as in my code to the multislot 'reasons' in the analysis deftemplate. For each symptom the user has a number such as 1 or 2 is added to the 'total' numeric slot in the analysis deftemplate. You said in your reply here that a lot of my rules attempt to call a function 'analysis' but this is simply a deftemplate name within my code and 'total' is the numeric slot I wish to add to as rules fire.

Once the 'total' and 'reasons' slots have been accordingly modified, the total is used to output a risk status to the user such as low, moderate or high and the multislot 'reasons' is printed out for the user to see a list of reasons as to why they have been assigned their level of risk. The rules in the defmodule 'report' are meant to print out risk status and list of reasons but they do not work as of yet. The rules in the report module are activated but do not fire. I think maybe I have wrote the code for rules in the report module somewhat incorrectly, I wonder if you can tell me where they would need to be changed.

One other problem is if I answer yes to all the symptoms then I seem to get a continues loop where rules are endlessly activated and facts seems to continuesly multiply such as f-25 up to f-200 on-going. The other error is that the slot 'total' is only added to once from what I see and not continuesly to get to a number such as 7 or 12.

Sorry for including all my code below, but I think it will help you understand what I have changed so far and the code is not that long. My current code is pasted below:



Many thanks if you can answer my questions and I appreciate your help kind Sir.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic