w3c / data-shapes

RDF Data Shapes WG repo
89 stars 33 forks source link

Validate that graph contains a node with a specific type #93

Closed MiguelAraCo closed 7 years ago

MiguelAraCo commented 7 years ago

I'm having a hard time figuring out how to create a shape that validates the following condition:

The data graph must contain a node with a specific type (e.g. ex:Product)

My first approach was to use a shape graph like the following one:

<ContainsOneProduct>
    sh:NodeShape ;
    sh:targetClass ex:Product ;
    sh:node
        <ContainsOneProduct#graph-contains-Product> ,
        <ContainsOneProduct#graph-contains-only-one-Product> ,
    .
<ContainsOneProduct#graph-contains-Product>
    a sh:NodeShape ;
    sh:message "The graph must contain a 'ex:Project'"@en ;
    sh:minCount "1"^^xsd:integer .
<ContainsOneProduct#graph-contains-only-one-Product>
    a sh:NodeShape ;
    sh:message "The graph mustn't contain more than one 'ex:Project'"@en ;
    sh:maxCount "1"^^xsd:integer .

This can't be done because sh:NodeShapes can't have sh:minCount or sh:maxCount. So what would be a way to validate this condition?

HolgerKnublauch commented 7 years ago

See https://www.w3.org/wiki/SHACL/Examples

MiguelAraCo commented 7 years ago

Awesome, thanks!