Handle empty RRF files, add MTS2012AB
authorKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 5 Apr 2013 16:50:22 +0000 (10:50 -0600)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Fri, 5 Apr 2013 16:50:22 +0000 (10:50 -0600)
parse-common.lisp
sql.lisp

index ae7af531d762865617de025b4ad5bc2d9b998acc..b1395665b68eb612ef4de7fcfccaa16436ce2981 100644 (file)
         (gen-ucols)
         (set-ucols-for-ufiles *umls-files*)
         (ensure-field-lengths))
-      (error (e)
-             (warn "Error reading ucols+ufiles: ~A." e)
-             (setf *umls-cols* nil *umls-files* nil)
-             nil))
+    (error (e)
+      (warn "Error reading ucols+ufiles: ~A." e)
+      (setf *umls-cols* nil *umls-files* nil)
+      nil))
   t)
 
 
   "Initial colstruct field lengths for files that don't have a measurement.
 Currently, these are the LEX and NET files."
   (dolist (length-list (ufiles-field-lengths (ufiles-to-measure)))
-    (destructuring-bind (filename fields-max fields-av) length-list
+    (destructuring-bind (filename fields-max fields-av count-lines) length-list
       (let ((file (find-ufile filename)))
         (unless file
           (error "Can't find ~A filename in ufiles" filename))
-        (unless (= (length fields-max) (length (fields file)))
-          (error
-           "Number of file fields ~A not equal to field count in ufile ~S"
-           fields-max file))
-        (dotimes (i (length (fields file)))
-          (declare (fixnum i))
-          (let* ((field (nth i (fields file)))
-                 (col (find-ucol field filename)))
-            (unless col
-                (error "can't find column ~A" field))
-            (setf (cmax col) (aref fields-max i))
-            (setf (av col) (aref fields-av i))
-            (ensure-ucol-datatype col (datatype-for-colname (col col)))))))))
+        (if (zerop count-lines)
+            (warn "File ~A is empty." filename)
+            (progn
+              (unless (= (length fields-max) (length (fields file)))
+                (error
+                 "Number of file fields ~A not equal to field count in ufile ~S"
+                 fields-max file))
+            (dotimes (i (length (fields file)))
+              (declare (fixnum i))
+              (let* ((field (nth i (fields file)))
+                     (col (find-ucol field filename)))
+                (unless col
+                  (error "can't find column ~A" field))
+                (setf (cmax col) (aref fields-max i))
+                (setf (av col) (aref fields-av i))
+                (ensure-ucol-datatype col (datatype-for-colname (col col)))))))))))
 
 (defun ufiles-to-measure ()
   "Returns a list of ufiles to measure"
@@ -131,7 +134,7 @@ Currently, these are the LEX and NET files."
                                      :initial-element 0))
         (setq fields-av (make-array num-fields :element-type '(or integer float)
                                     :initial-element 0)))
-      (dotimes (i num-fields)
+      (dotimes (i (or num-fields 0))
         (declare (fixnum i))
         (let* ((str (nth i line))
                (len (length #-(and clisp unicode) str
@@ -145,9 +148,12 @@ Currently, these are the LEX and NET files."
           (when (> len (aref fields-max i))
             (setf (aref fields-max i) len))))
       (incf count-lines))
-    (dotimes (i num-fields)
-      (setf (aref fields-av i) (float (/ (aref fields-av i) count-lines))))
-    (list (fil ufile) fields-max fields-av)))
+    (dotimes (i (or num-fields 0))
+      (setf (aref fields-av i)
+            (if (plusp count-lines)
+                (float (/ (aref fields-av i) count-lines))
+                0)))
+    (list (fil ufile) fields-max fields-av count-lines)))
 
 ;;; UMLS column/file functions
 
index e1414d9d0840015702adcb18e5d22a112c1a92e6..dab38b8ba2d29bb059cacf073ca6fbcd23a0cf0b 100644 (file)
--- a/sql.lisp
+++ b/sql.lisp
@@ -21,8 +21,9 @@
       (:2006ac . "KUMLS2006AC")
       (:2006ad . "MTS2006AD")
       (:2009ab . "MTS2009AB")
-      (:2010aa . "MTS2010AA")))
-(defvar +default-umls-db+ "MTS2010AA")
+      (:2010aa . "MTS2010AA")
+      (:2012ab . "MTS2012AB")))
+(defvar +default-umls-db+ "MTS2012AB")
 
 (defun lookup-db-name (db)
   (cdr (assoc (ensure-keyword db) +umls-sql-map+)))