2017-09-24 5 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

내가 어떻게 뒤로 체인 작품에 어떤 자세한 문서를 찾을 수 없습니다,하지만 난 당신이 $를 사용할 필요가 있다고 생각 당신은 단지 $이 변수? 주장 - 알레르기 패턴 :

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>