This utility generates a JSON-LD context document from a SHACL specification. Detailed documentation is available below.
The algorithm follow these steps to generate the JSON-LD context:
id, type and graph
to @id, @type and @graph respectively.sh:targetClass, or for shapes that are themselves classes), using the local part of the URI as JSON key.
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 :
@reverse in the mapping.
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.
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.@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).
http://www.w3.org/2001/XMLSchema# but is not xsd:string, use the value xsd:xxxxx as the value of @typerdf: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@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).
sh:pattern (on property shape reference node shape through sh:node).
@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.
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@container: @set should be added : if no other value for @container was set (e.g. with @language), then by default set @container: @set unles :
sh:maxCount is found, but there is an sh:hasValue, indicating that the property cannot have multiple values.sh:maxCount, and all the values are 1.