Skip to content

Linked Data Templates

Martynas Jusevičius edited this page Aug 11, 2017 · 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

Templates dh:Container and dh:Item are built-in templates, all other templates extend them by subclassing using rdfs:subClassOf property. Extending templates inherit LDT annotation properties from superclasses, unless they override inheritance by defining own property.

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

<#LabelResourcesContainer> a ldt:Template ;
    rdfs:subClassOf dh:Container ;
    ldt:path "/resources/labelled" ;
    ldt:query <#DescribeLabelResources> ;
    ldt:param [ a ldt:Argument ;
        rdfs:label "Limit" ;
        spl:predicate dh:limit ;
        spl:valueType xsd:long ;
        spl:defaultValue 20 ;
        spl:optional true
    ], [ a ldt:Argument ;
        rdfs:label "Order by" ;
        spl:predicate dh:orderBy ;
        spl:valueType xsd:string ;
        spl:optional true ;
        spl:defaultValue "title"
    ] ;
    rdfs:label "Labelled resource container" ;
    rdfs:isDefinedBy <#> .

In this example, resource's URI template is /resources/labelled, defined using ldt:path property. The template is mapped to the following SPARQL query in SPIN syntax using ldt:query property:

<#DescribeLabelResources>    a       sp:Describe ;
      sp:text """
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 ?this ?resource WHERE {
    {
        SELECT ?resource
        WHERE {
            ?resource rdfs:label|dct:title ?label .
            FILTER isURI(?resource) .
        }
    } .
}"""^^xsd:string .

During request processing in Processor, if a resource with relative URI /resources/labelled (relativized against webapp's base URI) is dereferenced, the SPIN query will be built with result modifiers set to dh:limit and dh:orderBy parameter values and executed:

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 ?this ?resource WHERE {
    {
        SELECT ?resource
        WHERE {
            ?resource rdfs:label|dct:title ?label .
            FILTER isURI(?resource) .
        }
        LIMIT 20
        ORDER BY ?label
    } .
}

URI templates

AtomGraph Processor is currently using 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

AtomGraph Processor is using TopBraid SPIN API to store and manage SPARQL queries as RDF. Queries are attached to resource classes as SPIN queries using the ldt:query property. It expects a query resource, i.e. an instance of sp:Describe or sp:Construct. 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.

Query bindings

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

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

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

User interface templates

For XSLT stylesheet support, see AtomGraph Web-Client.

Clone this wiki locally