Shapes

Shapes Creator - subset schemas and convert to SHACL.

This module provides two core operations:

  1. Subset: given a full JSON-LD schema (as produced by rdfsolve’s miner or parser) and a list of edges (paths) to keep, produce a smaller JSON-LD containing only those triples.

  2. SHACL conversion: take a (subset) JSON-LD schema and convert it to SHACL shapes via the existing VoidParser -> LinkML -> ShaclGenerator pipeline.

The shapes feature allows users to define intended schemas from mined schemas, which can then be used for RDF data validation.

jsonld_to_shacl(schema_jsonld: dict[str, Any], *, schema_name: str | None = None, closed: bool = True, suffix: str | None = None) str[source]

Convert a JSON-LD schema to SHACL Turtle via LinkML.

Delegates to rdfsolve.schema_models.shacl.to_shacl(), which runs the full LinkML -> ShaclGenerator pipeline on the given JSON-LD dict- no VoidParser instance required.

Parameters:
  • schema_jsonld – JSON-LD dict (the same format produced by subset_jsonld or the miner).

  • schema_name – Optional name for the generated LinkML/SHACL schema.

  • closed – Whether to produce closed SHACL shapes (sh:closed true).

  • suffix – Suffix appended to every shape name (e.g. "Shape" -> PersonShape).

Returns:

SHACL shapes serialised as Turtle.

Return type:

str

subset_jsonld(schema_jsonld: dict[str, Any], keep_edges: list[dict[str, str]]) dict[str, Any][source]

Return a copy of schema_jsonld containing only keep_edges.

Parameters:
  • schema_jsonld – Full JSON-LD schema with @context, @graph, and optionally @about.

  • keep_edges – List of edge specs. Each must have subject, predicate, and object keys (CURIEs or full URIs).

Returns:

A new JSON-LD document that keeps only the nodes and properties referenced by keep_edges. The @context is preserved; @about is carried over as-is.

Return type:

dict