Search code examples
clipsjess

How do I add a global variable to count the number of yes or no responses?


I am working on a nutrition diagnosis system where users are asked questions/symptoms and they respond by entering yes or no. I want to track the count of yes or no and make calculations with them. Like store the count of yes or no in global variables. I already have a function for the calculation but unsure how to capture the yes or no from the user input. I am new to using Jess rules. Below I have added codes of the working rule.

(defrule menu::initialize
  (diagnosis)
  =>
  (assert 

  (question (ident q21) (text "Does the child's hair tend to be slight? (Yes or No)") (type yes-no))

  (question (ident q22) (text "Does the child's hair tend to be reddish? (Yes or No)") (type yes-no))

  (question (ident q23) (text "Is the child often affected by ISPA/ TBC? (Yes or No)") (type yes-no))

  (question (ident q24) (text "Does the child's hair tend to be easily falls off? (Yes or No)") (type yes-no))

  (question (ident q25) (text "Is there any abnormality on the child's complexion? (Yes or No)") (type yes-no))

  (question (ident q26) (text "Is there any swelling on the child's face? (Yes or No)") (type yes-no))

  )
  (menu::init)
)

Solution

  • You have shown a rule called "menu::initialize" which inserts some facts called "question". You need a rule to fire on these facts, and this rule would then contain a statement to add 1 to a global variable. You can find examples for rules and for using global variables in the Jess manual.

    Please don't expect someone on SO to do your homework for you.