5

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?
Seki
  • 11,135
  • 7
  • 46
  • 70
florins
  • 1,605
  • 1
  • 17
  • 33

1 Answers1

4

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 :

Aymeric
  • 906
  • 9
  • 20
  • Hello, Aymeric! Thank you for your helpful answer. I would like to ask you if there is a programmatic way (saying by using Java language or script language) to execute such kind of rules over the AllegroGraph? I have a pipeline that poor statements into the AG and after the process is finished, rules should be applied. Thank you again. Regards, Florin – florins Jan 21 '12 at 17:03
  • Well you can store all the functors server-side using the scripts or the initfile. You can after that run some queries to add the new statements using the AllegroGraph HTTP API. – Aymeric Jan 23 '12 at 15:50
  • I have stumbled on a similar problem. The thing is, I want to add a triple only if it doesn't already exist. From what I have read, your adding functor(a--) should do this. I have copied it, but it doesn't seem to work. The triple is added, no matter if it already exists or not. Why is this happening? I have posted the question [here](http://stackoverflow.com/questions/9095983/allegrograph-check-existing-triple) – Dragos Feb 07 '12 at 13:26