Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for existence of instance of a class not working? #107

Open
jakubklimek opened this issue Mar 9, 2023 · 8 comments
Open

Checking for existence of instance of a class not working? #107

jakubklimek opened this issue Mar 9, 2023 · 8 comments

Comments

@jakubklimek
Copy link

I want to check whether in the Data graph, there is at least one instance of dcat:Catalog. I followed this example from the SHACL wiki.
tl;dr: It does not work in Zazuko, it works in SHACL Play!, but I am not sure which behavior is the correct one.

Data graph - note that there is one instance of dcat:Catalog:

@prefix dcat:    <http://www.w3.org/ns/dcat#> .
@prefix dct:     <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix vcard2006: <http://www.w3.org/2006/vcard/ns#> .

<https://data.gov.cz/lkod/mdcr/katalog> a dcat:Catalog ;
    dct:title "Katalog otevřených dat Ministerstva dopravy"@cs, "Open Data Catalog of the Ministry of Transport"@en ;
    dct:description "Otevřená data Ministerstva dopravy. Obsahuje datové sady o jízdních řádech a liniových vedeních veřejné dopravy."@cs;
    dct:description "Open data of the Ministry of Transport. It contains datasets regarding timetables of public transport."@en ;
    dct:publisher <https://rpp-opendata.egon.gov.cz/odrpp/zdroj/orgán-veřejné-moci/66003008> ;
    foaf:homepage <https://data.gov.cz/datové-sady?poskytovatel=Ministerstvo%20dopravy> ;
    dcat:contactPoint [
        a vcard2006:Organization ;
        vcard2006:fn "Ministerstvo dopravy, Odbor veřejné dopravy"@cs, "Ministry of Transport"@en ;
        vcard2006:hasEmail <mailto:sekretariat.190@mdcr.cz>
    ] ;
    dcat:dataset  <https://data.gov.cz/lkod/mdcr/datové-sady/seznam-zastavky> ,

Shapes graph:

@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <https://example.org/> .

# Shapes graph
ex:CatalogExistence
    a sh:NodeShape ;
    sh:targetNode dcat:Catalog ;
    sh:property [
      sh:path [ sh:inversePath rdf:type ];
      sh:minCount 1;
    ] .

Like this, it validates in Zazuko. However, if I remove the dcat:Catalog, e.g., by emptying the data graph, it still validates, which is not what I want. According to the example, and also in SHACL Play! it does not validate, which is what I want. However, I am not sure that the example is correct, since the targetNode cannot target anything, when there is no dcat:Dataset in the data graph, and therefore there is nothing to validate, and therefore the data graph seems valid. 🤷🏻‍♂️

@tpluscode
Copy link
Collaborator

Indeed, that is a know issue. If nothing in the data graph matches any shape targets (ie. in your example there is no resource with type dcat:Catalog), then no validation takes place. I think this is according to the spec and the wiki is a little misleading.

SHACL Play! shows a different message, not equivalent to failed validation. That may be a UI-only feature

@HolgerKnublauch
Copy link
Contributor

A shape with sh:targetNode will always be executed, regardless of whether the graph contains that node, or any node. It will simply set the target to the given targetNode even if it doesn't "exist". So - from my superficial look - the validation engine should report a violation if there is no instance of that class.

@tpluscode
Copy link
Collaborator

That does make sense but isn't it the opposite of what you said on Discord and also to how the engines behave?

I don't know which version of SHACL_TQ weso.es uses, but all engines report success when the shape has no target or target which is not present in data graph

https://rdfshape.weso.es/link/16789515368

By the way @jakubklimek, I noticed only now that you should change sh: targetNode to sh:targetClass

@jakubklimek
Copy link
Author

@tpluscode Actually, if I understand the Wiki example correctly, having sh:targetNode pointing to the class instead of sh:targetClass and supplementing it with the inverse of rdf:type are parts of the whole trick here.

@tpluscode
Copy link
Collaborator

ah ok, I failed to really understand before.

Yes, without a logic as described by Holger this cannot work. Otherwise it does assume that no targets found => no validation

@giacomociti
Copy link
Contributor

I propose we revert #81 because we misunderstood the spec (and the example to check there is at least one instance is useful)

@tpluscode
Copy link
Collaborator

Can you link to the spec where this is scenario mentioned?

@giacomociti
Copy link
Contributor

https://www.w3.org/TR/shacl/#targets

RDF terms produced by targets are not required to exist as nodes in the data graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants