about summary refs log tree commit diff
path: root/dump/triples.scm
diff options
context:
space:
mode:
Diffstat (limited to 'dump/triples.scm')
-rw-r--r--dump/triples.scm35
1 files changed, 25 insertions, 10 deletions
diff --git a/dump/triples.scm b/dump/triples.scm
index 32cd243..a0f8213 100644
--- a/dump/triples.scm
+++ b/dump/triples.scm
@@ -1,24 +1,39 @@
 (define-module (dump triples)
   #:use-module (ice-9 regex)
   #:use-module (ice-9 match)
-  #:use-module (dump utils)
+  #:use-module (dump strings)
   #:export (ontology
             string->identifier
             prefix
             triple
-            scm->triples))
+            scm->triples
+            annotate-field))
+
+(define (annotate-field field schema)
+  (let ([schema (cond ((symbol? schema)
+                       (symbol->string schema))
+                      ((string? schema) schema)
+                      (else
+                       (error "Use a string/symbol")))]
+        [string-field (if (number? field) (number->string field) field)])
+    (if (string-null? string-field)
+        ""
+        (string->symbol
+         (format #f "~s~a" string-field schema)))))
 
 (define (string->identifier prefix str)
   "Convert STR to a turtle identifier after replacing illegal
 characters with an underscore and prefixing with gn:PREFIX."
-  (string->symbol
-   (string-append "gn:" prefix "_"
-                  (string-map (lambda (c)
-                                (case c
-                                  ((#\/ #\< #\> #\+ #\( #\) #\space #\@) #\_)
-                                  (else c)))
-                              (string-downcase
-                               (string-trim-right str #\.))))))
+  (if (string-null? str)
+      ""
+      (string->symbol
+       (string-append "gn:" prefix "_"
+                      (string-map (lambda (c)
+                                    (case c
+                                      ((#\/ #\< #\> #\+ #\( #\) #\space #\@) #\_)
+                                      (else c)))
+                                  (string-downcase
+                                   (string-trim-right str #\.)))))))
 
 (define (prefix prefix iri)
   (format #t "@prefix ~a ~a .~%" prefix iri))