Export procedures to canonicalize the inputs to MAKE-RDF-TRIPLE.
authorChris Hanson <org/chris-hanson/cph>
Tue, 7 Mar 2006 06:16:26 +0000 (06:16 +0000)
committerChris Hanson <org/chris-hanson/cph>
Tue, 7 Mar 2006 06:16:26 +0000 (06:16 +0000)
v7/src/xml/rdf-struct.scm
v7/src/xml/xml.pkg

index 25c045fe1d26f208414c0a762d0bf007bc5dcde4..0151e4ca7d262265bfca38f153a3c9de5b6c3152 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: rdf-struct.scm,v 1.4 2006/03/07 02:51:12 cph Exp $
+$Id: rdf-struct.scm,v 1.5 2006/03/07 06:16:22 cph Exp $
 
 Copyright 2006 Massachusetts Institute of Technology
 
@@ -37,14 +37,9 @@ USA.
 (define-guarantee rdf-triple "RDF triple")
 
 (define (make-rdf-triple subject predicate object)
-  (%make-rdf-triple (if (rdf-bnode? subject)
-                       subject
-                       (->absolute-uri subject 'MAKE-RDF-TRIPLE))
-                   (->absolute-uri predicate 'MAKE-RDF-TRIPLE)
-                   (if (or (rdf-bnode? object)
-                           (rdf-literal? object))
-                       object
-                       (->absolute-uri object 'MAKE-RDF-TRIPLE))))
+  (%make-rdf-triple (canonicalize-rdf-subject subject 'MAKE-RDF-TRIPLE)
+                   (canonicalize-rdf-predicate predicate 'MAKE-RDF-TRIPLE)
+                   (canonicalize-rdf-object object 'MAKE-RDF-TRIPLE)))
 
 (define-record-type <rdf-bnode>
     (%make-rdf-bnode name)
@@ -129,6 +124,21 @@ USA.
       (if (not (rdf-literal? o))
          (add o (rdf-index-objects index))))))
 
+(define (canonicalize-rdf-subject subject #!optional caller)
+  (if (rdf-bnode? subject)
+      subject
+      (->absolute-uri subject caller)))
+
+(define (canonicalize-rdf-predicate predicate #!optional caller)
+  (->absolute-uri predicate caller))
+
+(define (canonicalize-rdf-object object #!optional caller)
+  (cond ((or (rdf-bnode? object)
+            (rdf-literal? object))
+        object)
+       ((string? object) (make-rdf-literal object #f))
+       (else (->absolute-uri object caller))))
+
 (define match-bnode-name
   (let* ((name-head
          (char-set-union (ascii-range->char-set #x41 #x5B)
index 6acb6037f715dc93d09e112cf3c2304dfa7ad78b..0b8662bae48adca261db1b79678ab72bd8c2ed72 100644 (file)
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Id: xml.pkg,v 1.66 2006/03/07 02:51:16 cph Exp $
+$Id: xml.pkg,v 1.67 2006/03/07 06:16:26 cph Exp $
 
 Copyright 2001,2002,2003,2004,2005,2006 Massachusetts Institute of Technology
 
@@ -530,6 +530,9 @@ USA.
          <rdf-literal>
          <rdf-triple>
          add-to-rdf-index
+         canonicalize-rdf-object
+         canonicalize-rdf-predicate
+         canonicalize-rdf-subject
          error:not-rdf-bnode
          error:not-rdf-index
          error:not-rdf-literal