CLIPS中的实例和插槽

时间:2014-10-24 00:16:14

标签: ontology protege clips

我目前正在为手机制作一个CLips计划。我有不同的手机和他们的规格。我试图找出如何使用defrules来整理Color等功能。我将在下面展示我的意思:

([phones_Class85] of  Moto+X

(Battery+Life "240")
(Build+Material "Metal")
(Camera "13")
(Card+Slot "Yes")
(Color "Cream")
(FingerPrint+Scanner "No")
(Memory "16")
(Operating+System "Android")
(Price "119")
(RAM "1")
(Screen+Size "5.2")
(Water+Resistant "Yes")
(Weight "144"))

([phones_Class86] of  IPhone+6

(Battery+Life "250")
(Build+Material "Metal")
(Camera "8")
(Card+Slot "No")
(Color "Gold")
(FingerPrint+Scanner "Yes")
(Memory "16")
(Operating+System "IOS")
(Price "199")
(RAM "1")
(Screen+Size "4.7")
(Water+Resistant "No")
(Weight "129"))


([phones_Class93] of  IPhone+5s

(Battery+Life "250")
(Build+Material "Metal")
(Camera "8")
(Card+Slot "No")
(Color "Gold")
(FingerPrint+Scanner "Yes")
(Memory "16")
(Operating+System "IOS")
(Price "99")
(RAM "1")
(Screen+Size "4")
(Water+Resistant "No")
(Weight "112"))

正如您所看到的,我有不同的手机,其中包含不同规格的实例。还有更多,但我jsut给了一些。我试图用一个defrule做一些事情,这将允许我打印出所有颜色为黄金的手机。当我遇到实例时,我不确定如何通过这个。有没有办法访问实例中的不同插槽(颜色),然后检查每个插槽?

1 个答案:

答案 0 :(得分:1)

CLIPS> 
(defclass Phone
   (is-a USER)
   (slot Battery+Life)
   (slot Build+Material)   
   (slot Camera)
   (slot Card+Slot)
   (slot Color)
   (slot FingerPrint+Scanner)
   (slot Memory)
   (slot Operating+System)
   (slot Price)
   (slot RAM)
   (slot Screen+Size)
   (slot Water+Resistant)
   (slot Weight))
CLIPS> 
(defclass Moto+X
   (is-a Phone))
CLIPS> 
(defclass IPhone
   (is-a Phone))
CLIPS>    
(defclass IPhone+6
   (is-a IPhone))
CLIPS>    
(defclass IPhone+5s
   (is-a IPhone))
CLIPS> 
(definstances Phones
   ([phones_Class85] of  Moto+X
      (Battery+Life "240")
      (Build+Material "Metal")
      (Camera "13")
      (Card+Slot "Yes")
      (Color "Cream")
      (FingerPrint+Scanner "No")
      (Memory "16")
      (Operating+System "Android")
      (Price "119")
      (RAM "1")
      (Screen+Size "5.2")
      (Water+Resistant "Yes")
      (Weight "144"))

([phones_Class86] of  IPhone+6
      (Battery+Life "250")
      (Build+Material "Metal")
      (Camera "8")
      (Card+Slot "No")
      (Color "Gold")
      (FingerPrint+Scanner "Yes")
      (Memory "16")
      (Operating+System "IOS")
      (Price "199")
      (RAM "1")
      (Screen+Size "4.7")
      (Water+Resistant "No")
      (Weight "129"))

([phones_Class93] of  IPhone+5s
      (Battery+Life "250")
      (Build+Material "Metal")
      (Camera "8")
      (Card+Slot "No")
      (Color "Gold")
      (FingerPrint+Scanner "Yes")
      (Memory "16")
      (Operating+System "IOS")
      (Price "99")
      (RAM "1")
      (Screen+Size "4")
      (Water+Resistant "No")
      (Weight "112")))
CLIPS>       
(defrule find-gold-phones
   (object (is-a Phone)
           (name ?name)
           (Color "Gold"))
   =>
   (printout t ?name " is a gold phone." crlf))
CLIPS>    
(defrule find-gold-iPhones
   (object (is-a IPhone)
           (name ?name)
           (Color "Gold"))
   =>
   (printout t ?name " is a gold iPhone." crlf))
CLIPS> (reset)
CLIPS> (run)
[phones_Class93] is a gold phone.
[phones_Class93] is a gold iPhone.
[phones_Class86] is a gold phone.
[phones_Class86] is a gold iPhone.
CLIPS>