2014-12-08 3 views
0

입력을 얻으려는 시도에 문제가 있으며 주장 된 사실의 증상을 사실 확인하십시오.클립의 사실과 일치하는 입력 확인

(deftemplate disease 
(slot name) 
(multislot symptom)) 

(assert (disease 
(name nitro-def) (symptom stunted-growth pale-yellow reddish-brown-leaf))) 
(assert (disease 
(name phosphor-def) (symptom stunted-root-growth spindly-stalk purplish-colour))) 
(assert (disease 
(name potassium-def) (symptom purple-colour weakened-stems shriveled-seeds))) 

(defrule reading-input 
(disease (name ?name1) (symptom ?symptom1)) 
=> 
(printout t "Enter the symptom your plant exhibits: ") 
(assert (var (read)))) 

(defrule checking-input 
?vars <- (var) 
(disease (name ?name1) (symptom ?symptom1)) 
(disease (symptom ?vars&:(eq ?vars ?symptom1))) 
=> 
(printout t "Disease is " ?name1 crlf)) 

기본적으로 증상을 입력하면 Clips는 해당 증상과 일치하는 질병을 반환합니다. 문제는, 이후로 파일을 일괄으로로드하고 실행 중이면 아무 일도 일어나지 않습니다. 사실은 주장되지만 입력이 필요하지 않습니다. 첫 번째 규칙에도 영향을주지 않습니다.

누구든지이 문제에 도움이 될 수 있으면 감사히 생각합니다.

감사합니다.

답변

1

증상이 여러 필드 슬롯 (0 개 이상의 필드가 포함 된 슬롯)으로 정의되었지만 슬롯에 일치하는 패턴은 슬롯에 단일 필드가있는 경우에만 일치합니다. ? symptom1과 같은 단일 필드 변수 대신 $? symptom1과 같은 multifield 변수를 사용하여 여러 값을 검색하십시오.

CLIPS> 
(deftemplate disease 
    (slot name) 
    (multislot symptom)) 
CLIPS> 
(deffacts diseases 
    (disease (name nitro-def) 
      (symptom stunted-growth pale-yellow reddish-brown-leaf)) 
    (disease (name phosphor-def) 
      (symptom stunted-root-growth spindly-stalk purplish-colour)) 
    (disease (name potassium-def) 
      (symptom purple-colour weakened-stems shriveled-seeds))) 
CLIPS> 
(defrule reading-input 
    => 
    (printout t "Enter the symptom your plant exhibits: ") 
    (assert (var (read)))) 
CLIPS> 
(defrule checking-input 
    (var ?symptom) 
    (disease (name ?name1) (symptom $?symptom1)) 
    (test (member$ ?symptom ?symptom1)) 
    => 
    (printout t "Disease is " ?name1 crlf)) 
CLIPS> (reset) 
CLIPS> (run) 
Enter the symptom your plant exhibits: stunted-growth 
Disease is nitro-def 
CLIPS> (reset) 
CLIPS> (run) 
Enter the symptom your plant exhibits: purplish-colour 
Disease is phosphor-def 
CLIPS> (reset) 
CLIPS> (run) 
Enter the symptom your plant exhibits: spindly-stalk 
Disease is phosphor-def 
CLIPS> 
+0

오우! 고마워요, 게리 씨! 코드를 분석하면 내가 만든 실수를 깨닫게되었습니다. 아,이 입력/매칭을 시도하면서 무수히 많은 시간을 보냈지 만, 나는 오전 4 시까 지 머 무르지 만 여전히 효과가 있도록 관리하지 못했습니다. 감사합니다. – Darknote