Generate a JSON-LD context

This utility generates a JSON-LD context document from a SHACL specification. Detailed documentation is available below.

  Shapes

Remove Select file Change
You can select multiple files. Supported extensions : .rdf, .ttl, .n3, .trig, or .zip. You can also upload Excel files (see SHACL in Excel).
URL of an RDF file. Same extensions as file upload are supported.
Supported syntaxes : Turtle, RDF/XML, JSON-LD, TriG, TriX, N-Quads. We recommend Turtle.

Documentation

JSON-LD context document generation algorithm

The algorithm follow these steps to generate the JSON-LD context:

  1. Always add a mapping from id, type and graph to @id, @type and @graph respectively.
  2. Add prefix mappings for each known prefixes in the SHACL file.
  3. Add mappings with the URI of targets of NodeShapes in the SHACL (reading sh:targetClass, or for shapes that are themselves classes), using the local part of the URI as JSON key.
  4. Add mappings with the URI of properties referred to in sh:path in the SHACL. Only direct property URIs, or inverse path are supported, and more complex paths are ignored. By default, the local part of the property URI is used as key, but a different JSON key can be specified by annotating the property shape with the property https://shacl-play.sparna.fr/ontology#shortname (if the same property is referred to by multiple property shapes annotated with different shortnames, then multiple mappings are generated). Then :
    1. If the property path is an inverse path, use @reverse in the mapping.
    2. If the property is rdf:type, map the shortname to @type instead of the property URI, so that compaction algorithm can compact it. Otherwise map to the property URI.
    3. For every reading of a property characteristic below (sh:datatype, sh:pattern, sh:languageIn, sh:class, sh:nodeKind), the lookup is always done on the property shape(s) but also on the node shape being referred to by sh:node on these property shapes.
    4. Determine the @type from datatypes : read the sh:datatype. If there is one, use it as the value of @type (if the same property is referred to by multiple property shapes with different sh:datatype, the first one is used, and a warning is output).
      1. If the datatype starts with http://www.w3.org/2001/XMLSchema# but is not xsd:string, use the value xsd:xxxxx as the value of @type
      2. If the datatype is rdf:langString, then if there is a single value for sh:languageIn, then use this language in a @language annotation on this mapping, otherwise set @container: @language on this mapping
      3. Otherwise, set the short form of the datatype URI as the value of @type
    5. Determine the @type from URI reference : if there is a sh:class, or if sh:nodeKind is sh:IRI or sh:BlankNodeOrIRI, set the @type to @id (note : sh:node is not considered here as it can point to a node shape actually describing a literal value).
    6. In order to have short values for IRI references in the JSON, determine is there is a common URI prefix for the values of the property in order to set an inner context. Search for a sh:pattern (on property shape reference node shape through sh:node).
      1. If there is one, and if is a regex describing the beginning of an http or https URI, add a scoped context for this property with a @vocab + @base indication using the beginning of the URI extracted from the regex, and set the @type to @vocab. See this discussion for why both @vocab and @base are set.
      2. Otherwise, if there is some sh:or on the property shape(s) using this predicate (or associated with this shortname), then read the sh:pattern on each of them, and determine if there is a single common root for all of the them. If there is, then use it to set @vocab + @base on an inner @context
    7. Determine if @container: @set should be added : if no other value for @container was set (e.g. with @language), then by default set @container: @set unles :
      1. no sh:maxCount is found, but there is an sh:hasValue, indicating that the property cannot have multiple values.
      2. all occurrences of the property in property shapes do have an sh:maxCount, and all the values are 1.