about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--transform/special-forms.scm41
1 files changed, 37 insertions, 4 deletions
diff --git a/transform/special-forms.scm b/transform/special-forms.scm
index ddb3180..8de4966 100644
--- a/transform/special-forms.scm
+++ b/transform/special-forms.scm
@@ -1,5 +1,6 @@
 (define-module (transform special-forms)
   #:use-module (srfi srfi-1)
+  #:use-module (ice-9 regex)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-26)
   #:use-module (transform sql)
@@ -18,8 +19,39 @@
             syntax-let
             map-alist
 	    with-documentation
+            emit-short-turtle
             define-transformer))
 
+(define (emit-short-turtle subject po-alist)
+  (let loop ((pairs po-alist) (first? #t))
+    (match pairs
+      (((p . o) rest ...)
+       ;; subject only on first line
+       (when first?
+         (format #t "~a " subject))
+       (when (not first?)
+         (format #t "\t"))   ; indent following lines
+
+       (match o
+         ((? symbol?)
+          (format #t "~a ~a" p (symbol->string o)))
+         ((or (? (lambda (el) (and (string? el)
+                                   (string-match "^\\(.*\\)$" el))))
+              (? (lambda (el) (and (string? el)
+                                   (string-match "^\\[.*\\]$" el)))))
+          (format #t "~a ~s" p o))
+         (_
+          (format #t "~a \"~a\"" p o)))
+
+       (if (null? rest)
+           (format #t " .~%")   ; last triple
+           (format #t " ;~%"))  ; continuation
+
+       (loop rest #f))
+
+      (() #f))))
+
+
 (define (key->assoc-ref alist x)
   "Recursively translate (key k) forms in source X to (assoc-ref ALIST
 k) forms."
@@ -505,10 +537,11 @@ The above query results to triples that have the form:
                                 (list 'triple-predicate ...)
                                 (list 'triple-object ...)))
                    (_ (error "Invalid schema triples clause:" #'schema-triples-clause)))
-	       (sql-for-each (lambda (row)
-                               (scm->triples
-                                (map-alist row #,@(field->key #'(predicate-clauses ...)))
-                                #,(field->assoc-ref #'row #'subject)))
+	       (sql-for-each  (lambda (row)
+                                (let* ((subject-val #,(field->assoc-ref #'row #'subject))
+                                       (po-alist
+                                        (map-alist row #,@(field->key #'(predicate-clauses ...)))))
+                                  (emit-short-turtle subject-val po-alist)))
                              db
                              (select-query #,(collect-fields #'(subject predicate-clauses ...))
                                            (primary-table other-tables ...)