检索多时隙值时过滤特定插槽

时间:2017-05-12 09:40:11

标签: clips

我想要检索包含多个时间段的对象,并同时过滤特定的插槽(获取时间)。 这是一个代码示例:

source "https://rubygems.org"
gem "middleman", ">= 4.0.0"
gem "middleman-compass", ">= 4.0.0"
gem "jquery-middleman"
gem "middleman-sprockets", ">= 4.0.0.rc.1"
gem "rubocop"
gem "rubocop-junit-formatter"
gem "middleman-s3_sync"
gem "middleman-dotenv"

CLIPS有可能吗?

谢谢Nicola

1 个答案:

答案 0 :(得分:1)

您可以过滤规则的RHS上的对象:

CLIPS> 
(defclass OBJ
   (is-a USER)
   (slot uuid
      (type STRING))
   (slot enable
      (type NUMBER)
      (allowed-integers 0 1) 
      (default 0)))
CLIPS> 
(defclass GROUP (is-a USER)
   (slot uuid
      (type STRING))
   (multislot objects
      (type INSTANCE-NAME)))
CLIPS> 
(definstances initial
   ([o1] of OBJ (enable 1))
   ([o2] of OBJ (enable 0))
   ([o3] of OBJ (enable 1))
   ([o4] of OBJ (enable 0))
   ([g1] of GROUP (objects [o1] [o2] [o3] [o4])))
CLIPS>    
(deffunction filter (?objects ?slot ?value)
   (bind ?result (create$))
   (progn$ (?o ?objects)
      (if (eq (send ?o (sym-cat get- ?slot)) ?value)
         then
         (bind ?result (create$ ?result ?o))))
   ?result)
CLIPS>    
(defrule my-rule  
   ?group <- (object (is-a GROUP)
                     (uuid ?uuid)
                     (objects $?objects)) 
   =>
   (bind ?objects (filter ?objects enable 1))
   (printout t "Objects = " ?objects crlf))
CLIPS> (reset)
CLIPS> (run)
Objects = ([o1] [o3])
CLIPS>