#! /usr/bin/env guile !# (use-modules (ice-9 getopt-long) (transform triples) (transform schema) (transform special-forms) (transform sql) (transform table)) (define (call-with-genenetwork-database connection-settings proc) (call-with-database "mysql" (string-join (list (assq-ref connection-settings 'sql-username) (assq-ref connection-settings 'sql-password) (assq-ref connection-settings 'sql-database) "tcp" (assq-ref connection-settings 'sql-host) (number->string (assq-ref connection-settings 'sql-port))) ":") proc)) (define (transform-table-schema connection-settings db) (let ((tables (tables connection-settings db))) (for-each (lambda (table) (let ((table-id (string->identifier "table" ;; We downcase table names in ;; identifiers. So, we distinguish ;; between the user and User tables. (if (string=? (table-name table) "User") "user2" (table-name table))))) (triple table-id 'rdf:type 'gn:sqlTable) (triple table-id 'gn:name (table-name table)) (triple table-id 'gn:hasSize (string->symbol (format #f "~a" (table-size table)))) (for-each (lambda (column) (let ((column-id (column-id (table-name table) (column-name column)))) (triple column-id 'rdf:type 'gn:sqlTableField) (triple column-id 'gn:name (column-name column)) (triple column-id 'gn:sqlFieldType (column-type column)) (triple table-id 'gn:hasField column-id))) (table-columns table)))) tables))) (let* ((option-spec '((settings (single-char #\s) (value #t)) (output (single-char #\o) (value #t)) (documentation (single-char #\d) (value #t)))) (options (getopt-long (command-line) option-spec)) (settings (option-ref options 'settings #f)) (output (option-ref options 'output #f)) (documentation (option-ref options 'documentation #f)) (%connection-settings (call-with-input-file settings read))) (call-with-genenetwork-database %connection-settings (lambda (db) (with-output-to-file output (lambda () (prefix "rdf:" "") (prefix "rdfs:" "") (prefix "gn:" "") (prefix "gnc:" "") (prefix "gnt:" "") (prefix "xsd:" "") (prefix "owl:" "") (newline) (transform-table-schema %connection-settings db))))))