Skip to content

Linked Data Templates

Martynas Jusevičius edited this page Sep 11, 2019 · 26 revisions

See the Linked Data Templates for a detailed specification of how templates are defined and executed

AtomGraph sitemap ontology contains Linked Data Templates (LDTs) expressed in RDF/OWL. Linked Data Template defines a class of document resources that:

  • their URI identifiers share the same URI pattern (match specified URI template)
  • their RDF representation was generated from the same SPARQL query

Inheritance

Template ct:Document is a built-in template, all other templates extend it by using the ldt:extends property. Extending templates inherit LDT annotation properties from super-templates, unless they override inheritance by defining their own property.

An example of a Linked Data Template that extends built-in container template and overrides its properties:

:LabelResources a ldt:Template ;
    ldt:extends ct:Document ;
    ldt:match "/resources/labelled" ;
    ldt:query :DescribeLabelResources ;
    ldt:param :LabelParam ;
    rdfs:label "Labelled resource container" ;
    rdfs:isDefinedBy : .

URI templates

AtomGraph Processor is using the JAX-RS @Path URI template syntax, which is based on Java-style regexp pattern. JAX-RS defines a priority algorithm which LDT is using to select the best match even if the request URI is matching multiple templates. For example, more specific /resources/labelled takes precedence over the catch-all /{path: .*}.

Query templates

LDT template's URI template is defined using the ldt:path property. In the above example its value is /resources/labelled.

AtomGraph Processor is using TopBraid SPIN API to store and manage SPARQL queries as RDF. Queries are instances of SPIN query class, e.g. of sp:Describe or sp:Construct. For example:

:DescribeLabelResources a sp:Describe ;
      sp:text """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dct:  <http://purl.org/dc/terms/>

DESCRIBE ?this ?resource WHERE {
    {
        SELECT ?resource
        WHERE {
            ?resource rdfs:label|dct:title ?label .
            FILTER isURI(?resource) .
        }
    } .
}"""^^xsd:string ;
    rdfs:isDefinedBy : .

SPIN also allows using instances of SPIN Templates wherever a query is expected (they are known as "template calls").

Read more about SPIN - SPARQL Inferencing Notation.

Parameters

:LabelParam a ldt:Parameter ;
    rdfs:label "Label parameter" ;
    spl:predicate :label ;
    spl:optional true ;
    rdfs:isDefinedBy : .

Query bindings

Like in SPIN API, ?this variable has a special meaning in AtomGraph. When processing SPARQL query, LDT always sets values to the following variables:

?this
the absolute URI of the request (excluding query string)

For example, if a template is with a query DESCRIBE ?this, what will be executed is DESCRIBE <http://localhost:8080/> if request to http://localhost:8080 matches this template.

Moreover, template parameter arguments become query bindings as well.

Execution

Lets consider our :LabelResources template and assume that our LDT server's base URI is http://localhost:8080/.

During request processing in Processor, if the http://localhost:8080/resources/labelled?label=foo URI is dereferenced, the following query will be executed on the SPARQL backend:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX sioc: <http://rdfs.org/sioc/ns#>
PREFIX dc:   <http://purl.org/dc/elements/1.1/>
PREFIX dct:  <http://purl.org/dc/terms/>

DESCRIBE <http://localhost:8080/resources/labelled> ?resource WHERE {
    {
        SELECT ?resource
        WHERE {
            ?resource rdfs:label|dct:title "foo" .
            FILTER isURI(?resource) .
        }
    } .
}

As you can see, ?this has been bound to the request URI, and ?label has been bound to the argument value foo. Without the argument value present, ?label would be bound and would remain a variable.

User interface templates

For user interface support, see AtomGraph Web-Client.

Clone this wiki locally