All turtle tests now pass
iri/iri.scm
| 96 | 96 | (loop | |
| 97 | 97 | (if add-slash? | |
| 98 | 98 | (string-join (cons "" (cdr (cdr segments))) "/") | |
| 99 | - | (string-join (cdr segments))) | |
| 99 | + | (string-join (cons "" (cdr segments)) "/")) | |
| 100 | 100 | (if add-slash? | |
| 101 | 101 | (string-append output "/" segment) | |
| 102 | 102 | (string-append output segment))))))))) |
rdf/rdf.scm
| 264 | 264 | #f)))) | |
| 265 | 265 | ||
| 266 | 266 | (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)))) | |
| 271 | 280 | ||
| 272 | 281 | (define (to-disjunctions constraints) | |
| 273 | 282 | (match constraints | |
| 274 | 283 | (('equiv b1 b2) (list (list (cons b1 b2)))) | |
| 275 | 284 | ('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))))) | |
| 277 | 295 | (('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))))))) | |
| 279 | 305 | ||
| 280 | 306 | (define (generate-triple-constraints t1 t2) | |
| 281 | 307 | (match t1 | |
… | |||
| 296 | 322 | ||
| 297 | 323 | (define (generate-constraints t1 g2) | |
| 298 | 324 | (match g2 | |
| 299 | - | ('() 'none) | |
| 325 | + | ('() 'bot) | |
| 300 | 326 | ((t2 g2 ...) | |
| 301 | 327 | (let ((c (generate-triple-constraints t1 t2))) | |
| 302 | 328 | (if c | |
… | |||
| 334 | 360 | (validate-mapping mapping g1 g2))))) | |
| 335 | 361 | ||
| 336 | 362 | (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." | |
| 338 | 364 | (let* ((constraints (fold (lambda (t constraints) | |
| 339 | 365 | (list 'and (generate-constraints t g2) constraints)) | |
| 340 | 366 | 'none g1)) | |
| 341 | 367 | (disjunctions (to-disjunctions constraints))) | |
| 342 | - | (pk 'dis disjunctions) | |
| 343 | 368 | (let loop ((disjunctions disjunctions)) | |
| 344 | - | (match disjunctions | |
| 369 | + | (match (filter sat? disjunctions) | |
| 345 | 370 | ('() (and (null? g1) (null? g2))) | |
| 346 | 371 | ((mapping disjunctions ...) | |
| 347 | 372 | (if (and (validate-mapping mapping g1 g2) | |
turtle/tordf.scm
| 59 | 59 | (update-parser-state state | |
| 60 | 60 | #:namespaces (cons (cons ns iri) (parser-state-namespaces state)))) | |
| 61 | 61 | ||
| 62 | - | (define (parse-string str) | |
| 62 | + | (define* (parse-string str #:optional for-iri?) | |
| 63 | 63 | (match str | |
| 64 | 64 | ((? string? str) str) | |
| 65 | 65 | ((component str ...) | |
… | |||
| 83 | 83 | (parse-string str))))) | |
| 84 | 84 | (() ""))) | |
| 85 | 85 | ||
| 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 | + | ||
| 86 | 91 | (define (parse-iri iri state) | |
| 92 | + | (pk 'iri iri) | |
| 87 | 93 | (match iri | |
| 88 | 94 | (('iri ('prefixed-name ('pname-ln ('pname-ns ns) ('pn-local suffix)))) | |
| 89 | 95 | `(("iri" . ,(string-append (assoc-ref (parser-state-namespaces state) ns) | |
… | |||
| 103 | 109 | `(("iri" . ,(resolve-iri (parser-state-base-uri state) "")) | |
| 104 | 110 | ("state" . ,state))) | |
| 105 | 111 | (('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)))))) | |
| 108 | 117 | ||
| 109 | 118 | (define (parse-verb verb state) | |
| 110 | 119 | (match verb | |