Skip to content

Namespace prefix handling

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

What is first

What we will cover

Let's get to it

Reading URIs is almost always easier when viewing them as CURIEs (aka QNames, like in XML). e.g., instead of:

<http://logd.tw.rpi.edu/source/visualizing-org/dataset/2010-global-agenda-council-interlinkage-survey/interlinkagesurveydata-metadata/typed/country/> 
   <http://purl.org/dc/terms/> "Ecosystems & Biodiversity" .

we get:

typed_council:Ecosystems_Biodiversity dcterms:identifier "Ecosystems & Biodiversity" .

Although an essential contributor to human readability, namespace abbreviations are not a fundamental part of RDF. Although RDF/XML and Turtle permit prefix declarations, passing the model through the N-TRIPLEs syntax will lose it all. In csv2rdf4lod, we do as much as we can to preserve this implicit and under-appreciated bit of knowledge.

We do it in three ways:

  • By recognizing and reusing any prefix declarations you provide in the parameters
  • By defining good prefixes for namespaces that the converter creates and uses
  • By encoding those abbreviations explicitly into the converted RDF output

Recognizing and reusing any prefix declarations you provide in the parameters

Prefix declarations are recognized in two forms. The first works for Turtle input files, while the second works for any input syntax.

By adding prefixes into the parameters Turtle file

:term_Mapping_2
   owl:annotatedTarget <http://knoesis.wright.edu/provenir/provenir.owl#process> ;

add:

@prefix provenir:   <http://knoesis.wright.edu/provenir/provenir.owl#> .

result:

:term_Mapping_2
   owl:annotatedTarget provenir:process ;

By encoding it as actual parameters

Since prefix definitions get squashed in some belligerent RDF syntaxes, it is helpful to encode it in the RDF itself:

:dataset conversion:conversion_process [
   conversion:interpret [                       
      vann:preferredNamespacePrefix "provenir";    
      vann:preferredNamespaceUri    "http://knoesis.wright.edu/provenir/provenir.owl#"; 
   ];                                           
] .

Note either of these approaches is sufficient to achieve the same abbreviated result.

Encoding those abbreviations explicitly into the RDF output of the conversion

VANN's vann:preferredNamespacePrefix/vann:preferredNamespaceUri pairs are included in the conversion output, so they can persist. A nice consequent of this is being able to query any named graph for its prefix abbreviations:

PREFIX vann:    <http://purl.org/vocab/vann/>

CONSTRUCT {
 ?s vann:preferredNamespacePrefix ?prefix; vann:preferredNamespaceUri ?ns
}
WHERE {
 GRAPH <http://logd.tw.rpi.edu/source/epa-gov-mcmahon-ethan/dataset/environmental-reports/version/2011-Jan-12>  {
  ?s vann:preferredNamespacePrefix ?prefix; vann:preferredNamespaceUri ?ns
 }
}

See Aggregating subsets of converted datasets for more queries against aggregated datasets.

results

PREFIX vann:       <http://purl.org/vocab/vann/>
PREFIX conversion: <http://purl.org/twc/vocab/conversion/>

SELECT distinct ?namespace ?prefix
WHERE {
  GRAPH <http://logd.tw.rpi.edu/vocab/Dataset>  {
    [] vann:preferredNamespacePrefix ?prefix;
       vann:preferredNamespaceUri    ?namespace
  }
} order by ?namespace ?prefix

Default prefixes for a new Turtle file

cr-default-prefixes.sh prints the prefixes commonly used.

bash-3.2$ cr-default-prefixes.sh
prefix rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs:       <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd:        <http://www.w3.org/2001/XMLSchema#>
prefix owl:        <http://www.w3.org/2002/07/owl#>
prefix wgs:        <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix dcterms:    <http://purl.org/dc/terms/>
prefix doap:       <http://usefulinc.com/ns/doap#>
prefix foaf:       <http://xmlns.com/foaf/0.1/>
prefix skos:       <http://www.w3.org/2004/02/skos/core#>
prefix sioc:       <http://rdfs.org/sioc/ns#>
prefix dcat:       <http://www.w3.org/ns/dcat#>
prefix void:       <http://rdfs.org/ns/void#>
prefix ov:         <http://open.vocab.org/terms/>
prefix frbr:       <http://purl.org/vocab/frbr/core#>
prefix qb:         <http://purl.org/linked-data/cube#>
prefix sd:         <http://www.w3.org/ns/sparql-service-description#>
prefix moby:       <http://www.mygrid.org.uk/mygrid-moby-service#>
prefix conversion: <http://purl.org/twc/vocab/conversion/>
prefix datafaqs:   <http://purl.org/twc/vocab/datafaqs#>
prefix dbpedia:    <http://dbpedia.org/resource/>
prefix prov:       <http://www.w3.org/ns/prov#>
prefix nfo:        <http://www.semanticdesktop.org/ontologies/nfo/#>
prefix sio:        <http://semanticscience.org/resource/>
prefix org:        <http://www.w3.org/ns/org#>
prefix vsr:        <http://purl.org/twc/vocab/vsr#>
prefix pml:        <http://provenanceweb.org/ns/pml#>
prefix twi:        <http://tw.rpi.edu/instances/>

bash-3.2$ cr-default-prefixes.sh --turtle
@prefix rdf:        <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:       <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:        <http://www.w3.org/2001/XMLSchema#> .
@prefix owl:        <http://www.w3.org/2002/07/owl#> .
@prefix wgs:        <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix dcterms:    <http://purl.org/dc/terms/> .
@prefix doap:       <http://usefulinc.com/ns/doap#> .
@prefix foaf:       <http://xmlns.com/foaf/0.1/> .
@prefix skos:       <http://www.w3.org/2004/02/skos/core#> .
@prefix sioc:       <http://rdfs.org/sioc/ns#> .
@prefix dcat:       <http://www.w3.org/ns/dcat#> .
@prefix void:       <http://rdfs.org/ns/void#> .
@prefix ov:         <http://open.vocab.org/terms/> .
@prefix frbr:       <http://purl.org/vocab/frbr/core#> .
@prefix qb:         <http://purl.org/linked-data/cube#> .
@prefix sd:         <http://www.w3.org/ns/sparql-service-description#> .
@prefix moby:       <http://www.mygrid.org.uk/mygrid-moby-service#> .
@prefix conversion: <http://purl.org/twc/vocab/conversion/> .
@prefix datafaqs:   <http://purl.org/twc/vocab/datafaqs#> .
@prefix dbpedia:    <http://dbpedia.org/resource/> .
@prefix prov:       <http://www.w3.org/ns/prov#> .
@prefix nfo:        <http://www.semanticdesktop.org/ontologies/nfo/#> .
@prefix sio:        <http://semanticscience.org/resource/> .
@prefix org:        <http://www.w3.org/ns/org#> .
@prefix vsr:        <http://purl.org/twc/vocab/vsr#> .
@prefix pml:        <http://provenanceweb.org/ns/pml#> .
@prefix twi:        <http://tw.rpi.edu/instances/> .

rdf2ttl.sh

rdf2ttl.sh uses the prefixes from prefix.cc to create a Turtle file from RDF/XML, N-Triples.

What is next

Clone this wiki locally