如何添加一个全局变量来计算是或否响应的数量?
How do I add a global variable to count the number of yes or no responses?
我正在开发一个营养诊断系统,用户会被询问 questions/symptoms 并且他们通过输入是或否来回答。我想跟踪是或否的计数并用它们进行计算。就像在全局变量中存储是或否的计数。我已经有一个计算函数,但不确定如何从用户输入中捕获是或否。我不熟悉使用 Jess 规则。下面我添加了工作规则的代码。
(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)
)
您展示了一个名为 "menu::initialize" 的规则,其中插入了一些名为 "question" 的事实。您需要一个规则来触发这些事实,然后该规则将包含一个将全局变量加 1 的语句。您可以在 Jess 手册中找到有关规则和使用全局变量的示例。
请不要指望 SO 上有人为您做功课。
我实施了上面建议的解决方案并得到了我想要的东西。
我的以下实现:.. 可能不是最佳解决方案,但它有效。谢谢 :D
(defrule get-y21
"Add 1 to global variable for every yes answer from question21"
(answer (ident q21) (text yes ))
=>
(bind ?*countyes* (+ ?*countyes* 1))
)
(defrule get-n21
"Add 1 to global variable for every no answer from question21 "
(answer (ident q21) (text no ))
=>
(bind ?*countno* (+ ?*countno* 1))
)
我正在开发一个营养诊断系统,用户会被询问 questions/symptoms 并且他们通过输入是或否来回答。我想跟踪是或否的计数并用它们进行计算。就像在全局变量中存储是或否的计数。我已经有一个计算函数,但不确定如何从用户输入中捕获是或否。我不熟悉使用 Jess 规则。下面我添加了工作规则的代码。
(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)
)
您展示了一个名为 "menu::initialize" 的规则,其中插入了一些名为 "question" 的事实。您需要一个规则来触发这些事实,然后该规则将包含一个将全局变量加 1 的语句。您可以在 Jess 手册中找到有关规则和使用全局变量的示例。
请不要指望 SO 上有人为您做功课。
我实施了上面建议的解决方案并得到了我想要的东西。
我的以下实现:.. 可能不是最佳解决方案,但它有效。谢谢 :D
(defrule get-y21
"Add 1 to global variable for every yes answer from question21"
(answer (ident q21) (text yes ))
=>
(bind ?*countyes* (+ ?*countyes* 1))
)
(defrule get-n21
"Add 1 to global variable for every no answer from question21 "
(answer (ident q21) (text no ))
=>
(bind ?*countno* (+ ?*countno* 1))
)