summaryrefslogtreecommitdiff
path: root/schemantic/rdf/datalog.scm
blob: cc8af5e03c62baf96b14b30bd2d012f17574f102 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(define-module (schemantic rdf datalog)
  #:use-module (schemantic rdf)
  #:use-module ((schemantic ns) #:select (rdf rdfs))

  #:use-module (datalog)
  #:use-module (datalog vhash-set)

  #:use-module (ice-9 vlist)

  #:use-module (srfi srfi-1)

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

            rhodf))

(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))


;; The ρdf fragment of RDF
;; See: Muñoz, S., Pérez, J., & Gutierrez, C. (2009). Simple and Efficient Minimal RDFS. Web Semantics: Science, Services and Agents on the World Wide Web, 7(3), 220–234. doi:10.1016/j.websem.2009.07.003
(define rhodf
  (list

   ;; Subproperty (a)
   (:- (rhodf (lvar 'a) (rdfs "subProperty") (lvar 'c))
    (rhodf (lvar 'a) (rdfs "subProperty") (lvar 'b))
    (rhodf (lvar 'b) (rdfs "subProperty") (lvar 'c)))

   ;; Subproperty (b)
   (:- (rhodf (lvar 'x) (lvar 'b) (lvar 'y))
    (rhodf (lvar 'a) (rdfs "subProperty") (lvar 'b))
    (rhodf (lvar 'x) (lvar 'a) (lvar 'y)))

   ;; Subclass (a)
   (:- (rhodf (lvar 'a) (rdfs "subClass") (lvar 'c))
    (rhodf (lvar 'a) (rdfs "subClass") (lvar 'b))
    (rhodf (lvar 'b) (rdfs "subClass") (lvar 'c)))

   ;; Subclass (b)
   (:- (rhodf (lvar 'x) (rdf "type") (lvar 'b))
    (rhodf (lvar 'a) (rdfs "subClass") (lvar 'b))
    (rhodf (lvar 'x) (rdf "type") (lvar 'a)))

   ;; Typing (a)
   (:- (rhodf (lvar 'x) (rdf "type") (lvar 'b))
    (rhodf (lvar 'a) (rdfs "domain") (lvar 'b))
    (rhodf (lvar 'x) (lvar 'a) (lvar 'y)))

   ;; Typing (b)
   (:- (rhodf (lvar 'y) (rdf "type") (lvar 'b))
    (rhodf (lvar 'a) (rdfs "range") (lvar 'b))
    (rhodf (lvar 'x) (lvar 'a) (lvar 'y)))

   ;; Implicit Typing (a)
   (:- (rhodf (lvar 'x) (rdf "type") (lvar 'b))
    (rhodf (lvar 'a) (rdfs "domain") (lvar 'b))
    (rhodf (lvar 'c) (rdfs "subProperty") (lvar 'a))
    (rhodf (lvar 'x) (lvar 'c) (lvar 'y)))

   ;; Implicit Typing (b)
   (:- (rhodf (lvar 'y) (rdf "type") (lvar 'b))
    (rhodf (lvar 'a) (rdfs "range") (lvar 'b))
    (rhodf (lvar 'c) (rdfs "subProperty") (lvar 'a))
    (rhodf (lvar 'x) (lvar 'c) (lvar 'y)))))