-
Notifications
You must be signed in to change notification settings - Fork 6
Linked Data Templates
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
One template can override and specialize another by extending (sub-classing) it and redefining its properties. Templates gp:Document
and gp:Container
are built-in templates, all other templates extend them.
An example of a Linked Data Template:
<#LabelResourcesContainer> a owl:Class, gp:Template ;
rdfs:subClassOf gp:Container ;
gp:path "/resources/labelled" ;
gp:query <#DescribeLabelResources> ;
gp:defaultLimit 20 ;
gp:defaultOrderBy "label" ;
rdfs:label "Labelled resource container" ;
rdfs:isDefinedBy <#> .
In this example, resource's URI template is /resources/labelled
, defined using gp:uriTemplate
property. The template is mapped to the following SPARQL query in SPIN syntax using gp:query
property:
<#DescribeLabelResources> a sp:Describe, sp:Query ;
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 requested, the SPIN query will be built with gp:defaultLimit
and gp:defaultOrderBy
modifier 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
} .
}
For a more detailed explanation, see our paper Linked Data Templates: Ontology-driven approach to read-write Linked Data
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 GP 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: .*}
.
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 gp: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.
Like in SPIN API, ?this
variable has a special meaning in AtomGraph. When processsing SPARQL query, GP always sets values to the following variables:
- ?this
- the URI of the request (excluding query string)
- ?baseUri
- the base URI of the application
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.
For XSLT stylesheet support, see AtomGraph Web-Client.