Swirrl / csv2rdf

Clojure library and command line application for converting CSV to RDF. An implementation of the W3C CSVW specifications
Eclipse Public License 1.0
26 stars 6 forks source link

Ability to use local table.json when @base is set #256

Open AlasdairGray opened 1 year ago

AlasdairGray commented 1 year ago

When @base is set in the .json metadata file, you cannot use a local table.json file since csv2rdf attempts to resolve the location of the tableSchema property based on the @base value.

If we include the table definitions directly within the .csv-metadata.json file, then running the following command generates the desired output.

csv2rdf -u age.csv-metadata.json -o age.ttl -t age.csv -m annotated

If instead we try to reference a local table.json file in the tableSchema property, then running the following command generates an error as csv2rdf attempts to resolve the location of the generated URL.

csv2rdf -u age-table.json.csv-metadata.json -o age.ttl -t age.csv -m annotated

Error report

#error {
 :cause Error at path ["tableSchema"]: Failed to resolve linked object property at URI http://statistics.gov.scot/def/concept-scheme/age.table.json: clj-http: status 404
 :data {:type :bad-metadata, :path [tableSchema]}
 :via
 [{:type clojure.lang.ExceptionInfo
   :message Error at path ["tableSchema"]: Failed to resolve linked object property at URI http://statistics.gov.scot/def/concept-scheme/age.table.json: clj-http: status 404
   :data {:type :bad-metadata, :path [tableSchema]}
   :at [clojure.core$ex_info invokeStatic core.clj 4739]}]
 :trace
 [[clojure.core$ex_info invokeStatic core.clj 4739]
  [clojure.core$ex_info invoke core.clj 4739]
  [csv2rdf.metadata.validator$make_error invokeStatic validator.clj 17]
  [csv2rdf.metadata.validator$make_error invoke validator.clj 16]
  [csv2rdf.metadata.types$resolve_linked_object_property_object invokeStatic types.clj 382]
  [csv2rdf.metadata.types$resolve_linked_object_property_object invoke types.clj 378]
  [csv2rdf.metadata.types$linked_object_property$fn__1700 invoke types.clj 386]
  [csv2rdf.metadata.validator$chain$fn__1298$fn__1299 invoke validator.clj 99]
  [csv2rdf.metadata.validator$variant$v__1304 invoke validator.clj 120]
  [csv2rdf.metadata.validator$variant$v__1304 invoke validator.clj 117]
  [csv2rdf.metadata.validator$optional_key$fn__1325 invoke validator.clj 166]
  [csv2rdf.metadata.validator$kvps$fn__1330$fn__1331 invoke validator.clj 184]
  [clojure.core$map$fn__5587 invoke core.clj 2747]
  [clojure.lang.LazySeq sval LazySeq.java 40]
  [clojure.lang.LazySeq seq LazySeq.java 49]
  [clojure.lang.RT seq RT.java 528]
  [clojure.core$seq__5124 invokeStatic core.clj 137]
  [clojure.core$filter$fn__5614 invoke core.clj 2801]
  [clojure.lang.LazySeq sval LazySeq.java 40]
  [clojure.lang.LazySeq seq LazySeq.java 49]
  [clojure.lang.Cons next Cons.java 39]
  [clojure.lang.RT next RT.java 706]
  [clojure.core$next__5108 invokeStatic core.clj 64]
  [clojure.core.protocols$fn__7852 invokeStatic protocols.clj 169]
  [clojure.core.protocols$fn__7852 invoke protocols.clj 124]
  [clojure.core.protocols$fn__7807$G__7802__7816 invoke protocols.clj 19]
  [clojure.core.protocols$seq_reduce invokeStatic protocols.clj 31]
  [clojure.core.protocols$fn__7835 invokeStatic protocols.clj 75]
  [clojure.core.protocols$fn__7835 invoke protocols.clj 75]
  [clojure.core.protocols$fn__7781$G__7776__7794 invoke protocols.clj 13]
  [clojure.core$reduce invokeStatic core.clj 6748]
  [clojure.core$into invokeStatic core.clj 6815]
  [clojure.core$into invoke core.clj 6807]
  [csv2rdf.metadata.validator$kvps$fn__1330 invoke validator.clj 186]
  [csv2rdf.metadata.types$validate_object_of$fn__1665 invoke types.clj 293]
  [csv2rdf.metadata.validator$variant$v__1304 invoke validator.clj 120]
  [csv2rdf.metadata.validator$variant$v__1304 invoke validator.clj 117]
  [csv2rdf.metadata.types$validate_contextual_object$fn__1692 invoke types.clj 373]
  [csv2rdf.metadata.validator$variant$v__1304 invoke validator.clj 120]
  [csv2rdf.metadata.validator$variant$v__1304 invoke validator.clj 117]
  [csv2rdf.metadata.table$parse_table_json invokeStatic table.clj 41]
  [csv2rdf.metadata.table$parse_table_json invoke table.clj 40]
  [csv2rdf.metadata$parse_metadata_json invokeStatic metadata.clj 17]
  [csv2rdf.metadata$parse_metadata_json invoke metadata.clj 10]
  [csv2rdf.metadata$parse_table_group_from_source invokeStatic metadata.clj 23]
  [csv2rdf.metadata$parse_table_group_from_source invoke metadata.clj 21]
  [csv2rdf.tabular.processing$from_metadata_source invokeStatic processing.clj 21]
  [csv2rdf.tabular.processing$from_metadata_source invoke processing.clj 20]
  [csv2rdf.tabular.processing$get_metadata invokeStatic processing.clj 33]
  [csv2rdf.tabular.processing$get_metadata invoke processing.clj 27]
  [csv2rdf.csvw$csv__GT_rdf invokeStatic csvw.clj 32]
  [csv2rdf.csvw$csv__GT_rdf invoke csvw.clj 23]
  [csv2rdf.csvw$csv__GT_rdf__GT_destination invokeStatic csvw.clj 46]
  [csv2rdf.csvw$csv__GT_rdf__GT_destination invoke csvw.clj 41]
  [csv2rdf.main$write_output invokeStatic main.clj 56]
  [csv2rdf.main$write_output invoke main.clj 54]
  [csv2rdf.main$inner_main invokeStatic main.clj 82]
  [csv2rdf.main$inner_main invoke main.clj 72]
  [csv2rdf.main$_main invokeStatic main.clj 87]
  [csv2rdf.main$_main doInvoke main.clj 85]
  [clojure.lang.RestFn applyTo RestFn.java 137]
  [csv2rdf.main main nil -1]]}

The zip file includes the csv file and the different configuration files:
age-example.zip

AlasdairGray commented 1 year ago

The -t flag allows us to pass a local csv file. Could a similar approach be adopted for the table.json files?

@RickMoynihan has suggested that this would need to point to a directory in which one or more table.json files exist.