Prolog functors are part of a Prolog program. When you write a query over an AllegroGraph store using Prolog, you re really writing a Prolog program that derives a set of answers to the constraints expressed in the program.
parentOf isn t part of the store, it s part of the program.
What you re trying to do is materialize the knowledge implied by a Prolog program, such that it s available in the same form as the ground triples.
To do that you need to write a… Prolog program that derives the inferred knowledge and adds it to the store.
Here s some code that should help. It s some setup and example in Lisp, but the Prolog functors should be obvious.
;; Assume the prefix is set up. These are for the Lisp environment.
(register-namespace "ex" "http://example.com/")
(enable-!-reader)
;; Define functors for basic relationships.
(<-- (parent ?x ?y)
(father ?x ?y))
(<- (parent ?x ?y)
(mother ?x ?y))
(<-- (male ?x)
(q- ?x !ex:sex !ex:male))
(<-- (female ?x)
(q- ?x !ex:sex !ex:female))
(<-- (father ?x ?y)
(male ?x)
(q- ?x !ex:has-child ?y))
(<-- (mother ?x ?y)
(female ?x)
(q- ?x !ex:has-child ?y))
;; Functors for adding triples.
(<-- (a- ?s ?p ?o)
;; Fails unless all parts ground.
(lisp (add-triple ?s ?p ?o)))
(<-- (a- ?s ?p ?o ?g)
;; Fails unless all parts ground.
(lisp (add-triple ?s ?p ?o ?g)))
(<-- (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)))
(<-- (a-- ?s ?p ?o ?g)
;; Fails unless all parts ground.
(lispp (not (get-triple :s ?s :p ?p :o ?o :g ?g)))
(lisp (add-triple ?s ?p ?o ?g)))
;; Add some sample data.
(create-triple-store "/tmp/foo")
(add-triple !ex:john !ex:sex !ex:male)
(add-triple !ex:dave !ex:sex !ex:male)
(add-triple !ex:alice !ex:sex !ex:female)
(add-triple !ex:alice !ex:has-child !ex:dave)
(add-triple !ex:john !ex:has-child !ex:dave)
;; Now who is a parent of whom?
(select (?parent ?child)
(parent ?parent ?child))
;; Returns:
;; (("http://example.com/john" "http://example.com/dave")
;; ("http://example.com/alice" "http://example.com/dave"))
;; Add the triples.
(select (?parent ?child) ; never succeeds
(parent ?parent ?child)
(a-- ?parent !ex:parentOf ?child)
(fail))
;; Now see what s in the store using the materialized triples.
(select (?parent ?child)
(q- ?parent !ex:parentOf ?child))
;; Returns:
;; (("http://example.com/john" "http://example.com/dave")
;; ("http://example.com/alice" "http://example.com/dave"))