aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdump.scm44
-rw-r--r--dump/triples.scm48
2 files changed, 49 insertions, 43 deletions
diff --git a/dump.scm b/dump.scm
index 8e2057e..295bf1e 100755
--- a/dump.scm
+++ b/dump.scm
@@ -9,6 +9,7 @@
(ice-9 string-fun)
(dump sql)
(dump table)
+ (dump triples)
(dump utils))
@@ -101,20 +102,6 @@ association list mapping substrings to their replacements."
str
replacement-alist))
-(eval-when (expand load eval)
- (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 #\.)))))))
-
-
(define (snake->lower-camel str)
(let ((char-list (string->list str)))
(call-with-output-string
@@ -128,32 +115,6 @@ characters with an underscore and prefixing with gn:PREFIX."
(drop char-list 1)
char-list)))))
-(define (scm->triples alist id)
- (for-each (match-lambda
- ((predicate . object)
- (when (cond
- ((string? object)
- (not (string-blank? object)))
- (else object))
- (triple id predicate object))))
- alist))
-
-(define (triple subject predicate object)
- (unless (or (string? subject)
- (symbol? subject))
- (error "Triple subject not a string or symbol:"
- (list subject predicate object)))
- (unless (or (string? predicate)
- (symbol? predicate))
- (error "Triple predicate not a string or symbol:"
- (list subject predicate object)))
- (unless (or (string? object)
- (symbol? object)
- (number? object))
- (error "Triple object not a string, symbol or number:"
- (list subject predicate object)))
- (format #t "~a ~a ~s .~%" subject predicate object))
-
(eval-when (expand load eval)
(define (field->key x)
(translate-forms 'field
@@ -809,9 +770,6 @@ is a <table> object."
;; Main function
-(define (prefix prefix iri)
- (format #t "@prefix ~a ~a .~%" prefix iri))
-
(call-with-genenetwork-database
(lambda (db)
(with-output-to-file (string-append %dump-directory "/dump.ttl")
diff --git a/dump/triples.scm b/dump/triples.scm
new file mode 100644
index 0000000..bb2acdc
--- /dev/null
+++ b/dump/triples.scm
@@ -0,0 +1,48 @@
+(define-module (dump triples)
+ #:use-module (ice-9 match)
+ #:use-module (dump utils)
+ #:export (string->identifier
+ prefix
+ triple
+ scm->triples))
+
+(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 #\.))))))
+
+(define (prefix prefix iri)
+ (format #t "@prefix ~a ~a .~%" prefix iri))
+
+(define (triple subject predicate object)
+ (unless (or (string? subject)
+ (symbol? subject))
+ (error "Triple subject not a string or symbol:"
+ (list subject predicate object)))
+ (unless (or (string? predicate)
+ (symbol? predicate))
+ (error "Triple predicate not a string or symbol:"
+ (list subject predicate object)))
+ (unless (or (string? object)
+ (symbol? object)
+ (number? object))
+ (error "Triple object not a string, symbol or number:"
+ (list subject predicate object)))
+ (format #t "~a ~a ~s .~%" subject predicate object))
+
+(define (scm->triples alist id)
+ (for-each (match-lambda
+ ((predicate . object)
+ (when (cond
+ ((string? object)
+ (not (string-blank? object)))
+ (else object))
+ (triple id predicate object))))
+ alist))