stringxsdshacl

How to validate literal values with no datatype definition in SHACL?


I assumed that not having any datatype is implicitly the same as having xsd:string as datatype, however SHACL gives me a validation error. Is my assumption wrong or is that just not covered by SHACL? In the latter case, how do I validate that the datatype is either empty or xsd:string?

string.ttl

@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.

<message> <title> "Hello World"@en.

shacl.ttl

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix sh:<http://www.w3.org/ns/shacl#> .

:TitleShape rdf:type sh:NodeShape;
    sh:targetObjectsOf <title>;
    sh:datatype xsd:string;
    sh:closed true.

Error

$ pyshacl  string.ttl -s shacl.ttl
Validation Report
Conforms: False
Results (1):
Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):
    Severity: sh:Violation
    Source Shape: :TitleShape
    Focus Node: Literal("Hello World", lang=en)
    Value Node: Literal("Hello World", lang=en)
    Message: Value is not Literal with datatype xsd:string

Solution

  • In your example the data contains an rdf:langString literal, which is not the same datatype as xsd:string - you see the @en language tag. You probably refer to the fact that the following would be equivalent: "Hello World" and "Hello World"^^xsd:string. So the pyshacl result above looks correct to me.