As you state it, there is no need to sort all open and close events so that
you can combine an OPEN to ist closest CLOSE. The conditions that define,
for any OPEN, the matching CLOSE are simple enough:

deftemplate Open   (slot time))
(deftemplate Close  (slot time))
(deftemplate Access (slot begin)(slot end))

(defrule MatchOpenClose
   "For any matching OpenClose, create an Access"
   ?open  <- (Open  (time ?otime))
   ; a matching CLOSE must not be earlier
   ?close <- (Close (time ?ctime &:(>= ?ctime ?otime)))
   ; there must not be a closer CLOSE
   (not (Close (time ?xtime &:(< (- ?xtime ?otime)(- ?ctime ?otime)))))
=>
   (retract ?open)
   (retract ?close)
   (assert (Access (begin ?otime)(end ?ctime)))
)

(deffacts Opcl
   (Open  (time  845))
   (Open  (time 1045))
   (Close (time  900))
   (Close (time 1115))
   (Open  (time 1215))
   (Close (time 1215))
)

(reset)
(run)
(facts)


f-0   (MAIN::initial-fact)
f-7   (MAIN::Access (begin 845) (end 900))
f-8   (MAIN::Access (begin 1045) (end 1115))
f-9   (MAIN::Access (begin 1215) (end 1215))
For a total of 4 facts in module MAIN.

Regards
Wolfgang


On Fri, May 9, 2008 at 8:41 PM, Gary Napier <[EMAIL PROTECTED]>
wrote:

> My basic problem is this.
> I have two events, OPEN and CLOSE, both timestamped
>
> I would like to relate an OPEN and CLOSE to generate a new fact X
> However with data skew, there may be a mix of OPEN and CLOSE facts
> mixed, such that
>
> OPEN 7:15
> CLOSE 9:00
> CLOSE 8:00
> OPEN 8:15
>
> Would there be any way of sorting these facts (possibly in a multi slot
> or using an extra slot) so that they were ordered.
>
>

Reply via email to