w3c / wot-thing-description

Web of Things (WoT) Thing Description
http://w3c.github.io/wot-thing-description/
Other
131 stars 63 forks source link

Wrong validation errors with SHACL #1345

Open egekorkan opened 2 years ago

egekorkan commented 2 years ago

If one uses the shacl validation file at https://github.com/w3c/wot-thing-description/blob/main/validation/td-validation.ttl with a shacl validator like https://shacl.org/playground/ or https://www.itb.ec.europa.eu/shacl/any/upload , TDs that contain op in forms are not accepted.

With the second tool, these additional errors also show up:

Details

Since some part of the spec is generated from this file, it is probably normative and needs fixes.

Notes:

AndreaCimminoArriaga commented 2 years ago

@egekorkan I changed the implementation since the ontology has changed and now the old shacl shapes throw new errors. For instance, before the key "title" was translated into dct:title but now it is translated into td:title. The shapes forced to have at least one dct:title in a valid TD, therefore now all TDs will not be valid since title is td:title.

I think the file at https://github.com/w3c/wot-thing-description/blob/main/validation/td-validation.ttl has been updated to cope with this new terms. However, I tried with https://shacl.org/playground/ specifying the rdf:type Thing (this is important because the shapes are endowed particularly for this type) and I get more errors:

[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:InConstraintComponent ;
    sh:sourceShape _:n1855 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value "MyLampThing" ;
    sh:resultPath td:title ;
    sh:resultMessage "Value is not in Blank node _:n2014" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:NodeConstraintComponent ;
    sh:sourceShape _:n1855 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value "MyLampThing" ;
    sh:resultPath td:title ;
    sh:resultMessage "Value does not have shape <http://www.w3.org/ns/td-validation#DataSchemaShape>" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
    sh:sourceShape _:n1855 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value "MyLampThing" ;
    sh:resultPath td:title ;
    sh:resultMessage "Value does not have datatype xsd:anyURI" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
    sh:sourceShape _:n1855 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:resultPath td:title ;
    sh:resultMessage "Less than 2 values" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:NodeConstraintComponent ;
    sh:sourceShape _:n1863 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value _:n2139 ;
    sh:resultPath _:n1864 ;
    sh:resultMessage "Value does not have shape <http://www.w3.org/ns/td-validation#InteractionAffordanceShape>" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:NodeConstraintComponent ;
    sh:sourceShape _:n1868 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value _:n2138 ;
    sh:resultPath td:hasEventAffordance ;
    sh:resultMessage "Value does not have shape <http://www.w3.org/ns/td-validation#EventAffordanceShape>" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
    sh:sourceShape _:n1871 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value <https://json-ld.org/playground/basic_sc> ;
    sh:resultPath td:hasSecurityConfiguration ;
    sh:resultMessage "Value does not have datatype xsd:string" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:NodeConstraintComponent ;
    sh:sourceShape _:n1872 ;
    sh:focusNode <urn:dev:ops:32473-WoTLamp-1234> ;
    sh:value _:n2136 ;
    sh:resultPath td:definesSecurityScheme ;
    sh:resultMessage "Value does not have shape <http://www.w3.org/ns/td-validation#SecuritySchemeShape>" ;
] .
[
    a sh:ValidationResult ;
    sh:resultSeverity sh:Violation ;
    sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
    sh:sourceShape _:n1855 ;
    sh:focusNode _:n2136 ;
    sh:resultPath td:title ;
    sh:resultMessage "Less than 2 values" ;
] .

The RDF document was:

<urn:dev:ops:32473-WoTLamp-1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/saref#LightSwitch> .
<urn:dev:ops:32473-WoTLamp-1234> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.w3.org/2019/wot/td#Thing> .
<urn:dev:ops:32473-WoTLamp-1234> <https://www.w3.org/2019/wot/td#definesSecurityScheme> _:b0 .
<urn:dev:ops:32473-WoTLamp-1234> <https://www.w3.org/2019/wot/td#hasActionAffordance> _:b1 .
<urn:dev:ops:32473-WoTLamp-1234> <https://www.w3.org/2019/wot/td#hasEventAffordance> _:b3 .
<urn:dev:ops:32473-WoTLamp-1234> <https://www.w3.org/2019/wot/td#hasPropertyAffordance> _:b6 .
<urn:dev:ops:32473-WoTLamp-1234> <https://www.w3.org/2019/wot/td#hasSecurityConfiguration> <https://json-ld.org/playground/basic_sc> .
<urn:dev:ops:32473-WoTLamp-1234> <https://www.w3.org/2019/wot/td#title> "MyLampThing" .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.w3.org/2019/wot/security#BasicSecurityScheme> .
_:b0 <https://www.w3.org/2019/wot/security#in> "header" .
_:b0 <https://www.w3.org/2019/wot/td#hasInstanceConfiguration> <https://json-ld.org/playground/basic_sc> .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/saref#ToggleCommand> .
_:b1 <https://www.w3.org/2019/wot/td#hasForm> _:b2 .
_:b1 <https://www.w3.org/2019/wot/td#name> "toggle" .
_:b2 <https://www.w3.org/2019/wot/hypermedia#hasTarget> <https://mylamp.example.com/toggle> .
_:b3 <https://www.w3.org/2019/wot/td#hasForm> _:b4 .
_:b3 <https://www.w3.org/2019/wot/td#hasNotificationSchema> _:b5 .
_:b3 <https://www.w3.org/2019/wot/td#name> "overheating" .
_:b4 <https://www.w3.org/2019/wot/hypermedia#hasTarget> <https://mylamp.example.com/oh> .
_:b5 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.w3.org/2019/wot/json-schema#StringSchema> .
_:b6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/saref#OnOffState> .
_:b6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.w3.org/2019/wot/json-schema#StringSchema> .
_:b6 <https://www.w3.org/2019/wot/td#hasForm> _:b7 .
_:b6 <https://www.w3.org/2019/wot/td#name> "status" .
_:b7 <https://www.w3.org/2019/wot/hypermedia#hasTarget> <https://mylamp.example.com/status> .
mahdanoura commented 8 months ago

@AndreaCimminoArriaga I checked this issue. I understand the problem with rdf:type td:Thing, but I am not sure how to resolve this. We cannot enforce this with the json-ld context file, as the @context file does not add an rdf:type relationship when the term is not existent in the json-ld instance.

Also, the SHACL validators seem to behave differently. The shacl playground has a strange behaviour with regards to the xsd:string and rdf:langString. Once the type is string it complains that it should be a langString, and the other way round.

I checked with python pyshacl library there is no validation errors regarding the title.

@egekorkan This is also the case with operations in Forms, this works. There was one issue I found in our SHACL shape graph, where I will do a PR that will fix this.