C++ API reference¶
The C++ SDK is a C++17 static library embedding the same Rust engine the CLI,
Python, and WebAssembly frontends wrap. Parsing, SPARQL, SHACL-AF inference,
validation, and shape-map extraction all run in Rust; the C++ side is a thin
RAII layer over a stable C ABI. The public API is a single header,
shifty/shifty.hpp.
Language |
C++17; public header |
Stability |
Stable, except interfaces explicitly marked experimental |
Related |
Install Shifty covers building with CMake and linking. This page describes the API surface; the shape-map vocabulary (typed keys, bindings, and terms) has its own section below and mirrors the Python Shape map reference reference.
Dataset¶
An in-memory RDF graph owned by the engine. Move-only; read-only operations may
run concurrently only with external synchronization against load operations.
Multiple sources union at the triple level: call load/load_file
repeatedly, or pass several documents where a single graph is accepted.
Member |
Meaning |
|---|---|
|
An empty graph. |
|
Parse RDF from memory ( |
|
Parse an RDF file and add it. |
|
Unique triples in the dataset. |
|
The whole graph as N-Triples. |
|
A |
QueryResult carries the result form (QueryResultKind), data()
(SPARQL Results JSON for SELECT/ASK, N-Triples for CONSTRUCT/DESCRIBE),
media_type(), and boolean_value() for ASK.
PreparedValidator¶
Parses and normalizes shapes once and validates any dataset against them.
Invalid shapes diagnostics, including malformed SPARQL or unresolved query
prefixes, raise shifty::Error with SHIFTY_STATUS_PARSE_ERROR while a
validator is constructed. diagnostics_json() therefore contains only
non-fatal warnings and unsupported-feature diagnostics.
Member |
Meaning |
|---|---|
|
Prepare shapes from memory. |
|
Prepare shapes from one or several files, unioned at the triple level. |
|
Prepare shapes from several in-memory documents, unioned the same way. |
|
Parser/lowering diagnostics as a JSON array. |
|
W3C |
|
Structured path: returns an |
|
Returns configuration-oriented typed key/value bindings. |
ValidationOptions carries graph_mode (Data/Union/UnionAll),
run_inference, minimum_severity (Severity::Info/Warning/
Violation — findings below the threshold stay reported but stop failing
conforms()), shape_names (limit validation to named entry shapes).
Shape maps¶
The shape-map view is the C++ port of Python shifty.shape_map(). For every
selected (shape, focus) pair it
produces a Mapping of the shape’s property obligations: bound keys carry the
values the data supplied as typed Terms (exact even on
partially-conforming foci), unbound keys carry the shortfall count and
near-misses. A one-property node shape retains that property’s name_path
value, and an unbounded sh:qualifiedValueShape still exposes the values
that satisfy its qualifier.
shifty::ShapeMapOptions opts;
opts.name_path = "sh:name"; // author's name per slot, shapes graph
opts.value_paths = {{"ts", "demo:hasTimeseriesId"}}; // annotate each value
const auto smap = validator.shape_map(dataset, opts);
for (const auto &name : smap.shape_names()) {
for (const auto &mapping : smap.mappings(name)) {
for (const auto *binding : mapping.successful()) {
std::cout << binding->key().str() << ":";
for (const auto &value : binding->values()) {
std::cout << " " << value.n3();
}
std::cout << "\n";
}
}
}
ShapeMapOptions¶
Member |
Meaning |
|---|---|
|
Validation behavior used while extracting bindings. |
|
Optional named entry shapes; empty selects every target-bearing shape. |
|
Property path naming the slot, evaluated from the authored
property-shape node over the shapes graph. Constant per property
shape. Defaults to |
|
|
Unlike Python, the C++ shape map is materialized eagerly at build time, so a
ShapeMap is a plain value that never needs its session to outlive it.
ShapeMap¶
Member |
Meaning |
|---|---|
|
Whether the whole run conformed. |
|
Every shape identity with at least one authored statement — named shape
IRIs, or |
|
The |
|
Every |
|
Those mappings split by conformance. |
|
Every mapping for one node, across profiles. Accepts a |
|
Sizes. |
|
A JSON-compatible summary keyed by shape, focus, and rendered key, with
terms in N-Triples spelling — the analogue of Python’s |
Mapping¶
Member |
Meaning |
|---|---|
|
The focus node, rendered in full N-Triples form. |
|
The shape IRI, or empty for an anonymous shape. |
|
The selector that chose this focus, rendered. |
|
Whether this pair conformed. |
|
Every |
|
Pointers to the bound / unbound bindings, in authored order. |
|
The number of bindings. |
|
The first binding whose |
|
The binding with the given typed |
|
Successful bindings only, as |
Binding¶
Member |
Meaning |
|---|---|
|
The typed |
|
Whether the key is usable; |
|
The resolved slot name (first value of |
|
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 observed qualifying-value count, where available. |
|
True exactly for a |
|
|
|
|
A partially-conforming focus yields both sides: its failing keys report
missing()/rejected_values(), while its passing keys are materialized so
a configuration consumer sees every value the focus can already supply.
Key¶
A typed, hashable key: the property shape’s path plus its qualifier class when
one is declared, disambiguated by ordinal() when several authored
obligations share a path and qualifier.
Member |
Values |
|---|---|
|
|
|
|
|
Distinguishes two authored obligations sharing a path and qualifier. Part of equality and ordering. |
|
Typed |
|
Renders as e.g. |
Path::parse_json() decodes the serde spelling of the algebra Path into
a typed Path for pattern matching; Terms are TermKind::Iri /
Literal / BNode with value(), datatype(), language(), and
n3() (N-Triples rendering matching terms.py — xsd:string datatypes
are omitted, lexical escapes applied). Term supports operator== and
operator< so it works as a std::map/std::set member.
See also¶
Shape map reference — the Python object model this page mirrors.
Extract bindings with a shape map — the shape map how-to (Python, but the semantics carry over).
cpp/README.md— build instructions and the same API in prose.