summaryrefslogtreecommitdiff
path: root/schemantic/rdf/datalog.scm
blob: e34a27208dc0a09986b32ac05b0b063d2936e2ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(define-module (schemantic rdf datalog)
  #:use-module (schemantic rdf)

  #:use-module (datalog vhash-set)

  #:use-module (ice-9 vlist)

  #:use-module (srfi srfi-1)

  #:export (add-rdf-graph-to-edb))

(define (add-rdf-graph-to-edb predicate-symbol graph context)
  (vhash-cons
   predicate-symbol
   (lambda (attributes)
     (fold
      (λ (triple result)
        (set-adjoin
         result
         (vector (triple-subject triple)
                 (triple-predicate triple)
                 (triple-object triple))))
      vlist-null
      (graph-match graph
                   (vector-ref attributes 0)
                   (vector-ref attributes 1)
                   (vector-ref attributes 2))))
   context))