SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
https://www.apachecon.com/acah2020/tracks/jena.html
Apache Jena track at ApacheCon@Home 2020
2020-09-28
SHACL in Apache Jena
Andy
Contributor to Apache Jena
Co-editor: SPARQL
Iotics : https://iotics.com/
Today
● About
● SHACL Core
○ Example walkthrough
● SHACL Compact syntax
● SHACL-SPARQL
● SHACL operations
SHACL
Describes what the data looks like
W3C standard: https://www.w3.org/TR/shacl/
Use for:
● Validation
● Schema
● HTML forms
● . . .
SHACL-AF
Also “SHACL Advanced features” : https://www.w3.org/TR/shacl-af/
● Custom Targets
● Rules
● Node expressions
● Functions
Active Community Group
https://www.w3.org/community/shacl/
Why validate?
● Unexpected data makes applications harder to write
● Unexpected data in a database is hard to clean up
● External data may be missing/incomplete/changed/. . .
● Unnoticed data changes
Unexpected or missing data is a signal
Доверяй, но проверяй
“Trust but verify”
-- Russian Proverb
SHACL
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:lessThan foaf:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
SHACL
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:lessThan foaf:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
Example data
:AlbertEinstein
a foaf:Person ;
foaf:givenName "Albert" ;
foaf:familyName "Einstein" ;
foaf:birthDate "1979-03-14"^^xsd:date ;
foaf:deathDate "1955-04-18"^^xsd:date ;
.
Validation
● Good: foaf:givenName
● No foaf:AddressShape (not required)
● foaf:familyName -- not matched
● Bad: foaf:birthDate
Validation Report
[ a sh:ValidationReport ;
sh:conforms false ;
sh:result [
a sh:ValidationResult ;
sh:focusNode :AlbertEinstein ;
sh:resultMessage "..." ;
sh:resultPath foaf:birthDate ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:LessThanConstraintComponent ;
sh:sourceShape [] ;
sh:value "1979-03-14"^^xsd:date
]
] .
SHACL Walkthrough
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:lessThan foaf:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
NodeShape URI: schema:PersonShape
… applies to resources of class foaf:Person
:AlbertEinstein rdf:type foaf:Person ;
foaf:givenName "Albert" ;
foaf:familyName "Einstein" ;
foaf:birthDate "1979-03-14"^^xsd:date ;
foaf:deathDate "1955-04-18"^^xsd:date ;
.
SHACL Walkthrough
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:lessThan foaf:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
Property Shape
… property foaf:givenName
:AlbertEinstein rdf:type foaf:Person ;
foaf:givenName "Albert" ;
foaf:familyName "Einstein" ;
foaf:birthDate "1979-03-14"^^xsd:date ;
foaf:deathDate "1955-04-18"^^xsd:date ;
.
SHACL Walkthrough
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:lessThan foaf:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
… property foaf:givenName
… … object must be an xsd:string
:AlbertEinstein rdf:type foaf:Person ;
foaf:givenName "Albert" ;
foaf:familyName "Einstein" ;
foaf:birthDate "1979-03-14"^^xsd:date ;
foaf:deathDate "1955-04-18"^^xsd:date ;
.
SHACL Walkthrough
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:maxCount 1 ;
sh:lessThan foaf:deathDate ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
… property foaf:birthDate
… … there must be at most one
:AlbertEinstein rdf:type foaf:Person ;
foaf:givenName "Albert" ;
foaf:familyName "Einstein" ;
foaf:birthDate "1979-03-14"^^xsd:date ;
foaf:deathDate "1955-04-18"^^xsd:date ;
.
SHACL Walkthrough
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:maxCount 1 ;
sh:lessThan foaf:deathDate ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
… property foaf:birthDate
… … value must be less than all values of foaf:deathDate
:AlbertEinstein rdf:type foaf:Person ;
foaf:givenName "Albert" ;
foaf:familyName "Einstein" ;
foaf:birthDate "1979-03-14"^^xsd:date ;
foaf:deathDate "1955-04-18"^^xsd:date ;
.
SHACL Walkthrough
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:maxCount 1 ;
sh:lessThan foaf:deathDate ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
… property schema:address
… … conforms to another node shape
SHACL Compact Syntax
schema:PersonShape
a sh:NodeShape ;
sh:targetClass foaf:Person ;
sh:property [
sh:path foaf:givenName ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path foaf:birthDate ;
sh:lessThan foaf:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path foaf:address ;
sh:node foaf:AddressShape ;
] .
shape schema:PersonShape -> foaf:Person {
foaf:givenName datatype=xsd:string .
foaf:birthDate [0..1] lessThan=foaf:deathDate .
foaf:address @foaf:AddressShape .
}
Targets
Classes
● sh:targetClass
● Implicit (with the class declaration)
sh:targetSubjectsOf property
● c.f. rdfs:domain
sh:targetObjectsOf property
● c.f. rdfs:range
sh:node
● Specific node
SPARQL targets (SHACL-af)
SHACL Core : Key concepts
Targets -- starting points
Node shapes
Property shapes and Paths
-- routes from starting points to nodes to validate
Constraints -- validations
Apache Jena
https://jena.apache.org/documentation/shacl/
● SHACL Core, SHACL SPARQL (the REC)
● SHACL Compact syntax - read and write
● Command line tools
○ Parse and print
○ Validate
● Fuseki service
○ Validate graph
○ Validate at node
SHACL SPARQL Constraints
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX ex: <http://example/>
## SHAPES
ex:prefixes
sh:declare [ sh:prefix "rdfs"; sh:namespace "http://www.w3.org/2000/01/rdf-schema#"^^xsd:anyURI; ] .
:sparqlShape
sh:targetClass :CLASS ;
sh:sparql [
# Test language tag is in capitals
sh:prefixes ex:prefixes ;
# Query to return violations.
sh:select """
SELECT $this ?value
WHERE {
$this rdfs:label ?value .
BIND(lang(?value) AS ?X)
FILTER (!isLiteral(?value) || lcase(?X) != ?X)
}
""" ;
] .
One violation for each result of the query.
SHACL Idiom
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX ex: <http://example/>
## Test whether the data graph is empty.
ex:global
a sh:NodeShape ;
sh:targetNode ex:anything ;
sh:sparql [
sh:select "SELECT * { ?s ?p ?o } LIMIT 1" ;
] .
Online
https://shacl.org/playground/
Online
users@jena.apache.org
Subscribe: users-subscribe@jena.apache.org
https://jena.apache.org/documentation/shacl/

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Building Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and HydraBuilding Next-Generation Web APIs with JSON-LD and Hydra
Building Next-Generation Web APIs with JSON-LD and Hydra
 
RDF data validation 2017 SHACL
RDF data validation 2017 SHACLRDF data validation 2017 SHACL
RDF data validation 2017 SHACL
 
ShEx by Example
ShEx by ExampleShEx by Example
ShEx by Example
 
RDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic RepositoriesRDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic Repositories
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked Data
 
JSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social WebJSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social Web
 
BLOGIC. (ISWC 2009 Invited Talk)
BLOGIC.  (ISWC 2009 Invited Talk)BLOGIC.  (ISWC 2009 Invited Talk)
BLOGIC. (ISWC 2009 Invited Talk)
 
Ontology In A Nutshell (version 2)
Ontology In A Nutshell (version 2)Ontology In A Nutshell (version 2)
Ontology In A Nutshell (version 2)
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQL
 
RDF data model
RDF data modelRDF data model
RDF data model
 
SPIN in Five Slides
SPIN in Five SlidesSPIN in Five Slides
SPIN in Five Slides
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with Ion
 
Validating RDF data: Challenges and perspectives
Validating RDF data: Challenges and perspectivesValidating RDF data: Challenges and perspectives
Validating RDF data: Challenges and perspectives
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
FIWARE Training: NGSI-LD Introduction
FIWARE Training: NGSI-LD IntroductionFIWARE Training: NGSI-LD Introduction
FIWARE Training: NGSI-LD Introduction
 
Full-on Hypermedia APIs with Hydra
Full-on Hypermedia APIs with HydraFull-on Hypermedia APIs with Hydra
Full-on Hypermedia APIs with Hydra
 
RDF 개념 및 구문 소개
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개
 
Html
HtmlHtml
Html
 

Ähnlich wie SHACL in Apache jena - ApacheCon2020

2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
Josef Petrák
 
Ks2007 Semanticweb In Action
Ks2007 Semanticweb In ActionKs2007 Semanticweb In Action
Ks2007 Semanticweb In Action
Rinke Hoekstra
 
SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
andyseaborne
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
Alvaro Graves
 

Ähnlich wie SHACL in Apache jena - ApacheCon2020 (20)

Part04_SHACL By Example presentation.pptx
Part04_SHACL By Example presentation.pptxPart04_SHACL By Example presentation.pptx
Part04_SHACL By Example presentation.pptx
 
Challenges and applications of RDF shapes
Challenges and applications of RDF shapesChallenges and applications of RDF shapes
Challenges and applications of RDF shapes
 
Two graph data models : RDF and Property Graphs
Two graph data models : RDF and Property GraphsTwo graph data models : RDF and Property Graphs
Two graph data models : RDF and Property Graphs
 
SHACL Specification Draft
SHACL Specification DraftSHACL Specification Draft
SHACL Specification Draft
 
SHACL shortly (ELAG 2018)
SHACL shortly (ELAG 2018)SHACL shortly (ELAG 2018)
SHACL shortly (ELAG 2018)
 
Optimizing SPARQL Queries with SHACL.pdf
Optimizing SPARQL Queries with SHACL.pdfOptimizing SPARQL Queries with SHACL.pdf
Optimizing SPARQL Queries with SHACL.pdf
 
Graph Data -- RDF and Property Graphs
Graph Data -- RDF and Property GraphsGraph Data -- RDF and Property Graphs
Graph Data -- RDF and Property Graphs
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge query
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
 
2016-02 Graphs - PG+RDF
2016-02 Graphs - PG+RDF2016-02 Graphs - PG+RDF
2016-02 Graphs - PG+RDF
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
 
Ks2007 Semanticweb In Action
Ks2007 Semanticweb In ActionKs2007 Semanticweb In Action
Ks2007 Semanticweb In Action
 
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
Search Engine Building with Lucene and Solr (So Code Camp San Diego 2014)
 
SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)SPARQL 1.1 Update (2013-03-05)
SPARQL 1.1 Update (2013-03-05)
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
XSPARQL Tutorial
XSPARQL TutorialXSPARQL Tutorial
XSPARQL Tutorial
 
Publishing a Perl6 Module
Publishing a Perl6 ModulePublishing a Perl6 Module
Publishing a Perl6 Module
 
Linked opendata parisemantique.fr - 24062011
Linked opendata   parisemantique.fr - 24062011Linked opendata   parisemantique.fr - 24062011
Linked opendata parisemantique.fr - 24062011
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 

Kürzlich hochgeladen

Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 

Kürzlich hochgeladen (20)

Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 

SHACL in Apache jena - ApacheCon2020

  • 1. https://www.apachecon.com/acah2020/tracks/jena.html Apache Jena track at ApacheCon@Home 2020 2020-09-28 SHACL in Apache Jena
  • 2. Andy Contributor to Apache Jena Co-editor: SPARQL Iotics : https://iotics.com/
  • 3. Today ● About ● SHACL Core ○ Example walkthrough ● SHACL Compact syntax ● SHACL-SPARQL ● SHACL operations
  • 4. SHACL Describes what the data looks like W3C standard: https://www.w3.org/TR/shacl/ Use for: ● Validation ● Schema ● HTML forms ● . . .
  • 5. SHACL-AF Also “SHACL Advanced features” : https://www.w3.org/TR/shacl-af/ ● Custom Targets ● Rules ● Node expressions ● Functions Active Community Group https://www.w3.org/community/shacl/
  • 6. Why validate? ● Unexpected data makes applications harder to write ● Unexpected data in a database is hard to clean up ● External data may be missing/incomplete/changed/. . . ● Unnoticed data changes Unexpected or missing data is a signal Доверяй, но проверяй “Trust but verify” -- Russian Proverb
  • 7. SHACL schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:lessThan foaf:deathDate ; sh:maxCount 1 ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] .
  • 8. SHACL schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:lessThan foaf:deathDate ; sh:maxCount 1 ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . Example data :AlbertEinstein a foaf:Person ; foaf:givenName "Albert" ; foaf:familyName "Einstein" ; foaf:birthDate "1979-03-14"^^xsd:date ; foaf:deathDate "1955-04-18"^^xsd:date ; . Validation ● Good: foaf:givenName ● No foaf:AddressShape (not required) ● foaf:familyName -- not matched ● Bad: foaf:birthDate
  • 9. Validation Report [ a sh:ValidationReport ; sh:conforms false ; sh:result [ a sh:ValidationResult ; sh:focusNode :AlbertEinstein ; sh:resultMessage "..." ; sh:resultPath foaf:birthDate ; sh:resultSeverity sh:Violation ; sh:sourceConstraintComponent sh:LessThanConstraintComponent ; sh:sourceShape [] ; sh:value "1979-03-14"^^xsd:date ] ] .
  • 10. SHACL Walkthrough schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:lessThan foaf:deathDate ; sh:maxCount 1 ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . NodeShape URI: schema:PersonShape … applies to resources of class foaf:Person :AlbertEinstein rdf:type foaf:Person ; foaf:givenName "Albert" ; foaf:familyName "Einstein" ; foaf:birthDate "1979-03-14"^^xsd:date ; foaf:deathDate "1955-04-18"^^xsd:date ; .
  • 11. SHACL Walkthrough schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:lessThan foaf:deathDate ; sh:maxCount 1 ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . Property Shape … property foaf:givenName :AlbertEinstein rdf:type foaf:Person ; foaf:givenName "Albert" ; foaf:familyName "Einstein" ; foaf:birthDate "1979-03-14"^^xsd:date ; foaf:deathDate "1955-04-18"^^xsd:date ; .
  • 12. SHACL Walkthrough schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:lessThan foaf:deathDate ; sh:maxCount 1 ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . … property foaf:givenName … … object must be an xsd:string :AlbertEinstein rdf:type foaf:Person ; foaf:givenName "Albert" ; foaf:familyName "Einstein" ; foaf:birthDate "1979-03-14"^^xsd:date ; foaf:deathDate "1955-04-18"^^xsd:date ; .
  • 13. SHACL Walkthrough schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:maxCount 1 ; sh:lessThan foaf:deathDate ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . … property foaf:birthDate … … there must be at most one :AlbertEinstein rdf:type foaf:Person ; foaf:givenName "Albert" ; foaf:familyName "Einstein" ; foaf:birthDate "1979-03-14"^^xsd:date ; foaf:deathDate "1955-04-18"^^xsd:date ; .
  • 14. SHACL Walkthrough schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:maxCount 1 ; sh:lessThan foaf:deathDate ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . … property foaf:birthDate … … value must be less than all values of foaf:deathDate :AlbertEinstein rdf:type foaf:Person ; foaf:givenName "Albert" ; foaf:familyName "Einstein" ; foaf:birthDate "1979-03-14"^^xsd:date ; foaf:deathDate "1955-04-18"^^xsd:date ; .
  • 15. SHACL Walkthrough schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:maxCount 1 ; sh:lessThan foaf:deathDate ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . … property schema:address … … conforms to another node shape
  • 16. SHACL Compact Syntax schema:PersonShape a sh:NodeShape ; sh:targetClass foaf:Person ; sh:property [ sh:path foaf:givenName ; sh:datatype xsd:string ; ] ; sh:property [ sh:path foaf:birthDate ; sh:lessThan foaf:deathDate ; sh:maxCount 1 ; ] ; sh:property [ sh:path foaf:address ; sh:node foaf:AddressShape ; ] . shape schema:PersonShape -> foaf:Person { foaf:givenName datatype=xsd:string . foaf:birthDate [0..1] lessThan=foaf:deathDate . foaf:address @foaf:AddressShape . }
  • 17. Targets Classes ● sh:targetClass ● Implicit (with the class declaration) sh:targetSubjectsOf property ● c.f. rdfs:domain sh:targetObjectsOf property ● c.f. rdfs:range sh:node ● Specific node SPARQL targets (SHACL-af)
  • 18. SHACL Core : Key concepts Targets -- starting points Node shapes Property shapes and Paths -- routes from starting points to nodes to validate Constraints -- validations
  • 19. Apache Jena https://jena.apache.org/documentation/shacl/ ● SHACL Core, SHACL SPARQL (the REC) ● SHACL Compact syntax - read and write ● Command line tools ○ Parse and print ○ Validate ● Fuseki service ○ Validate graph ○ Validate at node
  • 20. SHACL SPARQL Constraints PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX sh: <http://www.w3.org/ns/shacl#> PREFIX ex: <http://example/> ## SHAPES ex:prefixes sh:declare [ sh:prefix "rdfs"; sh:namespace "http://www.w3.org/2000/01/rdf-schema#"^^xsd:anyURI; ] . :sparqlShape sh:targetClass :CLASS ; sh:sparql [ # Test language tag is in capitals sh:prefixes ex:prefixes ; # Query to return violations. sh:select """ SELECT $this ?value WHERE { $this rdfs:label ?value . BIND(lang(?value) AS ?X) FILTER (!isLiteral(?value) || lcase(?X) != ?X) } """ ; ] . One violation for each result of the query.
  • 21. SHACL Idiom PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX sh: <http://www.w3.org/ns/shacl#> PREFIX ex: <http://example/> ## Test whether the data graph is empty. ex:global a sh:NodeShape ; sh:targetNode ex:anything ; sh:sparql [ sh:select "SELECT * { ?s ?p ?o } LIMIT 1" ; ] .