ontocast.tool.shapes_catalog¶
SHACL shapes catalog: the shapes partition of the triple store.
Shapes are a deployment artifact, not a per-process file path. A catalog that declares constraints ships them alongside its schema, and a tenant that owns a catalog owns its shapes -- so they live in the triple store, in their own partition, seeded once from disk and mutable over HTTP thereafter.
Why a partition of their own rather than the ontologies dataset: catalog
discovery claims every named graph carrying an owl:Ontology subject, and a
shapes document declares one. Stored beside the ontologies, a shapes file
registers as a catalog entry, gets indexed as ontology atoms, and is offered to
the renderer as first-class schema.
The facts validation gate is synchronous, so it cannot read the store itself.
This catalog resolves the merged shapes graph once, asynchronously, and hands
the gate a plain :class:~ontocast.onto.rdfgraph.RDFGraph.
Attributes¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
ShapesCatalog
¶
Bases: Tool
The shapes partition, and the merged graph the validation gate reads.
Partition-scoped, like
:class:~ontocast.tool.ontology_manager.OntologyManager: everything held
here belongs to one tenant/project, so a tenancy switch must
:meth:reset it.
Source code in ontocast/tool/shapes_catalog.py
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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
Methods:¶
__init__(**kwargs)
¶
Initialize an empty catalog with no triple store registered.
Source code in ontocast/tool/shapes_catalog.py
conformance_chapter(*, max_lines)
¶
The whole catalog rendered as a prompt chapter; "" without shapes.
Memoized per merged graph -- run-constant, shared by every unit of every document in a tenancy.
Source code in ontocast/tool/shapes_catalog.py
delete(graph_uri)
async
¶
Remove one shapes document and refresh the merged graph.
Source code in ontocast/tool/shapes_catalog.py
graph()
¶
Return the merged shapes graph, or None when nothing is stored.
None is load-bearing downstream: it is what keeps
facts_conformance.shacl_evaluated at None ("never checked")
rather than reporting a clean run against no shapes.
Source code in ontocast/tool/shapes_catalog.py
ingest(graph, *, graph_uri)
async
¶
Store one shapes document and refresh the merged graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
RDFGraph
|
The parsed shapes document. |
required |
graph_uri
|
str
|
Named graph to store it under. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The graph URI it was stored at. |
Source code in ontocast/tool/shapes_catalog.py
list_graph_uris()
async
¶
List the named graphs in the shapes partition.
Uses a named-graph listing rather than the ontology header query: a
shapes document is not required to declare an owl:Ontology header,
and one stored without a header must still be visible.
Source code in ontocast/tool/shapes_catalog.py
needs_selection(*, max_lines)
¶
Whether the catalog's rule lines exceed the prompt cap.
Below the cap the whole-catalog chapter is strictly better than any selection: run-constant, memoized once, no per-unit variance. Above it, rendering everything means blind truncation in document order, and per-unit selection takes over.
Source code in ontocast/tool/shapes_catalog.py
prompt_contract_terms(*, max_lines)
¶
IRIs the shapes require of the output (the exemption set).
Deliberately the FULL catalog's terms whatever selection does to the chapter: exemptions protect legitimate catalog IRIs from UNKNOWN_TERM, and the gate validates against every shape.
Source code in ontocast/tool/shapes_catalog.py
register_triple_store(manager)
¶
reset()
¶
selected_chapter(context_terms, *, max_lines)
¶
The chapter for one unit, joined on its ontology-context IRIs.
A shape is included iff its own terms (targets, paths, classes)
intersect context_terms. Distinct selections per run are bounded
by the unit count, so rendered chapters are cached by selected-anchor
set (bounded; oldest evicted first).
Source code in ontocast/tool/shapes_catalog.py
sync(shapes_dir=None)
async
¶
Seed from shapes_dir when needed, then materialize the merged graph.
Seeding mirrors the ontology bootstrap in
:meth:ontocast.toolbox.ToolBox._synchronize_ontologies: the directory
is a read-only fixture, the store is the persistence. Unlike that path
the search is recursive, matching what the validation gate accepted from
FACTS_SHAPES_DIR before shapes were stored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shapes_dir
|
str | None
|
Seed directory of |
None
|
Source code in ontocast/tool/shapes_catalog.py
Functions:¶
content_graph_uri(ttl)
¶
seed_graph_uri(path, root)
¶
Fallback graph name for a headerless shapes file, derived from its path.
Source code in ontocast/tool/shapes_catalog.py
shapes_graph_uri(graph, *, fallback)
¶
Name the named graph a shapes document is stored under.
A shapes document that declares an owl:Ontology header is addressed by
that IRI, which makes replace and delete by IRI work the way they do for
ontologies. A bare SHACL file has no identity of its own, so the caller's
fallback names it -- stable across edits, so re-seeding replaces the
document rather than accumulating stale copies beside it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
RDFGraph
|
The parsed shapes document. |
required |
fallback
|
str
|
Graph name to use when the document declares no ontology IRI. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The named-graph URI. |