public
Last active

A proposal for proxy vocabularies mapped to a mix of vocabularies (using SPARQL 1.1), for use in RDFa.

  • Download Gist
rdfa_map_sparql_example.mkd
Markdown

For the basic case, given data like:

<html lang="en">
  <head><base href="http://example.org/"/></head>
  <body vocab="http://example.org/vocab#" typeof="Site" lang="sv">
    <h1 property="title">The Website</h1>
    By:
    <ul rel="author">
      <li about="/persons/doe" typeof="Person">
        <a rel="url" href="/persons/doe.html">Doe</a>
      </li>
    </ul>
  </body>
</html>

Or, in Turtle:

@prefix : <http://example.org/vocab#> .
@base <http://example.org/> .

<> a :Site;
  :title "The Website"@en;
  :author </persons/doe> .

</persons/doe> a :Person;
  :url </persons/doe.html> .

And a (site specific) proxy vocabulary (using the hypothetical "RDF map" vocabulary):

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix map: <http://www.w3.org/ns/rdf/map#> . # EXPERIMENTAL
@prefix dct: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix sioc: <http://rdfs.org/sioc/ns#> .
@prefix : <http://example.org/vocab#> .

:Site a map:ProxyClass;
  rdfs:subClassOf  sioc:Site .

:title a map:ProxyProperty;
  rdfs:subPropertyOf dct:title .

:author a map:ProxyProperty;
  rdfs:subPropertyOf dct:creator .

:Person a map:ProxyClass;
  rdfs:subClassOf  foaf:Person .

:url a map:ProxyProperty;
  rdfs:subPropertyOf foaf:homepage .

A SPARQL 1.1 query like:

PREFIX map: <http://www.w3.org/ns/rdf/map#>

CONSTRUCT {
  ?subject ?property ?value .
} WHERE {

  GRAPH <given-data> {
    ?subject ?givenProperty ?givenValue .
  }

  OPTIONAL {
    ?givenProperty a map:ProxyProperty;
      rdfs:subPropertyOf ?subProperty .
  }
  OPTIONAL {
    FILTER(?givenProperty = rdf:type)
    ?givenValue a map:ProxyClass;
      rdfs:subClassOf ?subTypeValue .
  }

  BIND(COALESCE(?subProperty, ?givenProperty) as ?property)
  BIND(COALESCE(?subTypeValue, ?givenValue) as ?value)

}

Will produce this new, mapped data out of the original:

@prefix dct: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix sioc: <http://rdfs.org/sioc/ns#> .
@base <http://example.org/> .

<> a sioc:Site;
  dct:title "The Website"@en;
  dct:creator </persons/doe> .

</persons/doe> a foaf:Person;
  foaf:homepage </persons/doe.html> .

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.