I am using AllegroGraph 4. I have a triple store, and I am trying to add new triples only if they don't already exist.
Here is my Prolog query:
(select (?news) (alfas ?news) (a-- ?news !tst:has-annotation !tst:Test)))
where alfas checks for a condition(it works fine) and a--
is defined like this:
(<-- (a-- ?s ?p ?o)
;; Fails unless all parts ground.
(lisp (not (triple-exists-p ?s ?p ?o)))
(lisp (add-triple ?s ?p ?o)))
I have also tried defining it like this:
(<-- (a-- ?s ?p ?o)
;; Fails unless all parts ground.
(lisp (not (get-triple :s ?s :p ?p :o ?o)))
(lisp (add-triple ?s ?p ?o)))
But the triple is added anyway, no matter if it already exists or not. Why?
Your second attempt is more correct, but you should use
lispp
instead oflisp
to check if the triple already exists:You've seen this code already, because you commented here. But you must not have noticed the
lispp
functor, or understood that it runs as a predicate - as described in the documentation.