Ann
Ann

Reputation: 206

How to validate json-ld 1.1 data graphs with SHACL?

Data Graph: (json-ld)

{
    "@context": {
       "@version": 1.1,
        "pav": "http://purl.org/pav/",
        "xsd": "http://www.w3.org/2001/XMLSchema#",
        "skos": "http://www.w3.org/2004/02/skos/core#",
        "reproterms": "https://raw.githubusercontent.com/ReproNim/schema-standardization/master/terms/",
        "reproschema": "https://raw.githubusercontent.com/ReproNim/schema-standardization/master/schemas/",
        "schema": "http://schema.org/",
        "@language": "en",
        "prefLabel": {
            "@id": "skos:prefLabel",
            "@container": "@language"
        }
    },
    "@type": "reproschema:Activity",
    "@id": "phq9_data",
    "prefLabel": "PHQ-9 Assessment"
}

Data graph in .ttl format :

@prefix activity: <https://raw.githubusercontent.com/ReproNim/schema-standardization/master/activities/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix reproterms: <https://raw.githubusercontent.com/ReproNim/schema-standardization/master/terms/> .
@prefix activity: <https://raw.githubusercontent.com/ReproNim/schema-standardization/master/activities/> .
@prefix reproschema: <https://raw.githubusercontent.com/ReproNim/schema-standardization/master/schemas/> .

activity:PHQ-9/phq9_schema
    a reproschema:Activity ;
    skos:prefLabel "PHQ-9 Assessment" .

Shapes Graph:

@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix reproterms: <https://raw.githubusercontent.com/ReproNim/schema-standardization/master/terms/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix reproschema: <https://raw.githubusercontent.com/ReproNim/schema-standardization/master/schemas/> .

reproschema:ActivityShape
    a sh:NodeShape ;
    sh:targetClass reproschema:Activity;

    sh:property [
        sh:path skos:prefLabel ;
        sh:datatype rdf:langString ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .

if the context contains @version: 1.1 it doesn't seem to work; gives an error. How do I make the validation work for graphs expressed in JSON-LD 1.1? I've added the data graph in turtle format too.

Upvotes: 0

Views: 687

Answers (1)

Holger Knublauch
Holger Knublauch

Reputation: 1421

The constraint sh:datatype rdf:langString requires that all values of the property have a language tag. So for example, skos:prefLabel "PHQ-9 Assessment"@en would work. Or change the constraint to sh:datatype xsd:string.

Upvotes: 1

Related Questions