Skip to content

Using template variables to construct new values

timrdf edited this page May 28, 2011 · 86 revisions

See conversion:Enhancement.

What variables can be used in templates?

Global variables:

  • [/] - base_uri/
  • [/s] - base_uri/source/source_identifier
  • [/sd] - base_uri/source/source_identifier/dataset/dataset_identifier
  • [/sdv] - base_uri/source/source_identifier/dataset/dataset_identifier/version/dataset_version
  • [e] - the dataset's enhancement_identifier
  • [/sD] - base_uri/source/source_identifier/dataset/dataset_identifier[/subjectDiscriminator]
  • [/sDv] - base_uri/source/source_identifier/dataset/dataset_identifier[/subjectDiscriminator]/version/dataset_version

Contextual:

  • [@] - the local name of this property
  • [r] - the row of this value
  • [c] - the column of this value
  • [.] - the value of the cell; empty value proceeds without special processing or omission. (implemented as [+])
  • [+] - the value of the cell; if empty, provide unique non-empty value. (not implemented)
  • [!] - the value of the cell; if empty, omit any triple using template.
  • [#N] - the value of this row at column N
  • [@PROPERTY_NAME] - the value of this row at column whose output property will be PROPERTY_NAME (undefined when multiple columns are consolidated to a single predicate).

Operators:

  • ^ - upper case a value; e.g. [^.^] and [^#1^]
  • _ - lower case a value; e.g. [_._] and [_#1_]
  • ^_ - capitalize first letter of value
  • >< - apply replaceAll("[^a-zA-Z_0-9\\-]","_") and while(gsub(/__/,"_")) (Note: this is [done by default](On Identity) when constructing URIs and will be implemented if we need to relax that assumption).

Regex Contextual:

Contextual (not implemented yet):

  • [H] - the original header
  • [L] - the conversion:label of this property
  • [D] - domain of this property
  • [R] - range of this property

Experimental:

  • [#H+1] - the value of the cell one below the header of the current column (i.e., [c])
  • [#H+2] - the value of the cell two below the header of the current column (i.e., [c])

Default templates

(informative)

  • [/sdv]thing_[r] - the URI for the row
  • [/sd]value-of/[@]/[.] - the URI for a cell predicate-scoped promoted
  • [/sd]typed/[R]/[.] - the URI for a cell type-promoted

What datasets use Templates?

Datasets in http://logd.tw.rpi.edu/sparql that use templates (results):

prefix conversion: <http://purl.org/twc/vocab/conversion/>
prefix ov:         <http://open.vocab.org/terms/>
    
select ?p ?o count(?o) as ?count
where {
  graph <http://purl.org/twc/vocab/conversion/ConversionProcess>  {
    ?s ov:csvCol ?col; ?p ?o .
    filter (?p != (conversion:label))           # templates to name predicate are not recognized.
    filter (?p != (conversion:comment))         # templates in predicate comments are not recognized.
    filter (?p != (conversion:delimits_object)) # delimits_object specifies a pattern, not template.
    filter (?p != (conversion:key_template))    # key_template is DEPRECATED; replaced by domain_template.
    filter regex(?p, "^http://purl.org/twc/vocab/conversion/.*")
    filter regex(?o, ".*\\[.*\\]") # NOTE: This string is not correctly rendered.
  }
} group by ?p ?o order by ?p ?o desc(?count) 

conversion: predicates that accept templates

See also

See also Patterns versus Templates.

Java implementation

The comments on edu.rpi.tw.data.csv.impl.CSVRecordTemplateFiller list the template variables and their behavior.

The following methods implement the template filling:

  • edu.rpi.tw.data.csv.impl.DefaultEnrichmentParameters#fillTemplate fills the namespace-type variables [/] etc.
  • edu.rpi.tw.data.csv.impl.CSVRecordTemplateFiller#fillTemplate(String) fills the row-contextual variables [@p], [#3], [r], [c], etc.
  • edu.rpi.tw.data.csv.valuehandlers.LiteralCodebookValueHandler fills the regex capture groups on its own.

Issues

https://github.com/timrdf/csv2rdf4lod-automation/issues/issue/13

Clone this wiki locally