All turtle tests now pass

Julien LepillerFri Apr 03 00:25:18+0200 2020

1e96e06

All turtle tests now pass

iri/iri.scm

9696
                (loop
9797
                  (if add-slash?
9898
                      (string-join (cons "" (cdr (cdr segments))) "/")
99-
                      (string-join (cdr segments)))
99+
                      (string-join (cons "" (cdr segments)) "/"))
100100
                  (if add-slash?
101101
                      (string-append output "/" segment)
102102
                      (string-append output segment)))))))))

rdf/rdf.scm

264264
         #f))))
265265
266266
(define (merge-joins l1 l2)
267-
  (match l1
268-
    ('() l2)
269-
    ((e1 l1 ...)
270-
     (merge-joins l1 (map (lambda (e2) (append e1 e2)) l2)))))
267+
  (cond
268+
    ((null? l1) l2)
269+
    ((null? l2) l1)
270+
    (else
271+
      (fold
272+
        (lambda (e1 res)
273+
          (append
274+
            (map (lambda (e2)
275+
                   (append e1 e2))
276+
                 l2)
277+
            res))
278+
        '()
279+
        l1))))
271280
272281
(define (to-disjunctions constraints)
273282
  (match constraints
274283
    (('equiv b1 b2) (list (list (cons b1 b2))))
275284
    ('none (list (list)))
276-
    (('or e1 e2) (append (to-disjunctions e1) (to-disjunctions e2)))
285+
    (('or e1 e2)
286+
     (cond
287+
       ((equal? e2 'bot)
288+
        (to-disjunctions e1))
289+
       ((equal? e1 'bot)
290+
        (to-disjunctions e2))
291+
       (else
292+
         (let ((e1 (to-disjunctions e1))
293+
               (e2 (to-disjunctions e2)))
294+
           (append e1 e2)))))
277295
    (('and e1 e2)
278-
     (merge-joins (to-disjunctions e1) (to-disjunctions e2)))))
296+
     (cond
297+
       ((equal? e1 'bot)
298+
        'bot)
299+
       ((equal? e2 'bot)
300+
        'bot)
301+
       (else
302+
         (let ((e1 (to-disjunctions e1))
303+
               (e2 (to-disjunctions e2)))
304+
           (merge-joins e1 e2)))))))
279305
280306
(define (generate-triple-constraints t1 t2)
281307
  (match t1

296322
297323
(define (generate-constraints t1 g2)
298324
  (match g2
299-
    ('() 'none)
325+
    ('() 'bot)
300326
    ((t2 g2 ...)
301327
     (let ((c (generate-triple-constraints t1 t2)))
302328
       (if c

334360
          (validate-mapping mapping g1 g2)))))
335361
336362
(define (rdf-isomorphic? g1 g2)
337-
  "Compare two graphs and return whether they are isomorphic."
363+
  "Compare two graphs and return whether they are isomorph."
338364
  (let* ((constraints (fold (lambda (t constraints)
339365
                              (list 'and (generate-constraints t g2) constraints))
340366
                            'none g1))
341367
         (disjunctions (to-disjunctions constraints)))
342-
    (pk 'dis disjunctions)
343368
    (let loop ((disjunctions disjunctions))
344-
      (match disjunctions
369+
      (match (filter sat? disjunctions)
345370
        ('() (and (null? g1) (null? g2)))
346371
        ((mapping disjunctions ...)
347372
         (if (and (validate-mapping mapping g1 g2)

turtle/tordf.scm

5959
  (update-parser-state state
6060
    #:namespaces (cons (cons ns iri) (parser-state-namespaces state))))
6161
62-
(define (parse-string str)
62+
(define* (parse-string str #:optional for-iri?)
6363
  (match str
6464
    ((? string? str) str)
6565
    ((component str ...)

8383
          (parse-string str)))))
8484
    (() "")))
8585
86+
(define (valid-iri? iri)
87+
  (and (not (string-any (ucs-range->char-set 0 33) iri))
88+
       (not (string-any #\< iri))
89+
       (not (string-any #\> iri))))
90+
8691
(define (parse-iri iri state)
92+
  (pk 'iri iri)
8793
  (match iri
8894
    (('iri ('prefixed-name ('pname-ln ('pname-ns ns) ('pn-local suffix))))
8995
     `(("iri" . ,(string-append (assoc-ref (parser-state-namespaces state) ns)

103109
     `(("iri" . ,(resolve-iri (parser-state-base-uri state) ""))
104110
       ("state" . ,state)))
105111
    (('iri ('iriref iri ...))
106-
     `(("iri" . ,(resolve-iri (parser-state-base-uri state) (parse-string iri)))
107-
       ("state" . ,state)))))
112+
     (let ((iri (resolve-iri (parser-state-base-uri state) (parse-string iri))))
113+
       (if (valid-iri? iri)
114+
           `(("iri" . ,iri)
115+
             ("state" . ,state))
116+
           (throw 'invalid-iri iri))))))
108117
109118
(define (parse-verb verb state)
110119
  (match verb