X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=create-sql.lisp;h=1440fd32911e755fc16da94c974021cf8e644c2c;hb=fe0f8af77c3bc5bb58c1cc0ab3701688fa8089a8;hp=f2762861637a5422dc055db70f43fecc5bbaf844;hpb=6ebaa3627ee89b8f7f429ebcd01c4dc8d9892e0b;p=umlisp.git diff --git a/create-sql.lisp b/create-sql.lisp index f276286..1440fd3 100644 --- a/create-sql.lisp +++ b/create-sql.lisp @@ -128,7 +128,7 @@ (format nil " (~d)" length) ""))) ((:postgresql :postgresql-socket) - ;; FIXME: incorrect syntax + ;; FIXME: incorrect syntax for postgresql? (if (integerp length) (format nil "substr((~A)::text,1,~D)" colname length) colname)) @@ -169,6 +169,8 @@ (:oracle "NUMBER(2,0)") (t "INTEGER"))) :database conn) + ;; KCON deprecated by KPFENG field in MRCONSO + #+nil (dolist (tuple (query "select distinct cui from MRCONSO order by cui" :database conn)) (let ((cui (car tuple))) @@ -240,12 +242,15 @@ (sql-create-indexes conn +custom-index-cols+) (sql-create-special-tables conn))) -(defun create-umls-db (&key (extension ".trans") (skip-translation nil)) +(defun create-umls-db (&key (extension "-trans") (skip-translation nil) (verbose nil)) "SQL Databases: initializes entire database via SQL copy commands. This is much faster that using create-umls-db-insert." + (when verbose (format t "UMLS Import: Starting.~%")) (ensure-ucols+ufiles) + (when verbose (format t "UMLS Import: Preparsing files.~%")) (ensure-preparse) (unless skip-translation + (when verbose (format t "UMLS Import: Converting text UMLS files to optimized format.~%")) (translate-all-files extension)) (let ((copy-cmd (ecase (umls-sql-type) @@ -256,13 +261,20 @@ This is much faster that using create-umls-db-insert." (sql-drop-tables conn) (sql-create-tables conn) (dolist (file *umls-files*) + (when verbose (format t "UMLS Import: Importing file ~A.~%" file)) (sql-execute (funcall copy-cmd file extension) conn)) + (When verbose (format t "UMLS Import: Creating SQL indices.~%")) (sql-create-indexes conn) + (When verbose (format t "UMLS Import: Creating custom tables.~%")) (sql-create-custom-tables conn) + (When verbose (format t "UMLS Import: Creating custom indices.~%")) (sql-create-indexes conn +custom-index-cols+) - (sql-create-special-tables conn)))) + (When verbose (format t "UMLS Import: Creating special tables.~%")) + (sql-create-special-tables conn))) + (When verbose (format t "UMLS Import: Completed.~%")) + t) -(defun translate-all-files (&optional (extension ".trans")) +(defun translate-all-files (&optional (extension "-trans")) "Copy translated files and return postgresql copy commands to import" (make-noneng-index-file extension) (dolist (f (remove "MRXW_NONENG.RRF" *umls-files* :test #'string= :key #'fil)) @@ -292,13 +304,10 @@ This is much faster that using create-umls-db-insert." (incf translated-lines))) (dolist (input-ufile input-ufiles) (with-umls-ufile (line input-ufile) - (incf input-lines) - (when (> input-lines translated-lines) - (throw 'done-counting 'incomplete))))) + (incf input-lines) + (when (> input-lines translated-lines) + (throw 'done-counting 'incomplete))))) (cond - ((eql input-lines 0) - (error "Input lines is 0") - nil) ((< input-lines translated-lines) (format t "Translated file ~A incomplete, deleting...~%" output-path) (delete-file output-path) @@ -306,6 +315,9 @@ This is much faster that using create-umls-db-insert." ((eql input-lines translated-lines) (format t "Translated file ~A already exists: skipping...~%" output-path) t) + ((eql input-lines 0) + (warn "The number of input lines is 0 for output file ~A." output-path) + nil) ((> translated-lines input-lines) (error "Shouldn't happen. Translated lines of ~A is ~D, greater than input lines ~D" output-path translated-lines input-lines) @@ -345,13 +357,13 @@ This is much faster that using create-umls-db-insert." nil "COPY ~a FROM '~a' using delimiters '|' with null as ''" (table file) (ufile-pathname file extension))) -(defun mysql-copy-cmd (file extension &key local-file) +(defun mysql-copy-cmd (file extension &key (local-file t)) "Return mysql copy statement for a file" (format nil "LOAD DATA ~AINFILE \"~a\" INTO TABLE ~a FIELDS TERMINATED BY \"|\"" (if local-file "LOCAL " "") - (ufile-pathname file extension) (table file))) + (namestring (ufile-pathname file extension)) (table file))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;