Improve graph isomorphism detection
rdf/rdf.scm
339 | 339 | (match constraints | |
340 | 340 | (('equiv b1 b2) (list (list (cons b1 b2)))) | |
341 | 341 | ('none (list (list))) | |
342 | + | ('bot 'bot) | |
342 | 343 | (('or e1 e2) | |
343 | - | (cond | |
344 | - | ((equal? e2 'bot) | |
345 | - | (to-disjunctions e1)) | |
346 | - | ((equal? e1 'bot) | |
347 | - | (to-disjunctions e2)) | |
348 | - | (else | |
349 | - | (let ((e1 (to-disjunctions e1)) | |
350 | - | (e2 (to-disjunctions e2))) | |
344 | + | (let ((e1 (to-disjunctions e1)) | |
345 | + | (e2 (to-disjunctions e2))) | |
346 | + | (cond | |
347 | + | ((equal? e2 'bot) | |
348 | + | e1) | |
349 | + | ((equal? e1 'bot) | |
350 | + | e2) | |
351 | + | (else | |
351 | 352 | (append e1 e2))))) | |
352 | 353 | (('and e1 e2) | |
353 | - | (cond | |
354 | - | ((equal? e1 'bot) | |
355 | - | 'bot) | |
356 | - | ((equal? e2 'bot) | |
357 | - | 'bot) | |
358 | - | (else | |
359 | - | (let ((e1 (to-disjunctions e1)) | |
360 | - | (e2 (to-disjunctions e2))) | |
354 | + | (let ((e1 (to-disjunctions e1)) | |
355 | + | (e2 (to-disjunctions e2))) | |
356 | + | (cond | |
357 | + | ((equal? e1 'bot) | |
358 | + | 'bot) | |
359 | + | ((equal? e2 'bot) | |
360 | + | 'bot) | |
361 | + | (else | |
361 | 362 | (merge-joins e1 e2))))))) | |
362 | 363 | ||
363 | 364 | (define (generate-triple-constraints t1 t2) | |
… | |||
425 | 426 | "Compare two graphs and return whether they are isomorph." | |
426 | 427 | (let* ((constraints (generate-graph-constraints g1 g2)) | |
427 | 428 | (disjunctions (to-disjunctions constraints))) | |
428 | - | (let loop ((disjunctions (filter sat? disjunctions))) | |
429 | - | (match disjunctions | |
430 | - | ('() (and (null? g1) (null? g2))) | |
431 | - | ((mapping disjunctions ...) | |
432 | - | (if (and (validate-mapping mapping g1 g2) | |
433 | - | (validate-mapping (reverse-mapping mapping) g2 g1)) | |
434 | - | #t | |
435 | - | (loop disjunctions))))))) | |
429 | + | (if (list? disjunctions) | |
430 | + | (let loop ((disjunctions (filter sat? disjunctions))) | |
431 | + | (match disjunctions | |
432 | + | ('() (and (null? g1) (null? g2))) | |
433 | + | ((mapping disjunctions ...) | |
434 | + | (if (and (validate-mapping mapping g1 g2) | |
435 | + | (validate-mapping (reverse-mapping mapping) g2 g1)) | |
436 | + | #t | |
437 | + | (loop disjunctions))))) | |
438 | + | #f))) | |
436 | 439 | ||
437 | 440 | (define (generate-dataset-constraints d1 d2) | |
438 | 441 | (let ((g1 (rdf-dataset-default-graph d1)) | |
… | |||
480 | 483 | "Compare two datasets and return whether they are isomorphic." | |
481 | 484 | (let* ((constraints (generate-dataset-constraints d1 d2)) | |
482 | 485 | (disjunctions (to-disjunctions constraints))) | |
483 | - | (let loop ((disjuctions (filter sat? disjunctions))) | |
484 | - | (match disjunctions | |
485 | - | ('() (and (null? (rdf-dataset-default-graph d1)) | |
486 | - | (null? (rdf-dataset-default-graph d2)) | |
487 | - | (null? (rdf-dataset-named-graphs d1)) | |
488 | - | (null? (rdf-dataset-named-graphs d2)))) | |
489 | - | ((mapping disjunctions ...) | |
490 | - | (or (and (validate-dataset-mapping mapping d1 d2) | |
491 | - | (validate-dataset-mapping (reverse-mapping mapping) d2 d1)) | |
492 | - | (loop disjunctions))))))) | |
486 | + | (if (list? disjunctions) | |
487 | + | (let loop ((disjunctions (filter sat? disjunctions))) | |
488 | + | (match disjunctions | |
489 | + | ('() (and (null? (rdf-dataset-default-graph d1)) | |
490 | + | (null? (rdf-dataset-default-graph d2)) | |
491 | + | (null? (rdf-dataset-named-graphs d1)) | |
492 | + | (null? (rdf-dataset-named-graphs d2)))) | |
493 | + | ((mapping disjunctions ...) | |
494 | + | (or (and (validate-dataset-mapping mapping d1 d2) | |
495 | + | (validate-dataset-mapping (reverse-mapping mapping) d2 d1)) | |
496 | + | (loop disjunctions))))) | |
497 | + | #f))) | |
493 | 498 | ||
494 | 499 | ;; Recognizing datatypes is a transformation on the graph to add the proper | |
495 | 500 | ;; datatype to literals, and replace IRIs that represent a datatype with the |