API Reference¶
Top-level imports¶
shacl_bridges — N-to-m semantic mapping via SHACL shapes with SPARQL CONSTRUCT rules.
Typical usage::
from shacl_bridges.io.yaml_reader import load_mapping
from shacl_bridges.core.graph import select_root_class, check_connectivity
from shacl_bridges.core.shacl import generate_shacl
from shacl_bridges.core.diff import run_bridge_from_files, save_result
mapping = load_mapping("bridge.yaml")
root = select_root_class(mapping.source_pattern.triples, mapping.root_class())
issues = check_connectivity(mapping.source_pattern.triples, root)
if issues:
raise ValueError(f"Disconnected nodes for root {root!r}: {issues}")
shacl_ttl = generate_shacl(mapping, root)
with open("bridge_shape.ttl", "w") as f:
f.write(shacl_ttl)
result = run_bridge_from_files("data.ttl", "bridge_shape.ttl")
save_result(result, "expanded.ttl", "diff.ttl")
Or use the CLI::
shacl-bridges validate bridge.yaml
shacl-bridges diagram bridge.yaml -o diagram.mmd
shacl-bridges generate bridge.yaml -o bridge_shape.ttl
shacl-bridges run bridge.yaml data.ttl
load_mapping(path)
¶
Load a :class:BridgeMapping from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BridgeMapping
|
Parsed and structurally validated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required keys are missing or triples are malformed. |
FileNotFoundError
|
If path does not exist. |
select_root_class(triples, explicit_root=None)
¶
Return the CURIE of the class that should anchor the SHACL shape.
Selection order:
1. explicit_root if provided (comes from source_pattern.root in the YAML).
2. The node with the highest closeness centrality in the undirected view of
the source-pattern graph; ties broken by out-degree in the directed view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triples
|
list[Triple]
|
Source-pattern triples ( |
required |
explicit_root
|
str | None
|
CURIE string supplied by the user, or None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
CURIE string of the selected root class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If triples is empty. |
check_connectivity(triples, root)
¶
Return a list of nodes NOT reachable from root in the source-pattern graph.
A non-empty result means the WHERE clause would contain disconnected sub-patterns, causing the SPARQL CONSTRUCT to over-match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triples
|
list[Triple]
|
Source-pattern triples. |
required |
root
|
str
|
CURIE of the chosen root class. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of unreachable node CURIEs (empty if fully connected). |
generate_shacl(mapping, root_class, shape_name='shapes:BridgeShape')
¶
Generate a complete SHACL Turtle document for the given mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
BridgeMapping
|
Loaded :class: |
required |
root_class
|
str
|
CURIE of the class that the shape targets ( |
required |
shape_name
|
str
|
Local name for the generated |
'shapes:BridgeShape'
|
Returns:
| Type | Description |
|---|---|
str
|
Full Turtle string ready to be written to a |
run_bridge(data_graph, shacl_graph, inference='rdfs')
¶
Apply a SHACL bridge shape to data_graph and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_graph
|
Graph
|
The instance data to transform. |
required |
shacl_graph
|
Graph
|
The generated SHACL shape (containing the SPARQLRule). |
required |
inference
|
str
|
Reasoner to apply before validation. |
'rdfs'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BridgeResult
|
class: |
run_bridge_from_files(data_path, shacl_path, inference='rdfs')
¶
Convenience wrapper: load graphs from file paths, then call :func:run_bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str | Path
|
Path to the instance data Turtle file. |
required |
shacl_path
|
str | Path
|
Path to the SHACL shape Turtle file. |
required |
inference
|
str
|
Reasoner to apply. |
'rdfs'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BridgeResult
|
class: |
save_result(result, expanded_path, diff_path)
¶
Serialize expanded and diff graphs to Turtle files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
BridgeResult
|
Output of :func: |
required |
expanded_path
|
str | Path
|
Destination path for the expanded graph. |
required |
diff_path
|
str | Path
|
Destination path for the diff graph. |
required |
harmonize_to_turtle(source, destination=None, fmt=None)
¶
Load source in any RDF serialization and re-serialize as Turtle.
This normalizes syntax differences between tools (Protégé RDF/XML, robot OWL/XML, hand-written Turtle, etc.) before the bridge pipeline runs. No inference is applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Input RDF file (any serialization). |
required |
destination
|
str | Path | None
|
Output |
None
|
fmt
|
str | None
|
Force an input format string instead of auto-detecting. |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
The loaded :class: |
Graph
|
round-tripping through rdflib's parser/serializer). |
shacl_bridges.io.yaml_reader¶
shacl_bridges.io.yaml_reader
¶
YAML-based bridge mapping loader.
A mapping is defined in a single YAML file (conventionally named bridge.yaml)
with five top-level sections:
metadata— title, version, creator, license, default justificationprefixes— namespace declarations (prefix → IRI)source_pattern— S-P-O triples defining the source design pattern; optionalrootoverridetarget_pattern— S-P-O triples defining the target design patternclass_map— explicit alignment between source and target classes
See docs/yaml_format.md for the full schema and annotated example.
Triple = tuple[str, str, str]
module-attribute
¶
A (subject, predicate, object) triple where all three are CURIE strings.
BridgeMapping
dataclass
¶
All information that defines one bridge mapping.
Load with :func:load_mapping. Validate with
:func:~shacl_bridges.validate.validate_mapping.
Source code in shacl_bridges/io/yaml_reader.py
class_map
instance-attribute
¶
Alignment between source and target classes.
metadata = field(default_factory=Metadata)
class-attribute
instance-attribute
¶
Title, version, creator, license, default justification.
prefixes
instance-attribute
¶
Namespace declarations: {prefix: IRI}.
source_pattern
instance-attribute
¶
The source design pattern with its triples and optional root override.
target_pattern
instance-attribute
¶
The target design pattern triples.
class_alignment()
¶
Return {source_curie: target_curie} for regular (non-derived) entries.
Entries with a derived_iri represent new instances minted at query
time and are intentionally excluded here — they are accessed via
:meth:derived_class_map and handled separately by the SPARQL builder.
When the same source class appears in both a regular and a derived entry
the regular (non-derived) entry wins and sets the primary ?this
target type.
Source code in shacl_bridges/io/yaml_reader.py
derived_class_map()
¶
Return only the entries that carry a derived_iri (instance-split targets).
prefix_map()
¶
root_class()
¶
source_classes()
¶
target_classes()
¶
Return the set of target CURIEs declared in the class map (regular + derived).
ClassMapEntry
dataclass
¶
A single source-class → target-class alignment.
For a standard 1-to-1 mapping leave derived_iri as None.
For instance-split mappings — where one source instance must become two
target instances (e.g. a conflated "Agent+Role" class splitting into a
separate Agent and AgentRole) — add a second entry for the same
source class with derived_iri set. The tool will mint a new IRI for
the derived instance at query time.
Supported derived_iri forms:
"suffix:<string>"— appendto the source instance IRI. Example: suffix:_roleturnsex:agent1intoex:agent1_role.
Source code in shacl_bridges/io/yaml_reader.py
comment = None
class-attribute
instance-attribute
¶
Human-readable explanation of why this mapping is valid.
derived_iri = None
class-attribute
instance-attribute
¶
IRI minting rule for instance-split targets (see class docstring). When None the target instance reuses the source instance IRI (standard case).
justification = None
class-attribute
instance-attribute
¶
SSSOM-style justification CURIE, e.g. semapv:ManualMappingCuration.
source
instance-attribute
¶
CURIE of the source class (must appear in source_pattern.triples).
target
instance-attribute
¶
CURIE of the target class (must appear in target_pattern.triples).
Metadata
dataclass
¶
Human-readable metadata about the bridge mapping.
Source code in shacl_bridges/io/yaml_reader.py
mapping_justification = 'semapv:ManualMappingCuration'
class-attribute
instance-attribute
¶
Default justification applied to all class-map entries that don't override it.
SourcePattern
dataclass
¶
The source design pattern: a list of S-P-O triples and an optional root override.
Source code in shacl_bridges/io/yaml_reader.py
TargetPattern
dataclass
¶
load_mapping(path)
¶
Load a :class:BridgeMapping from a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BridgeMapping
|
Parsed and structurally validated :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required keys are missing or triples are malformed. |
FileNotFoundError
|
If path does not exist. |
Source code in shacl_bridges/io/yaml_reader.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
shacl_bridges.io.rdf_utils¶
shacl_bridges.io.rdf_utils
¶
Utilities for loading and normalizing RDF graphs.
The primary purpose here is syntax harmonization: converting any RDF serialization (RDF/XML, OWL/XML, Turtle, N-Triples, JSON-LD, etc.) to a canonical Turtle representation before the bridge pipeline runs. This avoids blank-node ID collisions and namespace prefix inconsistencies that arise when mixing serialization styles from tools like Protégé, OWLTools, or robot.
No semantic inference is performed here. That belongs in core/diff.py via pyshacl.
harmonize_many(sources, output_dir=None, fmt=None)
¶
Harmonize multiple RDF files to Turtle in one call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
list[str | Path]
|
List of input file paths. |
required |
output_dir
|
str | Path | None
|
Directory for output files. When None each file is written next to its source. |
None
|
fmt
|
str | None
|
Force an input format for all files. |
None
|
Returns:
| Type | Description |
|---|---|
dict[Path, Graph]
|
Mapping from output path to loaded :class: |
Source code in shacl_bridges/io/rdf_utils.py
harmonize_to_turtle(source, destination=None, fmt=None)
¶
Load source in any RDF serialization and re-serialize as Turtle.
This normalizes syntax differences between tools (Protégé RDF/XML, robot OWL/XML, hand-written Turtle, etc.) before the bridge pipeline runs. No inference is applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Input RDF file (any serialization). |
required |
destination
|
str | Path | None
|
Output |
None
|
fmt
|
str | None
|
Force an input format string instead of auto-detecting. |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
The loaded :class: |
Graph
|
round-tripping through rdflib's parser/serializer). |
Source code in shacl_bridges/io/rdf_utils.py
load_graph(source, fmt=None)
¶
Load an RDF graph from source, auto-detecting serialization if fmt is None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
File path or URL. |
required |
fmt
|
str | None
|
Explicit rdflib format string (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
A parsed :class: |
Source code in shacl_bridges/io/rdf_utils.py
shacl_bridges.core.graph¶
shacl_bridges.core.graph
¶
Graph analysis utilities used to select the root (target) class for SHACL generation.
The root class becomes sh:targetClass in the generated NodeShape and anchors
the ?this variable in the SPARQL CONSTRUCT WHERE clause. Choosing the wrong
root produces a disconnected WHERE pattern that over-matches — the most common
source of incorrect bridge output.
Two mechanisms are provided:
1. Explicit override via source_pattern.root in the bridge YAML.
2. Automatic selection using closeness centrality on the source-pattern graph,
with out-degree as a tiebreaker.
build_validation_graph(triples)
¶
Build a directed graph from a list of S-P-O triples.
Each triple (subject, predicate, object) becomes a directed edge
subject → object labelled with the predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triples
|
list[Triple]
|
List of |
required |
Returns:
| Type | Description |
|---|---|
DiGraph
|
Directed graph with |
Source code in shacl_bridges/core/graph.py
check_connectivity(triples, root)
¶
Return a list of nodes NOT reachable from root in the source-pattern graph.
A non-empty result means the WHERE clause would contain disconnected sub-patterns, causing the SPARQL CONSTRUCT to over-match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triples
|
list[Triple]
|
Source-pattern triples. |
required |
root
|
str
|
CURIE of the chosen root class. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of unreachable node CURIEs (empty if fully connected). |
Source code in shacl_bridges/core/graph.py
longest_path_length(G)
¶
Return the number of edges on the longest path in a DAG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
G
|
DiGraph
|
A directed acyclic graph. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of edges (0 for a single-node graph with no edges). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If G is not a DAG. |
Source code in shacl_bridges/core/graph.py
select_root_class(triples, explicit_root=None)
¶
Return the CURIE of the class that should anchor the SHACL shape.
Selection order:
1. explicit_root if provided (comes from source_pattern.root in the YAML).
2. The node with the highest closeness centrality in the undirected view of
the source-pattern graph; ties broken by out-degree in the directed view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
triples
|
list[Triple]
|
Source-pattern triples ( |
required |
explicit_root
|
str | None
|
CURIE string supplied by the user, or None. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
CURIE string of the selected root class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If triples is empty. |
Source code in shacl_bridges/core/graph.py
shacl_bridges.core.sparql¶
shacl_bridges.core.sparql
¶
SPARQL CONSTRUCT query generation.
Generates the CONSTRUCT { ... } WHERE { ... } block that is embedded inside
a sh:SPARQLRule. The WHERE clause is always anchored to ?this (the SHACL
convention for the focused node), which guarantees that only subgraphs that are
fully connected to the root class are matched.
Variable naming
?this— the focused node (bound to the root class by SHACL)?var_<suffix>— auto-generated variables for all other nodes, where suffix is a letter sequence (a, b, c, … z, aa, ab, …)
build_sparql_construct(class_alignment, source_triples, target_triples, root_class, prefix_map, derived_entries=None)
¶
Generate a SPARQL CONSTRUCT query from the bridge mapping.
The WHERE clause:
- Binds ?this to the root_class (?this rdf:type <root_class>)
- Includes only core source triples — those where both the subject and object
are source classes present in class_alignment. Peripheral/upper-level triples
(e.g. ex:Process isSome ex:ChemicalInvestigation) exist only at the TBox
level and are omitted from the SPARQL pattern.
- Every core triple produces type assertions for the non-root nodes.
- For each derived_entry a BIND(IRI(CONCAT(STR(?this), "…")) AS ?derived_X)
line is appended to mint a fresh IRI for the split-off instance.
The CONSTRUCT clause:
- Asserts new rdf:type triples for each source → target class mapping
- Asserts new rdf:type triples for each derived entry (instance split)
- Asserts the target-pattern relation triples, with variables resolved via the
reverse of class_alignment and the derived variable map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_alignment
|
dict[str, str]
|
|
required |
source_triples
|
list[Triple]
|
All triples from |
required |
target_triples
|
list[Triple]
|
All triples from |
required |
root_class
|
str
|
CURIE of the root class (the |
required |
prefix_map
|
dict[str, str]
|
|
required |
derived_entries
|
list[ClassMapEntry] | None
|
Entries with a |
None
|
Returns:
| Type | Description |
|---|---|
str
|
SPARQL CONSTRUCT string (without |
str
|
emitted separately as |
Source code in shacl_bridges/core/sparql.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
shacl_bridges.core.shacl¶
shacl_bridges.core.shacl
¶
SHACL shape generation.
Produces a complete Turtle-serialized SHACL document containing:
1. A sh:NodeShape targeting the root class with nested sh:property
constraints that mirror the source design pattern.
2. A sh:SPARQLRule embedding the SPARQL CONSTRUCT query from
:mod:shacl_bridges.core.sparql.
The nested property validation ensures that pyshacl only fires the SPARQL rule against nodes that genuinely conform to the source pattern — preventing the rule from matching isolated instances that happen to share a class name.
generate_shacl(mapping, root_class, shape_name='shapes:BridgeShape')
¶
Generate a complete SHACL Turtle document for the given mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
BridgeMapping
|
Loaded :class: |
required |
root_class
|
str
|
CURIE of the class that the shape targets ( |
required |
shape_name
|
str
|
Local name for the generated |
'shapes:BridgeShape'
|
Returns:
| Type | Description |
|---|---|
str
|
Full Turtle string ready to be written to a |
Source code in shacl_bridges/core/shacl.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
shacl_bridges.core.diff¶
shacl_bridges.core.diff
¶
Graph validation and diff computation.
Runs pyshacl in two passes: 1. Base pass: validates the data graph against itself (no external shape), with RDFS inference enabled. This captures any triples that RDFS alone would add and establishes the baseline. 2. Bridge pass: runs the generated SHACL shape against the data graph. The SPARQL CONSTRUCT rule fires and adds new triples.
The diff between pass-1 and pass-2 (via rdflib's isomorphic graph diff) gives exactly the triples introduced by the bridge — nothing more.
BridgeResult
dataclass
¶
Outcome of running the bridge pipeline on a data graph.
Source code in shacl_bridges/core/diff.py
conforms
instance-attribute
¶
Whether the data graph conforms to the validation constraints.
diff_graph
instance-attribute
¶
Only the triples introduced by the bridge (expanded minus inferred base).
expanded_graph
instance-attribute
¶
The full data graph after SHACL rule application (base + bridged triples).
report_graph
instance-attribute
¶
Machine-readable SHACL report graph.
report_text
instance-attribute
¶
Human-readable SHACL validation report.
run_bridge(data_graph, shacl_graph, inference='rdfs')
¶
Apply a SHACL bridge shape to data_graph and return the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_graph
|
Graph
|
The instance data to transform. |
required |
shacl_graph
|
Graph
|
The generated SHACL shape (containing the SPARQLRule). |
required |
inference
|
str
|
Reasoner to apply before validation. |
'rdfs'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BridgeResult
|
class: |
Source code in shacl_bridges/core/diff.py
run_bridge_from_files(data_path, shacl_path, inference='rdfs')
¶
Convenience wrapper: load graphs from file paths, then call :func:run_bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str | Path
|
Path to the instance data Turtle file. |
required |
shacl_path
|
str | Path
|
Path to the SHACL shape Turtle file. |
required |
inference
|
str
|
Reasoner to apply. |
'rdfs'
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BridgeResult
|
class: |
Source code in shacl_bridges/core/diff.py
save_result(result, expanded_path, diff_path)
¶
Serialize expanded and diff graphs to Turtle files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
BridgeResult
|
Output of :func: |
required |
expanded_path
|
str | Path
|
Destination path for the expanded graph. |
required |
diff_path
|
str | Path
|
Destination path for the diff graph. |
required |
Source code in shacl_bridges/core/diff.py
shacl_bridges.validate¶
shacl_bridges.validate
¶
Bridge mapping validator.
Runs structural and semantic checks on a loaded :class:BridgeMapping and
returns a list of :class:ValidationIssue objects. An empty list means the
mapping passed all checks.
CLI usage::
shacl-bridges validate my_bridge.yaml
Python usage::
from shacl_bridges.io.yaml_reader import load_mapping
from shacl_bridges.validate import validate_mapping, Severity
mapping = load_mapping("bridge.yaml")
issues = validate_mapping(mapping)
errors = [i for i in issues if i.severity == Severity.ERROR]
ValidationIssue
dataclass
¶
A single validation finding.
Source code in shacl_bridges/validate.py
validate_mapping(mapping)
¶
Run all validation checks on mapping.
Checks performed:
- Prefix completeness — every CURIE used references a declared prefix (or a well-known built-in).
- Root exists —
source_pattern.root(if set) appears in at least one source triple. - Source connectivity — every node in
source_patternis reachable from the chosen root. Disconnected nodes would cause silent over-matching. - Class-map sources ⊆ source nodes — every
class_map[].sourceappears insource_pattern.triples. - Class-map targets ⊆ target nodes — every
class_map[].targetappears intarget_pattern.triples. - Target connectivity — the target pattern forms a connected graph. Disconnected target nodes produce isolated triples in the bridge output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
BridgeMapping
|
A loaded :class: |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationIssue]
|
List of :class: |
list[ValidationIssue]
|
mapping passed all checks. |
Source code in shacl_bridges/validate.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
shacl_bridges.visualize.mermaid¶
shacl_bridges.visualize.mermaid
¶
Mermaid flowchart generation.
Produces a Mermaid flowchart TD diagram that shows:
- Core source nodes (in class_map) — rectangle
[Label] - Peripheral source nodes (validation-only, not in class_map) — stadium shape
([Label]) - Target nodes — rounded rectangle
(Label) - ShapeValidation subgraph:
- CoreShapeInformation inner subgraph: core structural triples (thick
==>arrows) - Peripheral/upper-level triples outside the inner subgraph (thin
--->arrows)
- CoreShapeInformation inner subgraph: core structural triples (thick
- TransformedGraph subgraph: target pattern triples (
-->arrows) - Bridge connections: dotted
-.....->arrows from each source class to its target class
This diagram is generated automatically from the YAML mapping and stays in sync with the source/target patterns without manual maintenance.
generate_mermaid(mapping)
¶
Generate a Mermaid flowchart diagram for mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
BridgeMapping
|
Loaded :class: |
required |
Returns:
| Type | Description |
|---|---|
str
|
Mermaid diagram string (suitable for embedding in Markdown or saving |
str
|
to a |
Source code in shacl_bridges/visualize/mermaid.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
generate_mermaid_markdown(mapping)
¶
Wrap the Mermaid diagram in a fenced code block for Markdown embedding.