X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=create-sql.lisp;h=9311a820bc3980804a7e94ca9faf11677c23f1e0;hb=9e472725307c8f98e1590814b0cb77c62cf5dc14;hp=83c1a22e65bc28aaca13f13967682dc21b6a0829;hpb=a418a83108a16eb76ce432a2f781a572406ec0c3;p=umlisp.git diff --git a/create-sql.lisp b/create-sql.lisp index 83c1a22..9311a82 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)) @@ -208,9 +208,10 @@ (format nil "DROP INDEX ~a" (concatenate 'string tablename "_" colname "_X"))))) -(defun sql-create-indexes (conn &optional (indexes +index-cols+)) +(defun sql-create-indexes (conn &key (indexes +index-cols+) verbose) "SQL Databases: create all indexes" (dolist (idx indexes) + (when verbose (format t "UMLS Import: Creating index ~S.~%" idx)) (ignore-errors (sql-execute (drop-index-cmd (car idx) (cadr idx)) conn)) (sql-execute (create-index-cmd (car idx) (cadr idx) (caddr idx)) conn))) @@ -229,7 +230,7 @@ (make-usrl conn) (make-ustats)) -(defun create-umls-db-by-insert () +(defun create-umls-db-by-insert (&key verbose) "SQL Databases: initializes entire database via SQL insert commands" (ensure-ucols+ufiles) (ensure-preparse) @@ -239,16 +240,19 @@ (sql-insert-all-values conn) (sql-create-indexes conn) (sql-create-custom-tables conn) - (sql-create-indexes conn +custom-index-cols+) + (sql-create-indexes conn :indexes +custom-index-cols+ :verbose verbose) (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 - (translate-all-files extension)) + (when verbose (format t "UMLS Import: Converting text UMLS files to optimized format.~%")) + (translate-all-files :extension extension :verbose verbose)) (let ((copy-cmd (ecase (umls-sql-type) (:mysql #'mysql-copy-cmd) @@ -258,17 +262,24 @@ 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)) - (sql-create-indexes conn) + (When verbose (format t "UMLS Import: Creating SQL indices.~%")) + (sql-create-indexes conn :verbose verbose) + (When verbose (format t "UMLS Import: Creating custom tables.~%")) (sql-create-custom-tables conn) - (sql-create-indexes conn +custom-index-cols+) + (When verbose (format t "UMLS Import: Creating custom indices.~%")) + (sql-create-indexes conn :indexes +custom-index-cols+ :verbose verbose) + (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")) - "Copy translated files and return postgresql copy commands to import" +(defun translate-all-files (&key (extension "-trans") verbose) + "Translate all *umls-files* to optimized import format." (make-noneng-index-file extension) (dolist (f (remove "MRXW_NONENG.RRF" *umls-files* :test #'string= :key #'fil)) + (when verbose (format t "UMLS Import: translating file ~S.~%" f)) (translate-umls-file f extension))) (defun translate-umls-file (file extension) @@ -295,13 +306,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) @@ -309,6 +317,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)