Shape map reference¶
A shape map is a binding table over an evidence run: one Mapping per
selected (shape, focus) pair, each a dictionary from a typed Key — the
property obligation — to a Binding — the values that satisfied it, or the
information needed to see why it did not.
It is similar in spirit to a ShEx shape map, but deliberately keeps the property-level bindings, so a profile can serve as an extraction schema and as a contract that needs repair. Extract bindings with a shape map shows it in use.
shape_map¶
shifty.shape_map(
data_graph,
shacl_graph=None,
*,
name_path="sh:name",
value_paths=None,
shape_names=None,
minimum_severity="info",
infer=True,
graph_mode="union",
base=None,
) -> ShapeMap
A convenience over EvidenceSession(...).validate() followed by
ShapeMap.from_run. Its graph arguments follow validate() and
validate_algebra(): data first, then shapes. If shacl_graph is omitted,
data_graph supplies both shapes and data.
Argument |
Meaning |
|---|---|
|
Property path naming the slot, evaluated from the authored
property-shape node over the shapes graph. Constant per property
shape. |
|
|
|
As for |
ShapeMap.from_run¶
session = shifty.EvidenceSession(shapes, data, infer=False)
run = session.validate()
smap = shifty.ShapeMap.from_run(run, session, name_path="sh:name",
value_paths=None)
Pass the session. Canonical failure evidence omits the passing siblings of a
failed conjunction; with the session the map materializes them on demand, and
without it such a binding has values is None — explicitly unknown rather
than guessed.
ShapeMap¶
Member |
Meaning |
|---|---|
|
Whether the whole run conformed. |
|
The shape IRIs present in the map. |
|
The list of |
|
Every |
|
Those mappings split by conformance. |
|
Every mapping for one node, across profiles. Accepts a |
|
A JSON-compatible summary keyed by shape, focus, and rendered key, with terms in N-Triples spelling. |
Mapping¶
Implements collections.abc.Mapping, so items(), keys(), len(),
and mapping[key] behave normally. __getitem__ also accepts a rendered
key string, for interactive use.
Member |
Meaning |
|---|---|
|
The focus node, as a |
|
The shape IRI. |
|
The selector that chose this focus. |
|
Whether this pair conformed. |
|
Ordered |
|
Successful bindings only. |
|
The first binding with that name, in authored order. Names need not be
unique; use |
|
The underlying |
Binding¶
Member |
Meaning |
|---|---|
|
Whether the obligation was satisfied. |
|
The resolved slot name, and every value |
|
The bound values as |
|
Values that qualified so far, on an unsatisfied obligation. |
|
Candidates the qualifier rejected. |
|
How many more values are required. |
|
Declared cardinality bounds. |
|
The count the evidence saw, where available. |
|
True exactly for a |
|
Effective SHACL severity, lowercase. |
|
|
|
The annotation map directly. |
|
The evidence subtree this binding was derived from. |
|
Human-readable rendering. |
Key¶
Immutable and hashable, so it works as a dictionary key or set member.
Field |
Values |
|---|---|
|
|
|
|
|
Distinguishes two authored obligations sharing a path and qualifier. Part of equality and hashing. |
str(key) renders as e.g. hasPoint→SupplyAirTemperatureSensor. That form
compacts IRIs to local names, so it is not globally unique and is intended for
logs and table headings, not program logic.
The pattern-matching example requires Python 3.10 or newer. The package also supports Python 3.9.
from shifty import Cls, Key, Pred
match key:
case Key(Pred("http://example.org/hasPoint"), Cls(sensor_class)):
...
Terms¶
Iri(value), Literal(value, datatype=None, language=None), and
BNode(id), sharing the base class Term. Focus nodes and bound values are
these rather than rendered strings, so an IRI, a blank node, and a literal with
similar text cannot be confused.
Method |
Meaning |
|---|---|
|
Parse an N-Triples spelling. |
|
Render as N-Triples. |
|
Convert common numeric and boolean datatypes; unknown datatypes keep their lexical form. |
|
Convert to the rdflib equivalent. Requires |