Change the sitemap

Change the sitemap: create queries and LDT templates

Change the sitemap

By default, the concept documents will match an Item template from the application's Templates ontology. You can verify that by checking the HTTP response headers, which should include a template URI such as https://linkeddatahub.com/linkeddatahub/docs/ns/templates#Document. You can use it to look up the SPARQL query which is used to load the RDF data for the document. It looks like this:

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>

DESCRIBE ?this ?primaryTopic ?seeAlso WHERE {
    GRAPH ?graph
    { ?this ?p ?o .
      OPTIONAL { ?this foaf:primaryTopic ?primaryTopic }
      OPTIONAL { ?this rdfs:seeAlso ?seeAlso }
    }
}

?this is an important variable here because it is "magic": its value gets set to the absolute request URI (without the query string). That is the only input into the query. As a result, ?this can only match document URIs as only documents are directly accessible over HTTP and have RDF representations, and not abstract concepts or physical things (as they are not information resources).

If you need to return a description of a non-document resource using an LDT template, it has to be paired a with a document in the RDF dataset (restrictions can be used to define such relationship in the model). The query of the template has to match that relationship in its pattern. For example, the above query uses the foaf:primaryTopic property to reach the non-document ?primaryTopic resource.

Lets say we want to change the RDF description of the concept to return not only its own properties, but also include its narrower concepts. That data then can be used to render the narrower concepts on the same document, instead of just linking to them.

In order to achieve that, we need to override the LDT template that matches our concept items and specify our custom SPARQL query for the overriding template.

Create a query

We will use the following query to retrieve concept description and save it under queries/describe-concept.rq:

PREFIX  skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>

DESCRIBE ?this ?concept ?narrower ?broader
WHERE
  { GRAPH ?graph
      { ?this  ?p  ?o
        OPTIONAL
          { ?this  foaf:primaryTopic  ?concept
            OPTIONAL
              {   { GRAPH ?narrowerGraph
                      { ?concept  skos:narrower  ?narrower }
                  }
                UNION
                  { GRAPH ?narrowerGraph
                      { ?narrower  skos:broader  ?concept }
                  }
              }
            OPTIONAL
              {   { GRAPH ?broaderGraph
                      { ?concept  skos:broader  ?broader }
                  }
                UNION
                  { GRAPH ?broaderGraph
                      { ?broader  skos:narrower  ?concept }
                  }
              }
          }
      }
  }

It returns a description not only of the concept's document and the concept itself, but also of the (optional) narrower and broader concepts. Inverse skos:narrower/skos:broader properties are traversed in both directions.

In the administration application, follow these steps:

  1. Click the Create dropdown in the top-left corner
  2. Click on DESCRIBE in the drop-down list that appears
  3. Fill out the mandatory fields in the form:
    Label
    Enter Describe concept
    IsDefinedBy
    Type Templates into the input (which provides autocomplete)
    Select Templates from the list — this is the ontology in which the query is defined
    Text
    Enter the SPARQL DESCRIBE query string
  4. Click Save
pwd=$(realpath -s $PWD)

pushd . && cd "$SCRIPT_ROOT"/admin/sitemap

./create-describe.sh \
-b "${base}" \
-f "${cert_pem_file}" \
-p "${cert_password}" \
--uri "https://localhost:4443/ns/templates#DescribeConcept" \
--label "Describe concept" \
--slug describe-concept \
--query-file "$pwd/queries/describe-concept.rq"

popd

Create a template

In the administration application, follow these steps to create a concept class:

  1. Click the Create dropdown in the top-left corner
  2. Click on Template in the drop-down list that appears
  3. Fill out the fields in the form:
    Label
    Enter Concept item
    IsDefinedBy
    Type Templates into the input (which provides autocomplete)
    Select Templates from the list — this is the ontology in which the class is defined
    Query
    Type Describe concept into the input (which provides autocomplete)
    Select Describe concept from the list — this is the query we created beforehand
  4. Click Save
pushd . && cd "$SCRIPT_ROOT"/admin/sitemap

./create-template.sh \
-b "${base}" \
-f "${cert_pem_file}" \
-p "${cert_password}" \
--uri "https://localhost:4443/ns/templates#ConceptItem" \
--label "Concept item" \
--slug concept-item \
--extends "https://localhost:4443/ns/templates#Document" \
--match "/concepts/{slug}/" \
--query "https://localhost:4443/ns/templates#DescribeConcept" \
--is-defined-by "https://localhost:4443/ns/templates#"

popd

Clear ontologies

For changes made to application ontologies (both of the model and of the sitemap) to take effect, the ontologies need to be cleared from memory and reloaded from dataset. Follow these steps:

Head to the administration application by clicking the Settings in the action bar and then choosing Administration.

  1. Open Sitemap / Ontologies / Templates
  2. Click Clear in the header of the ontology description
  3. Open Model / Ontologies / Namespace
  4. Click Clear in the header of the ontology description

Replace ${OWNER_KEY_PASSWORD} with its value from the .env file and execute the following commands:

pushd . && cd "$SCRIPT_ROOT"/admin

./clear-ontology.sh \
-f "${cert_pem_file}" \
-p "${cert_password}" \
"https://localhost:4443/admin/sitemap/ontologies/templates/"

./clear-ontology.sh \
-f "${cert_pem_file}" \
-p "${cert_password}" \
"https://localhost:4443/admin/model/ontologies/namespace/"

popd