Fix arguments for consistency checks

Julien LepillerSun Apr 05 04:10:34+0200 2020

a3f8af8

Fix arguments for consistency checks

rdf/entailment/d.scm

2323
  #:export (consistent-graph?
2424
            entails?))
2525
26-
(define (consistent-graph? graph)
26+
(define (consistent-graph? graph vocabulary)
2727
  (define consistent-data?
2828
    (match-lambda
2929
      (($ rdf-literal form ($ rdf-datatype _ _ lexical? _ _ _) _)
3030
       (lexical? form))
3131
      (_ #t)))
3232
33-
  (match graph
33+
  (match (recognize graph vocabulary)
3434
    ('() #t)
3535
    ((($ rdf-triple subject predicate object) graph ...)
3636
     (and (consistent-data? subject) (consistent-data? object)
37-
          (consistent-graph? graph)))))
37+
          (consistent-graph? graph vocabulary)))))
3838
3939
;; G entails E if E has an instance (where blank nodes are replaced by literals
4040
;; or IRIs) that is a subgraph of G.

163163
                        g2)))
164164
          (validate-mapping mapping g1 g2)))))
165165
166-
(define (entails? g e)
166+
(define (entails? g e vocabulary)
167167
  "Return true if g entails e"
168-
  (or (not (consistent-graph? g))
169-
      (let* ((constraints (fold (lambda (t constraints)
170-
                                  (list 'and (generate-constraints t g) constraints))
171-
                                'none e))
172-
             (disjunctions (to-disjunctions constraints)))
173-
        (if (equal? disjunctions 'bot)
174-
            #f
175-
            (let loop ((disjunctions (filter sat? disjunctions)))
176-
              (match disjunctions
177-
                ('() #f)
178-
                ((mapping disjunctions ...)
179-
                 (if (validate-mapping mapping e g)
180-
                   #t
181-
                   (loop disjunctions)))))))))
168+
  (let ((g (recognize g vocabulary)))
169+
    (or (not (consistent-graph? g vocabulary))
170+
        (let* ((constraints (fold (lambda (t constraints)
171+
                                    (list 'and (generate-constraints t g)
172+
                                          constraints))
173+
                                  'none e))
174+
               (disjunctions (to-disjunctions constraints)))
175+
          (if (equal? disjunctions 'bot)
176+
              #f
177+
              (let loop ((disjunctions (filter sat? disjunctions)))
178+
                (match disjunctions
179+
                  ('() #f)
180+
                  ((mapping disjunctions ...)
181+
                   (if (validate-mapping mapping e g)
182+
                     #t
183+
                     (loop disjunctions))))))))))

rdf/entailment/rdf.scm

5252
          (null?
5353
            (filter
5454
              (lambda (t)
55-
                (not (compatible (cdr t))))
55+
                (not (compatible? (cdr t))))
5656
              type-mappings))
5757
          (let* ((t (car graph)))
5858
            (if (equal? (rdf-triple-predicate t) (rdf-iri "type"))

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

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

rdf/entailment/rdfs.scm

4242
           (valid-subclasses? graph)))
4343
      ((_ graph ...)
4444
       (valid-subclasses? graph))))
45-
  (and (valid-subclasses? graph)
45+
  (and (valid-subclasses? (recognize graph vocabulary))
4646
       (rdf:consistent-graph? graph vocabulary)))
4747
4848
;; G entails E if E has an instance (where blank nodes are replaced by literals

316316
  (let* ((g (recognize g vocabulary)))
317317
    (or (not (consistent-graph? g vocabulary))
318318
        (d:entails? (augment g (rdf-vocabulary-datatypes vocabulary))
319-
                    (recognize e vocabulary)))))
319+
                    e vocabulary))))