Examples from the lectures: Difference between revisions

From info216
Line 1: Line 1:
==S07: SHACL==
==S07: SHACL==
The examples are for use with the [https://shacl.org/playground/ interactive SHACL Playground].
The examples are for use with the [https://shacl.org/playground/ interactive SHACL Playground].
===Minimal example===
First shape graph:
<syntaxhighlight lang="ttl">
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix kg: <http://i2s.uib.no/kg4news/> .
@prefix th: <http://i2s.uib.no/kg4news/theme/> .
@prefix ss: <http://semanticscholar.org/> .
kg:MainPaperShape
    a sh:NodeShape ;
    sh:targetClass kg:MainPaper ;
    sh:property kg:MainPaperYearShape  .
kg:MainPaperYearShape
        sh:path kg:year .
</syntaxhighlight>
First data graph:
<syntaxhighlight lang="ttl">
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix kg: <http://i2s.uib.no/kg4news/> .
@prefix th: <http://i2s.uib.no/kg4news/theme/> .
@prefix ss: <http://semanticscholar.org/> .
kg:LOD_Paper
    a kg:MainPaper ;
    dcterm:title "Linked Data - The Story so Far" .
</syntaxhighlight>
This should not give a validation error.
===Alternative shape graph===
Keep the prefixes from the first examples. You can also write the property constraint as a anyonymous node:
<syntaxhighlight>
kg:MainPaperShape
    a sh:NodeShape ;
    sh:targetClass kg:MainPaper ;
    sh:property [
        sh:path kg:year
    ] .
</syntaxhighlight>


===Full example===
===Full example===
Line 18: Line 70:
     a sh:NodeShape ;
     a sh:NodeShape ;
     sh:targetClass kg:MainPaper ;
     sh:targetClass kg:MainPaper ;
     sh:property kg:YearShape, kg:ContributorShape .
     sh:property kg:MainPaperYearShape, kg:MainPaperContributorShape .


kg:YearShape
kg:MainPaperYearShape
         sh:path kg:year ;
         sh:path kg:year ;
         sh:minCount 1 ;
         sh:minCount 1 ;
Line 26: Line 78:
         sh:datatype xsd:year .
         sh:datatype xsd:year .


kg:ContributorShape
kg:MainPaperContributorShape
         sh:path dcterm:contributor ;
         sh:path dcterm:contributor ;
         sh:minCount 1 ;
         sh:minCount 1 ;

Revision as of 14:00, 2 March 2023

S07: SHACL

The examples are for use with the interactive SHACL Playground.

Minimal example

First shape graph:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix kg: <http://i2s.uib.no/kg4news/> .
@prefix th: <http://i2s.uib.no/kg4news/theme/> .
@prefix ss: <http://semanticscholar.org/> .


kg:MainPaperShape
    a sh:NodeShape ;
    sh:targetClass kg:MainPaper ;
    sh:property kg:MainPaperYearShape  .

kg:MainPaperYearShape
        sh:path kg:year .

First data graph:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix kg: <http://i2s.uib.no/kg4news/> .
@prefix th: <http://i2s.uib.no/kg4news/theme/> .
@prefix ss: <http://semanticscholar.org/> .


kg:LOD_Paper
    a kg:MainPaper ;
    dcterm:title "Linked Data - The Story so Far" .

This should not give a validation error.

Alternative shape graph

Keep the prefixes from the first examples. You can also write the property constraint as a anyonymous node:

kg:MainPaperShape
    a sh:NodeShape ;
    sh:targetClass kg:MainPaper ;
    sh:property [
        sh:path kg:year 
    ] .


Full example

Final shape graph:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix kg: <http://i2s.uib.no/kg4news/> .
@prefix th: <http://i2s.uib.no/kg4news/theme/> .
@prefix ss: <http://semanticscholar.org/> .


kg:MainPaperShape
    a sh:NodeShape ;
    sh:targetClass kg:MainPaper ;
    sh:property kg:MainPaperYearShape, kg:MainPaperContributorShape .

kg:MainPaperYearShape
        sh:path kg:year ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
        sh:datatype xsd:year .

kg:MainPaperContributorShape
        sh:path dcterm:contributor ;
        sh:minCount 1 ;
        sh:class kg:MainAuthor ;
        sh:nodeKind sh:IRI .

Final data graph:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dcterm: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix kg: <http://i2s.uib.no/kg4news/> .
@prefix th: <http://i2s.uib.no/kg4news/theme/> .
@prefix ss: <http://semanticscholar.org/> .


kg:LOD_Paper
    a kg:MainPaper ;
    dcterm:title "Linked Data - The Story so Far" ;
    kg:year "2006"^^xsd:year ;
    dcterm:contributor kg:TBL, kg:CB .

kg:TBL
    a kg:MainAuthor;
    foaf:name "T. Berners-Lee" .
 
kg:CB
     a kg:MainAuthor;
     foaf:name "C. Bizer" .