At the end of the lab, each group should email their second project to the teacher. It consist of:
*.ttl
file with the ontology (started on Ontology 101, refined during the Advanced ontology engineering and extended with SWRL rules during today's lab),*.ttl
file with SHACL shapes (developed during the second part of today's lab).File
→ Check for plugins…
SWRLTab Protege 5.0+ Plugin
SHACL4Protege Constraint Validator
Install
Person(?x) ^ hasParent(?x, ?y) ^ hasParent(?x, ?z) ^ hasSpouse(?y, ?z) -> ChildOfMarriedParents(?x)
Also, sometimes you can describe something using OWL, but it can be more intuitive when defined as a SWRL rule.
->
).^
sign (logical and).?
.Person(?x)
will bind ?x
to an instance of the class Person and will iterate over each instance of the Person class.hasParent(?x, ?y)
will bind ?y
to each parent of ?x
(note that the ?x
will be bound in the previous expression).swrlb:
prefix, e.g., the math built-in swrlb:greaterThan(?age, 18)
succeeds if the value of ?age
is greater than 18. See 8. Built-Ins for full list and documentation.^
are changed to commans in the Rule view):Window
→ Tabs
→ SWRLTab
(there is no need to use the Drools engine in the bottom panel; we will use the HermiT/Pellet reasoners)Window
→ Views
→ Ontology views
→ Rules
and click somewhere in the Protege, where this view should be placed.Reasoner
menu select HermiT or Pellet reasonerReasoner
→ Start Reasoner
(or Synchronize reasoner
if it was started before)Window
→ Tabs
→ SHACL Editor
.ex:PersonShape
. If it is not there, simply copy the following file to SHACL Editor: @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix sh: <http://www.w3.org/ns/shacl#> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix ex: <http://www.example.org/#> . @prefix owl: <http://www.w3.org/2002/07/owl#> . ex:PersonShape a sh:NodeShape ; sh:targetClass ex:Person ; # Applies to all persons sh:property [ # _:b0 sh:path ex:ssn ; # constrains the values of ex:ssn sh:maxCount 1 ; ] ; sh:property [ # _:b1 sh:path ex:ssn ; # constrains the values of ex:ssn sh:datatype xsd:string ; sh:pattern "^\\d{3}-\\d{2}-\\d{4}$" ; sh:severity sh:Warning ; ] ; sh:closed true ; sh:ignoredProperties ( rdf:type owl:topDataProperty owl:topObjectProperty ) ; .
Validate
to see the Validation Report (in the table, at the bottom). sh:pattern
and sh:closed
(combined with sh:ignoredProperties
). Do you understand them? Save
button in the SHACL Editor
tab; the file should have .ttl
extension, as it is a regular Turtle file)These instructions are based on New Protégé Pizza Tutorial, OWL 2 and SWRL Tutorial and Shapes applications and tools tutorial
SWRL:
SHACL: