SHACL¶
kurra.shacl ¶
SHACL functions.
SH12 ¶
Bases: DefinedNamespace
SHACL 1.2 Profiling vocabulary terms not yet in rdflib's DefinedNamespace SH.
validate ¶
validate(data: GraphInput | Sequence[GraphInput], shacl: Graph | Path | str | int, hide_warnings: bool = False, advanced: bool = False, return_type: Literal['basic'] = 'basic', *, use_rudof: bool = False) -> tuple[bool, Graph, str]
validate(data: GraphInput | Sequence[GraphInput], shacl: Graph | Path | str | int, hide_warnings: bool = False, advanced: bool = False, return_type: Literal['basic', 'summary', 'provenance'] = 'basic', *, use_rudof: bool = False) -> tuple[bool, Graph, str] | tuple[bool, Graph, str, Graph]
Validates a data graph using a shapes graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphInput | Sequence[GraphInput]
|
A local RDF file path (a string or Path), a graph, or a sequence of these inputs. Multiple inputs are merged before validation. |
required |
shacl
|
Graph | Path | str | int
|
The SHACL shapes to validate with |
required |
hide_warnings
|
bool
|
If True, remove Warning and Info results from the report. |
False
|
advanced
|
bool
|
Enable pySHACL's advanced features. This setting does not apply to Rudof. |
False
|
use_rudof
|
bool
|
If true, use Rudof if installed; otherwise warn and use pySHACL. |
False
|
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 |
|---|---|
tuple[bool, Graph, str] | tuple[bool, Graph, str, Graph]
|
tuple[bool, Graph, str] | tuple[bool, Graph, str, Graph]: 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
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 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 | |
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 ¶
sync_validators(http_client: Client | None = None, validator_iris: list[str] | None = None) -> dict[str, dict[str, str | list[str]]]
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. If not given, a client with a 30-second timeout is created for listing and downloading validators. |
None
|
validator_iris
|
list[str] | None
|
Only cache these validator IRIs from the remote catalogue when supplied. An empty list downloads nothing; None syncs all validators. Existing cached validators are retained. |
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
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
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 |