Change the model

Change the model: create constructors, classes, and restrictions

Change the model

In order to be able to manage SKOS concepts and concept schemes, we need to create classes that represent them in the model of our dataspace. Not only will they serve as RDF types of the instances, but will have constructors attached that define the default properties and their (data)types for that class.

Since a SKOS concept is an abstract thing which cannot be directly dereferenced over HTTP, its instance has to be paired with a document instance. In the model, this relationship is defined by creating a property restriction between the concept class and its item (document) class. Another restriction will be used to define the relationship between the item class and its container. We therefore need to create 2 classes and 2 restrictions. The following examples will assume https://localhost:4443/ as the base URI of the dataspace.

Model is managed in the administration application of a dataspace. Head there by clicking the Settings in the action bar and then choosing Administration.

In order to edit the access control, model, or sitemap of a dataspace, you need to be an administrator, i.e. a member of the owners group.

Create a constructor

We will use the following SPARQL CONSTRUCT query as a constructor for our Concept class and save it in a file under queries/construct-concept.rq.

PREFIX :     <ns/domain#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>

CONSTRUCT
{
?this skos:inScheme [ a :ConceptScheme ] ;
    skos:topConceptOf [ a :ConceptScheme ] ;
    skos:prefLabel [ a xsd:string ] ;
    skos:altLabel [ a xsd:string ] ;
    skos:hiddenLabel [ a xsd:string ] ;
    skos:notation [ a xsd:string ] ;
    skos:note [ a xsd:string ] ;
    skos:changeNote [ a xsd:string ] ;
    skos:definition [ a xsd:string ] ;
    skos:editorialNote [ a xsd:string ] ;
    skos:example [ a xsd:string ] ;
    skos:historyNote [ a xsd:string ] ;
    skos:scopeNote [ a xsd:string ] ;
    skos:semanticRelation [ a :Concept ] ;
    skos:broader [ a :Concept ] ;
    skos:narrower [ a :Concept ] ;
    skos:related [ a :Concept ] ;
    skos:broaderTransitive [ a :Concept ] ;
    skos:narrowerTransitive [ a :Concept ] ;
    skos:mappingRelation [ a :Concept ] ;
    skos:broadMatch [ a :Concept ] ;
    skos:narrowMatch [ a :Concept ] ;
    skos:relatedMatch [ a :Concept ] ;
    skos:exactMatch [ a :Concept ] ;
    skos:closeMatch [ a :Concept ] .
}
WHERE {}

In the administration application, follow these steps:

  1. Click the Create dropdown in the top-left corner
  2. Click on CONSTRUCT in the drop-down list that appears
  3. Switch the Blank node dropdown to URI and enter https://localhost:4443/ns/domain#ConstructConcept
  4. Fill out the mandatory fields in the form:
    Label
    Enter Construct concept
    IsDefinedBy
    Type Domain into the input (which provides autocomplete)
    Select Domain from the list — this is the ontology in which the query is defined
    Text
    Enter the SPARQL CONSTRUCT query string
  5. Click Save
pwd=$(realpath -s $PWD)

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

./create-construct.sh \
-b "${base}admin/" \
-f "$cert_pem_file" \
-p "$cert_password" \
--uri "${base}ns/domain#ConstructConcept" \
--label "Construct concept" \
--slug construct-concept \
--query-file "$pwd/queries/construct-concept.rq"

popd

Follow the same steps for Concept scheme.

Create classes

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

  1. Click the Create dropdown in the top-left corner
  2. Click on Class in the drop-down list that appears
  3. Switch the Blank node dropdown to URI and enter https://localhost:4443/ns/domain#Concept
  4. Fill out the mandatory fields in the form:
    Label
    Enter Concept
    IsDefinedBy
    Type Domain into the input (which provides autocomplete)
    Select Domain from the list — this is the ontology in which the class is defined
    Constructor
    Type Construct concept into the input (which provides autocomplete)
    Select Construct concept from the list — this is the query we created beforehand
    SubClassOf
    Enter https://localhost:4443/ns/domain#TopicOfConceptItem. We'll create this restriction later on.
  5. Click Save

As mentioned, we need to create a second concept-specific document class as well. It does not need a constructor as it will extend a built-in class. Follow the steps to create an item class:

  1. Click the Create dropdown in the top-left corner
  2. Click on Class in the drop-down list that appears
  3. Switch the Blank node dropdown to URI and enter https://localhost:4443/ns/domain#ConceptItem
  4. Fill out the mandatory fields in the form:
    Label
    Enter Concept item
    IsDefinedBy
    Type Domain into the input (which provides autocomplete)
    Select Domain from the list — this is the ontology in which the class is defined
    SubClassOf
    Enter https://localhost:4443/ns/domain#ItemOfConceptContainer. We'll create this restriction later on.
    Now add another SubClassOf field using the [+] button at the bottom of the form.
    SubClassOf
    Enter https://localhost:4443/ns/domain/default#Item — the built-in class this class extends
  5. Click Save
pushd . && cd "$SCRIPT_ROOT"/admin/model

./create-class.sh \
-b "${base}" \
-f "${cert_pem_file}" \
-p "${cert_password}" \
--uri "${base}ns/domain#Concept" \
--label "Concept" \
--slug concept \
--constructor "${base}ns/domain#ConstructConcept" \
--sub-class-of "${base}ns/domain#TopicOfConceptItem" \
--path "{isPrimaryTopicOf.slug}/" \
--fragment "this"

./create-class.sh \
-b "${base}" \
-f "${cert_pem_file}" \
-p "${cert_password}" \
--uri "${base}ns/domain#ConceptItem" \
--label "Concept item" \
--slug concept-item \
--sub-class-of "${base}ns/domain/default#Item" \
--sub-class-of "${base}ns/domain#ItemOfConceptContainer"

popd

Follow the same steps for Concept scheme.

Create restrictions

Property restrictions define a meta-relationship between classes based on a property. Instances of the respective classes are expected to have the property specified by the restriction in order for instance dataset to align with the ontology.

In the administration application, follow these steps to create a restriction connecting the concept class and its item class:

  1. Click the Create dropdown in the top-left corner
  2. Click on Missing property value in the drop-down list that appears
  3. Switch the Blank node dropdown to URI and enter https://localhost:4443/ns/domain#TopicOfConceptItem
  4. Fill out the fields in the form:
    Label
    Enter Topic of concept item
    IsDefinedBy
    Type Domain into the input (which provides autocomplete)
    Select Domain from the list — this is the ontology in which the query is defined
    OnProperty
    Enter http://xmlns.com/foaf/0.1/isPrimaryTopicOf
    AllValuesFrom
    Enter https://localhost:4443/ns/domain#ConceptItem — the class we created earlier
  5. Click Save

As mentioned, we need to create a second restriction connecting the item class to its container https://localhost:4443/concepts/:

  1. Click the Create dropdown in the top-left corner
  2. Click on Missing property value in the drop-down list that appears
  3. Switch the Blank node dropdown to URI and enter https://localhost:4443/ns/domain#ItemOfConceptContainer
  4. Fill out the fields in the form:
    Label
    Enter Item of concept container
    IsDefinedBy
    Type Domain into the input (which provides autocomplete)
    Select Domain from the list — this is the ontology in which the query is defined
    OnProperty
    Enter http://rdfs.org/sioc/ns#has_container
    HasValue
    Enter https://localhost:4443/concepts/ or URI of another container that will have concept items as children
  5. Click Save
pushd . && cd "$SCRIPT_ROOT"/admin/model

./create-restriction.sh \
-b "${base}admin/" \
-f "$cert_pem_file" \
-p "$cert_password" \
--uri "${base}ns/domain#TopicOfConceptItem" \
--label "Topic of concept item" \
--slug topic-of-concept-item \
--on-property "http://xmlns.com/foaf/0.1/isPrimaryTopicOf" \
--all-values-from "${base}ns/domain#ConceptItem"

./create-restriction.sh \
-b "${base}admin/" \
-f "$cert_pem_file" \
-p "$cert_password" \
--uri "${base}ns/domain#ItemOfConceptContainer" \
--label "Item of concept container" \
--slug item-of-concept-container \
--on-property "http://rdfs.org/sioc/ns#has_container" \
--has-value "${base}concepts/"

popd

Create a constraint

To control data quality, we probably want to make some of the instance properties mandatory. For example, a Concept instance should always have a skos:prefLabel value.

In the administration application, follow these steps:

  1. Click the Create dropdown in the top-left corner
  2. Click on Missing property value in the drop-down list that appears
  3. Fill out the fields in the form:
    Label
    Enter Missing skos:prefLabel
    IsDefinedBy
    Type Domain into the input (which provides autocomplete)
    Select Domain from the list — this is the ontology in which the query is defined
    Arg1
    Enter http://www.w3.org/2004/02/skos/core#prefLabel
  4. Click Save
pushd . && cd "$SCRIPT_ROOT"/admin/model

./create-property-constraint.sh \
-b "${base}" \
-f "${cert_pem_file}" \
-p "${cert_password}" \
--uri "https://localhost:4443/ns/domain#MissingPrefLabel" \
--label "Missing skos:prefLabel" \
--slug missing-pref-label \
--property "http://www.w3.org/2004/02/skos/core#prefLabel"

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 Model / Ontologies / Domain
  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/model/ontologies/domain/"

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

popd