2014-09-16 2 views
0

현재 CLIPS에서 일하고 있으며 새로운 경험이 있습니다. 나는 클립에 다음 정보가 deftemplate 복제하는 것을 시도하고있다 :CLIPS : 멀티 슬롯 내 슬롯

[Person, [Class,Class],[[M 9,11],[F,9,11]]] 

그것은 그들이 수업을 할 수있는 사람, 여러 그들이 취할 수있는 클래스와 시간을 가지고있다. 나는 다음과 같은 deftemplate이 정보를 복제하려고 :

(deftemplate person 
    (slot Name) 
    (multislot Class) 
    (multislot Available)) 

내 문제는 내가는 3 개 개의 입력을 가지고 있기 때문에 내가 사용할 수있는 멀티 슬롯에 어떻게해야하고 무엇을 이해하지 못하는 것입니다. 멀티 슬롯 내에서 슬롯을 만들 수있는 방법이 있습니까? 이 방법을 온라인에서 찾았지만이 문제를 올바르게 해결하지 못했습니다.

답변

1

다음과 같은 네 가지 접근 방식이 있습니다. 나는 이것들이 사실들/인스턴스들 사이의 단순한 연결을 포함하기 때문에 접근법 3 또는 4와 비슷한 것을 제안 할 것이다.

CLIPS> (clear) ; Approach 1 
CLIPS> 
(deftemplate person 
    (slot Name) 
    (multislot Class) 
    (multislot Available)) 
CLIPS>  
(deffacts people 
    (person (Name Frank) 
      (Class Biology Calculus) 
      (Available M 9 11 F 9 11))) 
CLIPS> 
(deffunction #-of-triplets (?mf) 
    (div (length$ ?mf) 3)) 
CLIPS>  
(deffunction nth-triplet (?mf ?n) 
    (subseq$ ?mf (+ 1 (* (- ?n 1) 3))(* ?n 3))) 
CLIPS>  
(defrule print-availability 
    (person (Name ?name) 
      (Available $?a)) 
    => 
    (loop-for-count (?i (#-of-triplets ?a)) 
     (bind ?triplet (nth-triplet ?a ?i)) 
     (bind ?d (nth$ 1 ?triplet)) 
     (bind ?b (nth$ 2 ?triplet)) 
     (bind ?e (nth$ 3 ?triplet)) 
     (printout t ?name " " ?d " " ?b " " ?e crlf))) 
CLIPS> (reset) 
CLIPS> (run) 
Frank M 9 11 
Frank F 9 11 
CLIPS> (clear) ; Approach 2 
CLIPS> 
(deftemplate person 
    (slot Name) 
    (multislot Class) 
    (multislot Available-Weekday) 
    (multislot Available-Begin) 
    (multislot Available-End)) 
CLIPS>  
(deffacts people 
    (person (Name Frank) 
      (Class Biology Calculus) 
      (Available-Weekday M F) 
      (Available-Begin 9 9) 
      (Available-End 11 11))) 
CLIPS> 
(defrule print-availability 
    (person (Name ?name) 
      (Available-Weekday $?f1 ?d $?) 
      (Available-Begin $?f2 ?b $?) 
      (Available-End $?f3 ?e $?)) 
    (test (= (length$ ?f1) 
      (length$ ?f2) 
      (length$ ?f3))) 
    => 
    (printout t ?name " " ?d " " ?b " " ?e crlf)) 
CLIPS> (reset) 
CLIPS> (run) 
Frank M 9 11 
Frank F 9 11 
CLIPS> (clear) ; Approach 3 
CLIPS> 
(deftemplate person 
    (slot Name) 
    (slot ID) 
    (multislot Class)) 
CLIPS>  
(deftemplate availability 
    (slot owner-ID) 
    (slot Weekday) 
    (slot Begin) 
    (slot End)) 
CLIPS>  
(deffacts information 
    (person (Name Frank) (ID 1) 
      (Class Biology Calculus)) 
    (availability (owner-ID 1) (Weekday M) (Begin 9) (End 11)) 
    (availability (owner-ID 1) (Weekday F) (Begin 9) (End 11))) 
CLIPS> 
(defrule print-availability 
    (person (Name ?name) (ID ?id)) 
    (availability (owner-ID ?id) (Weekday ?d) (Begin ?b) (End ?e)) 
    => 
    (printout t ?name " " ?d " " ?b " " ?e crlf)) 
CLIPS> (reset) 
CLIPS> (run) 
Frank F 9 11 
Frank M 9 11 
CLIPS> (clear) ; Approach 4 
CLIPS> 
(defclass PERSON 
    (is-a USER) 
    (slot Name) 
    (multislot Class) 
    (multislot Available)) 
CLIPS>  
(defclass AVAILABILITY 
    (is-a USER) 
    (slot Weekday) 
    (slot Begin) 
    (slot End)) 
CLIPS>  
(definstances information 
    (of PERSON (Name Frank) 
       (Class Biology Calculus) 
       (Available (make-instance of AVAILABILITY (Weekday M) (Begin 9) (End 11)) 
         (make-instance of AVAILABILITY (Weekday F) (Begin 9) (End 11))))) 
CLIPS>       
(defrule print-availability 
    (object (is-a PERSON) (Name ?name) (Available $? ?a $?)) 
    (object (is-a AVAILABILITY) (name ?a)) 
    => 
    (printout t ?name " " (send ?a get-Weekday) 
         " " (send ?a get-Begin) 
         " " (send ?a get-End) crlf))) 
CLIPS> (reset) 
CLIPS> (run) 
Frank F 9 11 
Frank M 9 11 
CLIPS>