Skip to content

conversion:date_pattern

Tim L edited this page Aug 12, 2013 · 24 revisions
csv2rdf4lod-automation is licensed under the [Apache License, Version 2.0](https://github.com/timrdf/csv2rdf4lod-automation/wiki/License)

See conversion:Enhancement. See also conversion:datetime_pattern.

Patterns are now processed with Joda time.

conversion:date_pattern specifies how to parse a cell's literal value into a date. The pattern is specified by Java's date patterns. This only has effect when conversion:range is xsd:date.

Step 1: Change the conversion:range to xsd:date

  conversion:enhance [
     ov:csvCol         4;
     ov:csvHeader     "Completion_Date";
     conversion:label "Completion_Date";
     conversion:comment "";
     conversion:range  xsd:date;
  ];

If you run the conversion without following Step 2 (below), you will see something like this in the stderr log:

bash-3.2$ ./convert-uk-offshore-oil-wells.sh 
...
DATE FAILED: "1989-10-02" !~ 0 patterns @ :thing_2 :completion_date
...

This is telling you that the string did not match any of the zero patterns provided. So let's add some patterns!

Step 2: Add the conversion:pattern

This tells the converter how to parse the date.

  conversion:enhance [
     ov:csvCol         4;
     ov:csvHeader     "Completion_Date";
     conversion:label "Completion_Date";
     conversion:comment "";
     conversion:eg           "1989-10-02";
     conversion:pattern "yyyy-MM-dd";
     conversion:range  xsd:date;
  ];

Patterns should be specified using Java's SimpleDateFormat, whose table of variables is reproduced here:

snapshot of Java's SimpleDateFormat patterns

What patterns have been used in the wild?

results

PREFIX rdfs:       <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:        <http://www.w3.org/2001/XMLSchema#>
PREFIX conversion: <http://purl.org/twc/vocab/conversion/>

SELECT distinct ?pattern
WHERE {
  GRAPH <http://purl.org/twc/vocab/conversion/ConversionProcess> {
    ?enhancement conversion:pattern ?pattern .
  }
}

What datasets use this enhancement?

45

PREFIX rdfs:       <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:        <http://www.w3.org/2001/XMLSchema#>
PREFIX conversion: <http://purl.org/twc/vocab/conversion/>

SELECT count(distinct ?enhancement) as ?count
WHERE {
  GRAPH <http://purl.org/twc/vocab/conversion/ConversionProcess> {
    ?dataset a void:Dataset;
      conversion:conversion_process [
        conversion:enhance ?enhancement
      ]
    .
    ?enhancement conversion:pattern ?pattern .
  }
}
Clone this wiki locally