Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define rules for AllegroGraph triples and how to apply them

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?
like image 379
florins Avatar asked Oct 09 '22 23:10

florins


1 Answers

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 :

  • Prolog functors
  • Lisp Reference
like image 174
Aymeric Avatar answered Oct 23 '22 22:10

Aymeric