Utilities¶
kgm.utils
¶
path_or_url(s: str) -> Path | str
¶
get_files_from_artifact(manifest: Path | tuple[Path, Path, Graph], artifact: Node) -> list[Path | str] | Generator[Path]
¶
Returns an iterable (list or generator) of Path objects for files within an artifact literal.
This function will correctly interpret artifacts such as 'file.ttl', '.ttl', '**/.trig' etc.
Source code in kgm/utils.py
get_identifier_from_file(file: Path) -> list[URIRef]
¶
Returns a list if RDFLib graph identifier (URIRefs) from a triples or quads file for all KNOWN_ENTITY_CLASSES objects
Source code in kgm/utils.py
get_manifest_paths_and_graph(manifest: Path | tuple[Path, Path, Graph]) -> (Path, Graph)
¶
Reads either a Manifest file from a Path, or a Manifest file from a Path and its root directory, a Path, and the Manifest as a deserialized Graph and returns the Manifest Path, its root dir as a Path and its content as a Graph
Source code in kgm/utils.py
get_artifact_main_entity_iri(artifact: Path, manifest: Path | tuple[Path, Path, Graph], artifact_graph: Graph = None, cc: URIRef = None, atype: URIRef = None) -> URIRef
¶
Gets the IRI of the instance of the Main Entity in an artifact where the class of the Main Entity is either one of KNOWN_ENTITY_CLASSES or supplied in the Manifest either as a class to search for - by using schema:additionalType - or by directly indicating the IRI of the main Entity with schema:mainEntity
Source code in kgm/utils.py
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 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 | |
compare_version_indicators(first: dict, second: dict) -> VersionIndicatorComparison
¶
Compares Modified Date, Version IRI & Version info for each and returns latest
Source code in kgm/utils.py
which_is_more_recent(version_indicators: dict, sparql_endpoint: str = None, http_client: httpx.Client | None = None) -> VersionIndicatorComparison
¶
Tests to see if the given artifact is more recent than a previously stored copy of its content
Source code in kgm/utils.py
denormalise_artifacts(manifest: Path | tuple[Path, Path, Graph]) -> dict
¶
Extracts all the artifacts from a Manifest.
Returns a dict of:
Artifact path, Main Entity, Conformance Claims Date Modified Version IRI Version Info Role Version Indicators
Source code in kgm/utils.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
store_remote_artifact_locally(manifest: Path | tuple[Path, Path, Graph], sparql_endpoint: str, graph_id: str, http_client: httpx.Client | None = None) -> Graph
¶
Writes a remote graph to a local file and registers that file as a Resource in the given Manifest.
Only the Resource Role ResourceData is supported.
Source code in kgm/utils.py
get_background_graph(manifest: Path | tuple[Path, Path, Graph]) -> Graph
¶
Returns the contents of all Manifest resources with role *CatalogueAndResourceLabels as a graph