       ;; the category combined, which will be used to create edges from
       ;; the category to its values when we import the latter.
       (let [[orig-headers & orig-rows] (read-csv orig-tsv-file)
-            headers (vec (cons "corpus_cat" orig-headers))
-            rows    (vec (map #(vec (cons (str corpus "_" (first %)) %)) orig-rows))]
+            headers (cons "corpus_cat" orig-headers)
+            rows    (map #(cons (str corpus "_" (first %)) %) orig-rows)]
         (assert (= ["corpus_cat" "code" "name"] headers)
                 (str "Format error: Expected first line to contain column headers "
                      "and the two columns to be 'code' and 'name'."))
-        (csv/write-csv tsv-file (vec (cons headers rows)) :separator \tab)))))
+        (write-csv tsv-file (cons headers rows))))))
 
 (defn- modify-metadata-categories-config! [corpus config-path tsv-path]
   (spit config-path (-> metadata-categories-config-template

                     "and the two columns to be 'code' and 'name'."))
        (run-etl config-path)))))

(defn import-metadata-categories [corpus]
  (let [tsv-path    (.getPath (fs/temp-file "metadata-cats"))
        config-path (.getPath (fs/temp-file "metadata_cat_config"))]
    (modify-metadata-categories-tsv! corpus tsv-path)
    (modify-metadata-categories-config! corpus config-path tsv-path)
    (run-etl config-path)))


                   :classes [{:name "Corpus", :extends "V"}
                             {:name "MetadataCategory", :extends "V"}
                             {:name "HasMetadataCategory", :extends "E"}],
                   :indexes [{:class "Corpus", :fields ["code:string"], :type "UNIQUE"}
                             {:class "MetadataCategory", :fields ["code:string"], :type "UNIQUE"}
                             {:class "MetadataCategory", :fields ["corpus_cat:string"], :type "UNIQUE"}]}}})

(def ^:private tids-config-template
  {:config       {:log "debug"},
   :begin        [{:console
                   {:commands
                    ["CONNECT remote:localhost/Glossa admin admin;"
                     "TRUNCATE CLASS MetadataValue;"
                     "TRUNCATE CLASS HasMetadataValue;"]}}],
   :source       {:file {:path :WILL-BE-REPLACED}},
   :extractor    {:row {}},
   :transformers [{:csv {:separator "\t"}}
                  {:vertex {:class "MetadataValue"}}
                  {:edge
                   {:class                "HasMetadataValue",
                    :lookup               "MetadataCategory.corpus_cat",
                    :joinValue            :WILL-BE-REPLACED
                    :unresolvedLinkAction "ERROR"}}],
   :loader       {:orientdb
                  {:dbURL   "remote:localhost/Glossa",
                   :dbType  "graph",
                   :classes [{:name "MetadataCategory", :extends "V"}
                             {:name "MetadataValue", :extends "V"}
                             {:name "HasMetadataValue", :extends "E"}],
                   :indexes [{:class "MetadataCategory", :fields ["corpus_cat:string"], :type "UNIQUE"}]}}})

(defn- read-csv [file]
  (csv/read-csv file :separator \tab :quote \^))

(defn- write-csv [file data]
  (csv/write-csv file data :separator \tab))

(defn- run-etl [config-path]
  (let [etl-path (:oetl environ/env)]
