2017-09-24 67 views
0

我想讓一個人過敏,然後通過過敏來分裂過敏來斷言每個人。爲此,我使用do-backward-chaining,assert-stringreadline將閱讀列表分解爲其元素

(do-backward-chaining allergies) 

(defrule ask-allergies 
    (need-allergies nil) 
    => 
    (printout t "Tell me your allergies (tomato, cheese): ") 
    (assert-string (str-cat "(allergies " (readline) ")"))) 

(defrule assert-allergies 
    (allergies $? ?a $?) 
    => 
    (assert (allergy ?a))) 

(reset) 
(run) 

但輸出此錯誤:

Jess reported an error in routine Context.getVariable 
    while executing (reset). 
Message: No such variable _blank_mf1. 

回答

0

我無法找到如何在反向鏈接的作品的任何詳細的文檔,但我認爲你需要使用$變量,你只需要$?在assert-allergies模式下:

Jess> (do-backward-chaining allergies) 
TRUE 
Jess> 
(defrule ask-allergies 
    (need-allergies $?) 
    => 
    (printout t "Tell me your allergies (tomato, cheese): ") 
    (assert-string (str-cat "(allergies " (readline) ")"))) 
TRUE 
Jess> 
(defrule assert-allergies 
    (allergies $?b ?a $?e) 
    => 
    (assert (allergy ?a))) 
TRUE 
Jess> (reset) 
TRUE 
Jess> (run) 
Tell me your allergies (tomato, cheese): fish onions salt 
4 
Jess> (facts) 
f-0 (MAIN::initial-fact) 
f-1 (MAIN::need-allergies nil nil nil) 
f-2 (MAIN::allergies fish onions salt) 
f-3 (MAIN::allergy salt) 
f-4 (MAIN::allergy fish) 
f-5 (MAIN::allergy onions) 
For a total of 6 facts in module MAIN. 
Jess>