Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command line argument to specify the base uri #349

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/csv2rdf/csvw.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
like `:minimal`, but it also includes RDF data from the CSVW metadata
json file."
([tabular-source metadata-source] (csv->rdf tabular-source metadata-source {}))
([tabular-source metadata-source {:keys [mode] :as options}]
([tabular-source metadata-source {:keys [mode base-uri]}]
(let [mode (or mode :standard)
{:keys [tables] :as metadata} (processing/get-metadata tabular-source metadata-source)
{:keys [tables] :as metadata} (processing/get-metadata tabular-source metadata-source base-uri)
table-group-dialect (:dialect metadata)
output-tables (remove properties/suppress-output? tables)
{:keys [statements] :as ctx} (table-group-context mode metadata)
Expand Down
11 changes: 7 additions & 4 deletions src/csv2rdf/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[["-t" "--tabular TABULAR" "Location of the tabular file"]
["-u" "--user-metadata METADATA" "Location of the metadata file"]
["-o" "--output-file OUTPUT" "Output file to write to"]
["-b" "--base-uri URI" "The base uri to use"]
["-m" "--mode MODE" "CSVW mode to run"
:validate [#(contains? #{:minimal :standard :annotated} %)]
:default :standard
Expand Down Expand Up @@ -51,9 +52,10 @@
:summary summary}))
options)))

(defn- write-output [writer {:keys [rdf-format tabular-source metadata-source mode]}]
(defn- write-output [writer {:keys [rdf-format tabular-source metadata-source mode base-uri]}]
(let [dest (gio/rdf-writer writer :format rdf-format :prefixes nil)]
(csvw/csv->rdf->destination tabular-source metadata-source dest {:mode mode})))
(csvw/csv->rdf->destination tabular-source metadata-source dest {:mode mode
:base-uri base-uri})))

(defmulti display-error
"Displays an exception in the UI"
Expand All @@ -71,11 +73,12 @@

(defn- inner-main [args]
(let [options (parse-cli-options args)
{:keys [mode tabular user-metadata output-file]} options
{:keys [mode tabular user-metadata output-file base-uri]} options
opts {:tabular-source (some-> tabular parse-source)
:metadata-source (some-> user-metadata parse-source)
:rdf-format (or (some-> output-file formats/->rdf-format) RDFFormat/TURTLE)
:mode mode}
:mode mode
:base-uri (some-> base-uri (URI.))}
output-file (some-> output-file io/file)]
(if output-file
(with-open [w (io/writer output-file)]
Expand Down
7 changes: 2 additions & 5 deletions src/csv2rdf/metadata.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@

:else (make-error context "Expected top-level of metadata document to describe a table or table group"))))

(defn parse-table-group-from-source [source]
(defn parse-table-group-from-source [source base-uri]
(let [json (source/get-json source)]
(parse-metadata-json (source/->uri source) json)))

(s/fdef parse-table-group-from-source
:args (s/cat :source (s/and ::source/uriable ::source/json-source)))
(parse-metadata-json (or base-uri (source/->uri source)) json)))

(defn ^{:tabular-spec "5.1"} overriding-metadata
"Construct an 'overriding metadata' document if the user provides both tabular and
Expand Down
11 changes: 6 additions & 5 deletions src/csv2rdf/tabular/processing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
(table/validate-compatible validating? user-table table-metadata)
(table/compatibility-merge user-table table-metadata)))

(defn- from-metadata-source [metadata-source]
(let [{:keys [tables] :as user-table-group} (meta/parse-table-group-from-source metadata-source)
(defn- from-metadata-source [metadata-source base-uri]
(let [{:keys [tables] :as user-table-group} (meta/parse-table-group-from-source metadata-source base-uri)
validating? false
merged-tables (mapv (fn [table] (validate-merge-table validating? table)) tables)
merged-table-group (assoc user-table-group :tables merged-tables)]
(set-table-group-parents merged-table-group)))

(defn ^{:tabular-spec "6.1"} get-metadata

"Retrieves and resolves the metadata given either a tabular data source or metadata source. If user metadata
is provided, each referenced table definition is validated against the corresponding tabular data file."
[tabular-source metadata-source]
[tabular-source metadata-source base-uri]
(cond
(and (some? tabular-source) (some? metadata-source))
(from-metadata-source (meta/overriding-metadata tabular-source metadata-source))
(from-metadata-source (meta/overriding-metadata tabular-source metadata-source) base-uri)

(some? metadata-source)
(from-metadata-source metadata-source)
(from-metadata-source metadata-source base-uri)

(some? tabular-source)
(from-tabular-source tabular-source)
Expand Down