Change the model
Change the model: create constructors, classes, and constraints
Change the model
In order to be able to manage instances, 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.
Model is managed in the administration application of a dataspace. Head there by clicking the in the action bar and then choosing Administration.
In order to manage the access control, or the model of a dataspace, the agent needs to be a member of the owners group.
We will use the SKOS ontology and its skos:Concept class as an example in this guide.
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 skos: <http://www.w3.org/2004/02/skos/core#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> CONSTRUCT { $this skos:inScheme [ a skos:ConceptScheme ] ; skos:topConceptOf [ a skos: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 skos:Concept ] ; skos:broader [ a skos:Concept ] ; skos:narrower [ a skos:Concept ] ; skos:related [ a skos:Concept ] ; skos:broaderTransitive [ a skos:Concept ] ; skos:narrowerTransitive [ a skos:Concept ] ; skos:mappingRelation [ a skos:Concept ] ; skos:broadMatch [ a skos:Concept ] ; skos:narrowMatch [ a skos:Concept ] ; skos:relatedMatch [ a skos:Concept ] ; skos:exactMatch [ a skos:Concept ] ; skos:closeMatch [ a skos:Concept ] . } WHERE {}
In the administration application, follow these steps:
- Click the Create dropdown in the top-left corner
- Click on CONSTRUCT in the drop-down list that appears
- Switch the Blank node dropdown to URI and enter https://localhost:4443/ns#ConstructConcept
- Fill out the mandatory fields in the form:
- Label
- Enter Construct concept
- Select Domain from the list — this is the ontology in which the query is defined
- Text
- Enter the SPARQL
CONSTRUCT
query string
- 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#ConstructConcept" \ --label "Construct concept" \ --slug construct-concept \ --query-file "$pwd/queries/construct-concept.rq" \ "${base}admin/model/ontologies/namespace/" popd
Follow the same steps for Concept scheme.
Create a constraint
To control data quality, we probably want to make some of the instance properties
mandatory. For example, a skos:Concept instance should always have a skos:prefLabel
value.
In the administration application, follow these steps:
- Click the Create dropdown in the top-left corner
- Click on Missing property value in the drop-down list that appears
- 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
- 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#MissingPrefLabel" \ --label "Missing skos:prefLabel" \ --slug missing-pref-label \ --property "http://www.w3.org/2004/02/skos/core#prefLabel" \ "${base}admin/model/ontologies/namespace/" popd
Create classes
In the administration application, follow these steps to create the concept class:
- Click the Create dropdown in the top-left corner
- Click on Class in the drop-down list that appears
- Switch the Blank node dropdown to URI and enter https://localhost:4443/ns#Concept
- Fill out the mandatory fields in the form:
- Label
- Enter Concept
- 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
- Click Save
pushd . && cd "$SCRIPT_ROOT"/admin/model ./create-class.sh \ -b "$base" \ -f "$cert_pem_file" \ -p "$cert_password" \ --uri "http://www.w3.org/2004/02/skos/core#Concept" \ --label "Concept" \ --slug concept \ --constructor "{$base}ns#ConstructConcept" \ --constraint "{$base}ns#MissingPrefLabel" \ "${base}admin/model/ontologies/namespace/" popd
Follow the same steps for Concept scheme.