Utilities
kgm.utils
path_or_url(s: str) -> Path | str
Converts a string into a Path, preserving http(s)://...
Source code in kgm/utils.py
59 60 61 62 63 64 | |
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
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 | |
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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
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
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
resource_is_ignored(manifest_graph: Graph, resource: Node) -> bool
Whether a resource descriptor opts all of its artifacts out of processing.
Source code in kgm/utils.py
155 156 157 | |
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
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 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
print_local_version_indicators(file: Path | str, manifest: Path | str | None = None) -> None
Print the version metadata sync() reads from a local RDF file.
If the file is listed in the manifest, use its metadata before inspecting the RDF. File size is reported for context but is not used in version comparison.
Source code in kgm/utils.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
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
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 | |
which_is_more_recent(version_indicators: dict, sparql_endpoint: str = None, http_client: httpx2.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
638 639 640 641 642 643 644 645 646 647 648 649 | |
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
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
store_remote_artifact_locally(manifest: Path | tuple[Path, Path, Graph], sparql_endpoint: str, graph_id: str, http_client: httpx2.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
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | |
get_background_graph(manifest: Path | tuple[Path, Path, Graph]) -> Graph
Returns the contents of all Manifest resources with role *CatalogueAndResourceLabels as a graph
Source code in kgm/utils.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |