Recognize augmented triples

Julien LepillerSun Apr 05 14:15:15+0200 2020

cbc9d6d

Recognize augmented triples

rdf/entailment/rdf.scm

3636
           (cons (cons k v) (alist-set lst key val))))))
3737
3838
  (define (compatible? types)
39-
    (match types
39+
    (match (filter rdf-datatype? types)
4040
      (() #t)
4141
      ((_) #t)
4242
      ((a b ...)

6363
                                   (or
6464
                                     (assoc-ref type-mappings
6565
                                                (rdf-triple-subject t))
66-
                                     '())))))))))
66+
                                     '()))))
67+
                (loop (cdr graph) type-mappings))))))
6768
6869
  (and (d:consistent-graph? graph vocabulary)
69-
       (compatible-types? (augment (recognize graph vocabulary)))))
70+
       (compatible-types? (augment (recognize graph vocabulary) vocabulary))))
7071
7172
;; G entails E if E has an instance (where blank nodes are replaced by literals
7273
;; or IRIs) that is a subgraph of G.

121122
                          answer)))
122123
         (loop answer g))))))
123124
124-
(define (augment g)
125+
(define (augment g vocabulary)
125126
  (let* ((g (append rdf-axioms g))
126127
         (g (append
127128
              (append-map rdf-axioms-container (rdf-container-properties g))
128129
              g)))
129-
    (let loop ((g g))
130+
    (let loop ((g (recognize g vocabulary)))
130131
      (let ((augment-set
131132
             (let loop2 ((g2 g) (augment-set '()))
132133
               (match g2

155156
                      augment-set))))))))
156157
        (if (null? augment-set)
157158
            g
158-
            (loop (append augment-set g)))))))
159+
            (loop (append (recognize augment-set vocabulary) g)))))))
159160
160161
(define (equiv? n1 n2)
161162
  (match (list n1 n2)

192193
(define (entails? g e vocabulary)
193194
  "Return true if g entails e"
194195
  (let* ((g (recognize g vocabulary))
195-
         (g (augment g))
196+
         (g (augment g vocabulary))
196197
         (e (recognize e vocabulary)))
197198
    (or (not (consistent-graph? g vocabulary))
198199
        (d:entails? g e vocabulary))))

rdf/entailment/rdfs.scm

4242
           (valid-subclasses? graph)))
4343
      ((_ graph ...)
4444
       (valid-subclasses? graph))))
45-
  (and (valid-subclasses? (augment (recognize graph vocabulary)
46-
                                   (rdf-vocabulary-datatypes vocabulary)))
45+
  (and (valid-subclasses? (augment (recognize graph vocabulary) vocabulary))
4746
       (rdf:consistent-graph? graph vocabulary)))
4847
4948
;; G entails E if E has an instance (where blank nodes are replaced by literals

259258
                   '()))))
260259
        graph))))
261260
262-
(define (augment g d)
261+
(define (augment g voc)
263262
  (let* ((g (append rdfs-axioms g))
264-
         (g (append (rdfs-axioms-types d) g))
263+
         (g (append (rdfs-axioms-types (rdf-vocabulary-datatypes voc)) g))
265264
         (g (append
266265
              ;; rdfs1
267266
              (map
268267
                (lambda (t)
269268
                  (make-rdf-triple t (rdf-iri "type") (rdfs-iri "Datatype")))
270-
                d)))
269+
                (rdf-vocabulary-datatypes voc))))
271270
         (g (append
272271
              (append-map rdfs-axioms-container (rdf-container-properties g))
273272
              g)))

279278
                                     (augment-set
280279
                                       (if (null? graph)
281280
                                           g
282-
                                           (pk 'entailments
283-
                                           (get-entailments
284-
                                             graph subclasses subprops ranges
285-
                                             domains types)))))
281+
                                           (recognize
282+
                                             (get-entailments
283+
                                               graph subclasses subprops ranges
284+
                                               domains types)
285+
                                             voc))))
286286
        (match augment-set
287287
          (() (if added?
288288
                  (loop graph subclasses subprops ranges domains types)

315315
(define (entails? g e vocabulary)
316316
  "Return true if g entails e recognizing d"
317317
  (let* ((g (recognize g vocabulary))
318-
         (g (augment g (rdf-vocabulary-datatypes vocabulary)))
318+
         (g (augment g vocabulary))
319319
         (e (recognize e vocabulary)))
320320
    (or (not (consistent-graph? g vocabulary))
321321
        (d:entails? g e vocabulary))))