You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jess诊断GUI应用仅显示首个问题,答案未记录的故障排查

Hey there! Let's dig into why your Jess diagnostic GUI is stuck on the first question and not tracking answers properly. I've spotted several key issues in your simplified code that are causing these problems:

1. Uncontrolled Initial Question Assertions

Your four questions_basique_X rules all have (declare (auto-focus TRUE)) and no triggering conditions. That means when the engine starts, all four rules fire at the same time, asserting (ask age), (ask poids), and duplicate (ask symptome_majeur_1) facts immediately. This overwhelms the ask::ask-question-by-id rule, which can only handle one question at a time—leaving subsequent questions blocked.

Fix: Make basic questions fire in sequence, each relying on the previous question's answer existing:

(defrule MAIN::questions_basique_1
  (declare (auto-focus TRUE))
  ;; Trigger only if no basic question answers exist yet
  (not (MAIN::reponses (ident ?&:(member ?id (age poids symptome_majeur_1)))))
  =>
  (assert (ask age)))

(defrule MAIN::questions_basique_2
  (declare (auto-focus TRUE))
  ;; Trigger only after age is answered
  (MAIN::reponses (ident age))
  (not (MAIN::reponses (ident poids)))
  =>
  (assert (ask poids)))

(defrule MAIN::questions_basique_3
  (declare (auto-focus TRUE))
  ;; Trigger only after poids is answered
  (MAIN::reponses (ident poids))
  (not (MAIN::reponses (ident symptome_majeur_1)))
  =>
  (assert (ask symptome_majeur_1)))

(Note: Your original questions_basique_4 duplicates symptome_majeur_1—update it to the next unique question ID.)

2. Incomplete collect-user-input Rule

Your ask::collect-user-input rule cuts off before critical steps that close the loop on user input:

  • It doesn't remove the processed ask and user-input facts
  • It doesn't trigger the engine to run subsequent rules after saving the answer

Fix the full rule:

(defrule ask::collect-user-input
  (declare (auto-focus TRUE))
  (MAIN::questions (ident ?id) (texte ?text) (type ?type)(valid $?valid))
  (not (MAIN::reponses (ident ?id)))
  ?user <- (user-input ?input)
  ?ask <- (MAIN::ask ?id)
  =>
  (if (is-of-type ?input ?type ?valid) then
    ;; Save valid answer
    (assert (MAIN::reponses (ident ?id) (texte ?input)))
    ;; Clean up processed facts
    (retract ?ask ?user)
    ;; Kick off next rules
    ((engine) run)
  else
    ;; Retry invalid input (optional: add error message here)
    (ask-patient ?text ?type ?valid)
    (retract ?user)
  ))

3. Missing user-input Fact Trigger

Your GUI code (not fully shown) needs to assert a (user-input ?answer) fact when the user clicks an OK button. This is how the Jess engine gets notified of user input. For example, add this to your button's ActionListener:

// Example for text input OK button
?*afield-ok*.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        String input = ?*afield*.getText();
        // Send input to Jess engine
        engine.assertString("(user-input \"" + input + "\")");
    }
});

4. Duplicate Rules & Typo Checks

  • Remove the duplicate questions_basique_4 rule that repeats symptome_majeur_1
  • Fix inconsistent French spellings (e.g., dypn茅e_brute vs dyspn茅)—mismatched IDs will break rule matching

Final Testing Steps

  1. Start with (reset) (safe since you set (set-reset-globals FALSE))
  2. Run (run) to trigger the first question
  3. Verify that each valid answer clears the current ask fact and triggers the next rule in sequence

内容的提问来源于stack exchange,提问作者Nadh Hely

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:03:32