Differences
This shows you the differences between two versions of the page.
courses:semint:lab_rules [2022/09/08 22:24] – created kkt | courses:semint:lab_rules [2022/11/10 02:09] (current) – kkt | ||
---|---|---|---|
Line 55: | Line 55: | ||
- Take a look at inferred knowledge | - Take a look at inferred knowledge | ||
- | === 2. SWRL in use [20 minutes] === | + | === 2. SWRL in use [25 minutes] === |
- Open your own ontology in the Protege Desktop. | - Open your own ontology in the Protege Desktop. | ||
Line 62: | Line 62: | ||
- //After adding rules, don't forget to save the new version of the ontology so you don't lose your work if something will go wrong!// | - //After adding rules, don't forget to save the new version of the ontology so you don't lose your work if something will go wrong!// | ||
- | === 3. Introduction to SHACL [20 minutes] === | + | === 3. Introduction to SHACL [15 minutes] === |
- | + | ||
- | * SHACL stands for **Shapes Constraint Language** (no, these are not geometric shapes ;-) ). It's all about **constraints** (a shape is a collection of constraints that shapes the data). | + | |
- | * Unlike ontologies (which model a selected part of real-world), | + | |
- | * The starting point is our knowledge graph. Alongside it, we create a second graph (with SHACL triples) that describes the constraints. | + | |
- | * Whatever you can do with SHACL you can also do with OWL or SWRL. __So why do we need SHACL?__ \\ (based on [[https:// | + | |
- | * //OWL has been designed to support inferencing, | + | |
- | * //Confusion about the meaning of restrictions -- in particular that OWL does not constrain anything but rather describes inferences.// | + | |
- | * //Reasoning under Open World Assumption is tricky. Especially if you want to determine if all records meet the constraints.// | + | |
- Open the [[https:// | - Open the [[https:// | ||
- | - Open [[https:// | + | - Protégé has dedicated plugin for SHACL. |
- | - Click on the Shapes Graph icon (top left). Select Format: '' | + | * [[https://shacl-playground.zazuko.com/|Zazuko |
- | - Click on the Data Graph icon (next to Shapes Graph icon). Select Format: '' | + | |
- | - Now, you can see graphs in Turtle syntax in both windows: Shapes Graph and Data Graph. | + | |
- | - Let's start with a simple example. | + | |
- | - Copy the following Shapes Graph to SHACL Playground: <code turtle> | + | |
- | @prefix sh: < | + | |
- | @prefix xsd: < | + | |
- | @prefix schema: < | + | |
- | + | ||
- | :UserShape a sh: | + | |
- | | + | |
- | | + | |
- | sh:path schema:name ; | + | |
- | sh:minCount 1; | + | |
- | sh:maxCount 1; | + | |
- | sh:datatype xsd: | + | |
- | ] ; | + | |
- | | + | |
- | sh:path schema: | + | |
- | sh:minCount 1; | + | |
- | sh:maxCount 1; | + | |
- | sh:nodeKind sh:IRI | + | |
- | ] . | + | |
- | </ | + | |
- | @prefix sh: < | + | |
- | @prefix xsd: < | + | |
- | @prefix schema: < | + | |
- | + | ||
- | :alice schema:name "Alice Cooper" | + | |
- | | + | |
- | + | ||
- | :bob | + | |
- | | + | |
- | + | ||
- | :carol schema:name " | + | |
- | | + | |
- | - Data Graph should be clear for you ;-) \\ Shapes Graph has a '': | + | |
- | * First, we provide information about nodes in Data Graph that should follow these constraints: | + | |
- | * Then, we provide information about constraints on two outgoing relations (i.e., properties in which targetNodes are the subject). '' | + | |
- | * For each property, we define the cardinality (min and max count; so, one user must have exactly one name and one email) and the expected object type (to be more concrete -> all restrictions on relations, i.e., everything in blank nodes in this example, are __PropertyShapes__) | + | |
- | - The Validation Report is presented below. It is formatted in nice HTML, but the SHACL standard defines the exact report structure in RDF. If you want to see the RAW report, select the Validation Report icon (third icon in the top left corner) and select Display errors as '' | + | |
- | - There are some errors in the Data Graph. Fix them to check if you understand the defined shapes correctly! | + | |
- | - SHACL is for humans, so make it more human-friendly! Play with all three relations: | + | |
- | - You can define your own message in a Shape, using '' | + | |
- | - You can also define the severity of each constraint, using '' | + | |
- | | + | |
- | - Constraints applied to specific nodes listed by URIs ('' | + | |
- | - Load the new Data Graph (with specification of instances of '': | + | |
- | @prefix sh: < | + | |
- | @prefix xsd: < | + | |
- | @prefix schema: < | + | |
- | + | ||
- | :alice a :User ; | + | |
- | | + | |
- | | + | |
- | + | ||
- | :bob | + | |
- | | + | |
- | | + | |
- | + | ||
- | :carol a :User ; | + | |
- | | + | |
- | | + | |
- | - Change the definition of the '': | + | |
- | - All instances of '': | + | |
- | - All subjects of '' | + | |
- | - SHACL provides logical operators to combine constraints. | + | |
- | | + | |
- | @prefix sh: < | + | |
- | @prefix xsd: < | + | |
- | @prefix schema: < | + | |
- | + | ||
- | :UserShape a sh: | + | |
- | | + | |
- | | + | |
- | + | ||
- | : | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | : | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | - Now, let's back to the Data Graph provided | + | |
- | + | ||
- | + | ||
- | === 4. SHACL and Protégé [10 minutes] === | + | |
- | + | ||
- | - Protégé has dedicated plugin for SHACL. We will try it now (it should be already installed; as the first task during this lab). | + | |
- Download the [[https:// | - Download the [[https:// | ||
- Open dedicated tab by selecting: '' | - Open dedicated tab by selecting: '' | ||
Line 196: | Line 97: | ||
- There are 6 violations. Fix them! (fix the knowledge base and/or change the constraints) | - There are 6 violations. Fix them! (fix the knowledge base and/or change the constraints) | ||
- | === 5. SHACL in use [20 minutes] === | + | === 4. SHACL in use [25 minutes] === |
- Open your own ontology (with SWRL rules developed during this lab) in the Protégé. | - Open your own ontology (with SWRL rules developed during this lab) in the Protégé. |