|
18 | 18 | annotated-rows (csv/annotated-rows url table dialect)] |
19 | 19 | (table-statements context table annotated-rows))) |
20 | 20 |
|
| 21 | +(defn annotate-tables [tabular-source metadata-source] |
| 22 | + (processing/get-metadata tabular-source metadata-source)) |
| 23 | + |
| 24 | +(defn- validate-rows |
| 25 | + "Validates the CSVW schema for the given tabular file, metadata and options. |
| 26 | +
|
| 27 | + `tabular-source` and `metadata-source` can be any of the following |
| 28 | + types: |
| 29 | +
|
| 30 | + - java.io.File |
| 31 | + - java.lang.String |
| 32 | + - java.net.URI |
| 33 | + - java.nio.file.Path (including nio Paths that are inside zip filesystems) |
| 34 | +
|
| 35 | + If metadata-source is non-nil then processing will start from the |
| 36 | + asscociated metadata document, otherwise it will start from |
| 37 | + tabular-source." |
| 38 | + [tabular-source metadata-source] |
| 39 | + (let [{:keys [tables] :as metadata} (processing/get-metadata tabular-source metadata-source) |
| 40 | + table-group-dialect (:dialect metadata) |
| 41 | + output-tables (remove properties/suppress-output? tables) |
| 42 | + ;;ctx (table-group-context mode metadata) ;; TODO this might be useful later when iterating over tables |
| 43 | + ] |
| 44 | + |
| 45 | + (util/liberal-mapcat (fn [{:keys [url dialect] :as table}] |
| 46 | + ;;(validated-rows ctx table table-group-dialect) |
| 47 | + (let [dialect (or dialect table-group-dialect)] |
| 48 | + (csv/annotated-rows url table dialect))) |
| 49 | + |
| 50 | + output-tables))) |
| 51 | + |
| 52 | +(defn only-validate-schema |
| 53 | + "Only validate the data against the schemas in the metadata file, and |
| 54 | + report errors. Does not convert into RDF. |
| 55 | +
|
| 56 | + Returns a map with the key `:data-validation-errors?` set to a |
| 57 | + boolean indicating whether any schema errors occurred." |
| 58 | + [{:keys [tabular-source metadata-source]}] |
| 59 | + (let [errors? (atom false)] |
| 60 | + (doseq [{:keys [cells] row-number :source-number :as row} (validate-rows tabular-source metadata-source) |
| 61 | + {:keys [errors column-number column] :as cell} cells |
| 62 | + :when (seq errors)] |
| 63 | + (reset! errors? true) |
| 64 | + (doseq [error errors] |
| 65 | + (println (format "Row #%d col #%d (column '%s') has error: " row-number column-number (:name column)) error))) |
| 66 | + {:data-validation-errors? @errors?})) |
| 67 | + |
21 | 68 | (defn csv->rdf |
22 | 69 | "Runs the CSVW process for the given tabular or metadata data sources |
23 | 70 | and options. |
|
0 commit comments