about summary refs log tree commit diff
path: root/dump/triples.scm
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-05-15 15:21:34 +0300
committerBonfaceKilz2023-05-26 08:40:22 +0300
commit79975a5dc78daa03b43d37b3fe636265c148abc0 (patch)
tree01ac595bfc69e5b6473be944a57642acdcee36e4 /dump/triples.scm
parent7b9cd459c90db9337b4e64f0b99dbf8a4c3431bf (diff)
downloadgn-transform-databases-79975a5dc78daa03b43d37b3fe636265c148abc0.tar.gz
Re-organize dumping macros and associated functions
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
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))