Noel Huebers wrote
 (defquery searchcontext
   (declare (variables ?name ?task ?val))
   (context
        (username ?name)
        (action "Bewertet")
        (task ?task)
        (value ?val)))

 Now I want to delete the some facts. How do I get a fact from the
 queryresult '?result' ?

 ;(deffunction delformerattempts(?n ?t ?v)
 ;    (bind ?results (run-query* searchcontext ?n ?t ?v))
 ;    (while (?results next))
 ;    (retract ?results get))

All you have to do is extend the pattern in the query with a binding for the entire fact:

(defquery searchcontext
  (declare (variables ?name ?task ?val))
  ?context <- (context
      (username ?name)
      (action "Bewertet")
      (task ?task)
      (value ?val)))

And then you access it with the get method:
(deffunction delformerattempts (?n ?t ?v)
   (bind ?results (run-query* searchcontext ?n ?t ?v))
   (while (?results next)
     (retract (?results get context ))))

But wouldn't it be more convenient to rearrange things so that the context fact maintains a counter, with new "Bewertet" events being counted right there. Here's how:

(clear)

(deftemplate Base   (slot username)(slot action)(slot value)(slot task))
(deftemplate Context extends Base (slot count (default 1)))
(deftemplate Event   extends Base (slot stamp ))

(defrule IncrementCount
   ?event <- (Event (username ?s)(action "Bewertet")(value ?v)(task ?t))
?context <- (Context (username ?s)(action "Bewertet")(value ?v)(task ?t)(count ?c))
   =>
   (modify ?context (count (++ ?c)))
   (retract ?event)
)

(defrule FirstTime
   ?event <- (Event (username ?s)(action "Bewertet")(value ?v)(task ?t))
   (not (Context (username ?s)(action "Bewertet")(value ?v)(task ?t)))
   =>
   (assert (Context (username ?s)(action "Bewertet")(value ?v)(task ?t)))
   (retract ?event)
)

(deffacts ecs
(Event (username "Max")(action "Bewertet")(value "3")(task "Thesis")(stamp 1)) (Event (username "Max")(action "Bewertet")(value "3")(task "Thesis")(stamp 2)) (Event (username "Max")(action "Bewertet")(value "3")(task "Thesis")(stamp 3))
)

(reset)
(run)

kr
Wolfgang




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to