Reputation: 2981
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?
Upvotes: 2
Views: 179
Reputation: 11
Your second attempt is more correct, but you should use lispp
instead of lisp
to check if the triple already exists:
(<-- (a-- ?s ?p ?o)
;; Fails unless all parts ground.
(lispp (not (get-triple :s ?s :p ?p :o ?o)))
(lisp (add-triple ?s ?p ?o)))
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.
Upvotes: 0