Define rules for AllegroGraph triples and how to apply them

473 views Asked by At

I'm using AllegroGraph to store statement like this:

<newsid1  hasAnnotation  Gamma>
<newsid1  hasAnnotation Beta>

I would like to define a rule on this staments that says: if the subject newsid1 hasAnnotation either Gamma or Beta, then add a new statement in the triplestore that says that the subject hasAnnotation Theta, i.e. the statement

<newsid1  hasAnnotation Theta>

My questions are the following:

  1. How I can define such a rule for Allegro?
  2. How can I apply these rules over the statements?
1

There are 1 answers

3
Aymeric On BEST ANSWER

1) You can define use Prolog functors to define these rules. In your case you will define.

;; Functors to add triples.
(<-- (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)))

;; Functors to seek news that should have theta annotation
(<-- (shouldHaveAnnotationTheta ?news)  
(q- ?news !namespace:hasAnnotation !"Gamma"))

(<- (shouldHaveAnnotationTheta ?news)  
(q- ?news !namespace:hasAnnotation !"Beta"))

2) Run then the following prolog query (using the AGview for exemple) to add these news statements

(select (?news)
(shouldHaveAnnotationTheta ?news)
(a-- ?news !namespace:hasAnnotation !"Theta")
(fail))

You can read the following documents to understand this code :