首页 > 解决方案 > 如何添加全局变量来计算是或否响应的数量?

问题描述

我正在开发一个营养诊断系统,在该系统中向用户询问问题/症状,他们通过输入是或否来回答。我想跟踪是或否的计数并用它们进行计算。就像将是或否的计数存储在全局变量中一样。我已经有一个计算功能,但不确定如何从用户输入中捕获是或否。我是使用 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)
)

标签: clipsjess

解决方案


您已经展示了一个名为“menu::initialize”的规则,它插入了一些称为“问题”的事实。您需要一个规则来触发这些事实,然后该规则将包含一个将 1 添加到全局变量的语句。您可以在 Jess 手册中找到有关规则和使用全局变量的示例。

请不要指望 SO 上的某个人会为您做作业。


推荐阅读