SHACL¶
kurra.shacl ¶
SHACL functions.
SH12 ¶
Bases: DefinedNamespace
SHACL 1.2 Profiling vocabulary terms not yet in rdflib's DefinedNamespace SH.
validate ¶
validate(data: Path | Graph | list[Path] | list[Graph], shacl: Graph | Path | str | int, hide_warnings: bool = False, advanced: bool = False, return_type: Literal['basic'] = 'basic') -> tuple[bool, Graph, str]
validate(data: Path | Graph | list[Path] | list[Graph], shacl: Graph | Path | str | int, hide_warnings: bool = False, advanced: bool = False, return_type: Literal['basic', 'summary', 'provenance'] = 'basic')
Validates a data graph using a shapes graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Path | Graph | list[Path] | list[Graph]
|
The path to an RDF data file, a graph, a list of Paths or a list of Graphs to validate. List items will be merged |
required |
shacl
|
Graph | Path | str | int
|
The SHACL shapes to validate with |
required |
return_type
|
Literal['basic', 'summary', 'provenance']
|
What to return alongside the validation status, results graph and message. "basic" (the default) returns just those three. "summary" adds a compact summary graph. "provenance" adds a PROV-O provenance graph, per the SHACL 1.2 Profiling vocabulary's persisting validation results guidance. |
'basic'
|
Returns:
| Type | Description |
|---|---|
|
The validation status, results graph and message, plus a summary graph or a provenance |
|
|
graph if requested via return_type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a given local validator ID is out of range. |
RuntimeError
|
If the shapes graph cannot be resolved, locally or from the Semantic Background. |
Source code in kurra/shacl.py
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 | |
list_local_validators ¶
List the SHACL validators cached locally, without contacting the Semantic Background.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, int]] | None
|
A dict keyed by validator IRI, each value holding |
Source code in kurra/shacl.py
sync_validators ¶
Refresh the local SHACL validator cache from the Semantic Background, downloading any validators not already cached locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed to access a SPARQL endpoint as context. A new one is created if not given. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, str | list[str]]]
|
The refreshed local validator listing, in the same form as |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the Semantic Background's validator set is not yet available. |
RuntimeError
|
If a validator's graph could not be fetched from the SPARQL endpoint. |
Source code in kurra/shacl.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
get_validator_graph ¶
Resolve a validator reference to its shapes graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_or_file_or_url_or_id
|
Graph | Path | str | int
|
A Graph, RDF file path, local validator ID, or path/URL string. |
required |
Returns:
| Type | Description |
|---|---|
Graph | None
|
The resolved shapes Graph, or None if it could not be resolved. |
Source code in kurra/shacl.py
check_validator_known ¶
Check whether a validator identified by IRI is known either locally or via the Semantic Background. If not found locally the cache is synced to the Semantic Background for a recheck.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator_iri
|
str
|
The IRI of the validator to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the validator is known, either locally or after syncing from the Semantic Background. |
Source code in kurra/shacl.py
infer ¶
Apply SHACL Rules (SRL) to a data graph and return the inferred triples.
If rules contains a SPARQL DELETE statement, it is run directly as a SPARQL update instead of being parsed as SRL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Graph | Path | str
|
The data graph to apply the rules to. |
required |
rules
|
Graph | Path | str
|
The SRL rules to apply, as a string or a path to a |
required |
include_base
|
bool
|
If True, include the original data triples in the result. |
False
|
Returns:
| Type | Description |
|---|---|
Graph
|
The inferred triples, or (if |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If |
ValueError
|
If |