ogc-na 0.4__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ogc-na might be problematic. Click here for more details.
- ogc/na/_version.py +2 -2
- ogc/na/ingest_json.py +52 -9
- ogc/na/provenance.py +18 -2
- {ogc_na-0.4.dist-info → ogc_na-0.4.1.dist-info}/METADATA +1 -1
- {ogc_na-0.4.dist-info → ogc_na-0.4.1.dist-info}/RECORD +7 -7
- {ogc_na-0.4.dist-info → ogc_na-0.4.1.dist-info}/WHEEL +1 -1
- {ogc_na-0.4.dist-info → ogc_na-0.4.1.dist-info}/top_level.txt +0 -0
ogc/na/_version.py
CHANGED
ogc/na/ingest_json.py
CHANGED
|
@@ -45,7 +45,7 @@ from typing import Union, Optional, Sequence, cast, Iterable, Any
|
|
|
45
45
|
import jq
|
|
46
46
|
from jsonpath_ng.ext import parse as json_path_parse
|
|
47
47
|
from jsonschema import validate as json_validate
|
|
48
|
-
from rdflib import Graph, DC, DCTERMS, SKOS, OWL, RDF, RDFS, XSD, DCAT
|
|
48
|
+
from rdflib import Graph, DC, DCTERMS, SKOS, OWL, RDF, RDFS, XSD, DCAT, URIRef
|
|
49
49
|
from rdflib.namespace import Namespace, DefinedNamespace
|
|
50
50
|
|
|
51
51
|
from ogc.na import util, profile
|
|
@@ -418,7 +418,8 @@ def process_file(input_fn: str | Path,
|
|
|
418
418
|
provenance_base_uri: str | bool | None = None,
|
|
419
419
|
provenance_process_id: str | None = None,
|
|
420
420
|
fetch_url_whitelist: bool | Sequence[str] | None = None,
|
|
421
|
-
transform_args: dict | None = None
|
|
421
|
+
transform_args: dict | None = None,
|
|
422
|
+
generated_provenance_classes: bool | list[str | URIRef] = False) -> UpliftResult | None:
|
|
422
423
|
"""
|
|
423
424
|
Process input file and generate output RDF files.
|
|
424
425
|
|
|
@@ -439,6 +440,8 @@ def process_file(input_fn: str | Path,
|
|
|
439
440
|
retrieving them. If None, it will not be used; if empty sequence or False, remote fetching operations will
|
|
440
441
|
throw an exception
|
|
441
442
|
:param transform_args: Additional arguments to pass as variables to the jq transform
|
|
443
|
+
:param generated_provenance_classes: List of classes whose instances will be included in the "generated"
|
|
444
|
+
provenance metadata. If `True`, all subjects in the output graph will be added.
|
|
442
445
|
:return: List of output files created
|
|
443
446
|
"""
|
|
444
447
|
|
|
@@ -489,16 +492,16 @@ def process_file(input_fn: str | Path,
|
|
|
489
492
|
|
|
490
493
|
provenance_metadata: ProvenanceMetadata | None = None
|
|
491
494
|
if provenance_base_uri is not False:
|
|
492
|
-
used = [FileProvenanceMetadata(filename=input_fn, mime_type='application/json')]
|
|
493
|
-
used.extend(FileProvenanceMetadata(filename=c, mime_type='application/yaml') for c in provenance_contexts)
|
|
494
495
|
provenance_metadata = ProvenanceMetadata(
|
|
495
|
-
used=used,
|
|
496
496
|
batch_activity_id=provenance_process_id,
|
|
497
497
|
base_uri=provenance_base_uri,
|
|
498
498
|
root_directory=os.getcwd(),
|
|
499
499
|
start=start_time,
|
|
500
500
|
end_auto=True,
|
|
501
501
|
)
|
|
502
|
+
provenance_metadata.add_used(FileProvenanceMetadata(filename=input_fn, mime_type='application/json'))
|
|
503
|
+
provenance_metadata.add_used(FileProvenanceMetadata(filename=c, mime_type='application/yaml')
|
|
504
|
+
for c in provenance_contexts)
|
|
502
505
|
|
|
503
506
|
if transform_args is None:
|
|
504
507
|
transform_args = {}
|
|
@@ -518,13 +521,29 @@ def process_file(input_fn: str | Path,
|
|
|
518
521
|
|
|
519
522
|
uplift_result.input_file = input_fn
|
|
520
523
|
|
|
524
|
+
if provenance_metadata and generated_provenance_classes:
|
|
525
|
+
if generated_provenance_classes is True:
|
|
526
|
+
# add all subjects to "generated"
|
|
527
|
+
provenance_metadata.add_generated(
|
|
528
|
+
FileProvenanceMetadata(uri=str(s), use_bnode=False)
|
|
529
|
+
for s in uplift_result.graph.subjects()
|
|
530
|
+
if isinstance(s, URIRef)
|
|
531
|
+
)
|
|
532
|
+
elif generated_provenance_classes:
|
|
533
|
+
provenance_metadata.add_generated(
|
|
534
|
+
FileProvenanceMetadata(uri=str(s), use_bnode=False)
|
|
535
|
+
for cls in generated_provenance_classes
|
|
536
|
+
for s in uplift_result.graph.subjects(predicate=RDF.type, object=URIRef(cls))
|
|
537
|
+
if isinstance(s, URIRef)
|
|
538
|
+
)
|
|
539
|
+
|
|
521
540
|
# False = do not generate
|
|
522
541
|
# None = auto filename
|
|
523
542
|
# - = stdout
|
|
524
543
|
if ttl_fn is not False:
|
|
525
544
|
if ttl_fn == '-':
|
|
526
545
|
if provenance_metadata:
|
|
527
|
-
provenance_metadata.
|
|
546
|
+
provenance_metadata.add_generated(FileProvenanceMetadata(mime_type='text/turtle', use_bnode=False))
|
|
528
547
|
generate_provenance(uplift_result.graph, provenance_metadata)
|
|
529
548
|
print(uplift_result.graph.serialize(format='ttl'))
|
|
530
549
|
else:
|
|
@@ -533,9 +552,9 @@ def process_file(input_fn: str | Path,
|
|
|
533
552
|
if input_fn.suffix != '.ttl' \
|
|
534
553
|
else input_fn.with_suffix(input_fn.suffix + '.ttl')
|
|
535
554
|
if provenance_metadata:
|
|
536
|
-
provenance_metadata.
|
|
555
|
+
provenance_metadata.add_generated(FileProvenanceMetadata(filename=ttl_fn,
|
|
537
556
|
mime_type='text/turtle',
|
|
538
|
-
use_bnode=False)
|
|
557
|
+
use_bnode=False))
|
|
539
558
|
generate_provenance(uplift_result.graph, provenance_metadata)
|
|
540
559
|
uplift_result.graph.serialize(destination=ttl_fn, format='ttl')
|
|
541
560
|
uplift_result.output_files.append(ttl_fn)
|
|
@@ -656,7 +675,8 @@ def process(input_files: str | Path | Sequence[str | Path],
|
|
|
656
675
|
provenance_base_uri: Optional[Union[str, bool]] = None,
|
|
657
676
|
fetch_url_whitelist: Optional[Union[Sequence, bool]] = None,
|
|
658
677
|
transform_args: dict | None = None,
|
|
659
|
-
file_filter: str | re.Pattern = None
|
|
678
|
+
file_filter: str | re.Pattern = None,
|
|
679
|
+
generated_provenance_classes: bool | list[str | URIRef] = False) -> list[UpliftResult]:
|
|
660
680
|
"""
|
|
661
681
|
Performs the JSON-LD uplift process.
|
|
662
682
|
|
|
@@ -678,6 +698,8 @@ def process(input_files: str | Path | Sequence[str | Path],
|
|
|
678
698
|
throw an exception
|
|
679
699
|
:param transform_args: Additional arguments to pass as variables to the jq transform
|
|
680
700
|
:param file_filter: Filename filter for input files
|
|
701
|
+
:param generated_provenance_classes: List of classes whose instances will be included in the "generated"
|
|
702
|
+
provenance metadata. If `True`, all subjects in the output graph will be added.
|
|
681
703
|
:return: a list of JSON-LD and/or Turtle output files
|
|
682
704
|
"""
|
|
683
705
|
result: list[UpliftResult] = []
|
|
@@ -729,6 +751,7 @@ def process(input_files: str | Path | Sequence[str | Path],
|
|
|
729
751
|
fetch_url_whitelist=fetch_url_whitelist,
|
|
730
752
|
domain_cfg=domain_cfg,
|
|
731
753
|
transform_args=transform_args,
|
|
754
|
+
generated_provenance_classes=generated_provenance_classes,
|
|
732
755
|
))
|
|
733
756
|
except MissingContextException as e:
|
|
734
757
|
if skip_on_missing_context or batch:
|
|
@@ -751,6 +774,7 @@ def process(input_files: str | Path | Sequence[str | Path],
|
|
|
751
774
|
fetch_url_whitelist=fetch_url_whitelist,
|
|
752
775
|
domain_cfg=domain_cfg,
|
|
753
776
|
transform_args=transform_args,
|
|
777
|
+
generated_provenance_classes=generated_provenance_classes,
|
|
754
778
|
))
|
|
755
779
|
except Exception as e:
|
|
756
780
|
if skip_on_missing_context:
|
|
@@ -879,6 +903,18 @@ def _process_cmdln():
|
|
|
879
903
|
help='Regular expression to filter input filenames',
|
|
880
904
|
)
|
|
881
905
|
|
|
906
|
+
parser.add_argument(
|
|
907
|
+
'--generated-provenance-classes',
|
|
908
|
+
nargs='*',
|
|
909
|
+
help='Classes whose subjects will be included in the "generated" provenance metadata',
|
|
910
|
+
)
|
|
911
|
+
|
|
912
|
+
parser.add_argument(
|
|
913
|
+
'--all-subjects-provenance',
|
|
914
|
+
action='store_true',
|
|
915
|
+
help='Add all subjects in the resulting graph to the "generated" provenance metadata',
|
|
916
|
+
)
|
|
917
|
+
|
|
882
918
|
args = parser.parse_args()
|
|
883
919
|
|
|
884
920
|
if args.domain_config:
|
|
@@ -904,6 +940,12 @@ def _process_cmdln():
|
|
|
904
940
|
if args.transform_arg:
|
|
905
941
|
transform_args = dict((e.split('=', 1) for e in args.transform_arg))
|
|
906
942
|
|
|
943
|
+
generated_provenance_classes = False
|
|
944
|
+
if args.all_subjects_provenance:
|
|
945
|
+
generated_provenance_classes = True
|
|
946
|
+
elif args.generated_provenance_classes:
|
|
947
|
+
generated_provenance_classes = args.generated_provenance_classes
|
|
948
|
+
|
|
907
949
|
result = process(input_files,
|
|
908
950
|
context_fn=args.context,
|
|
909
951
|
domain_cfg=domain_cfg,
|
|
@@ -915,6 +957,7 @@ def _process_cmdln():
|
|
|
915
957
|
fetch_url_whitelist=args.url_whitelist,
|
|
916
958
|
transform_args=transform_args,
|
|
917
959
|
file_filter=args.file_filter,
|
|
960
|
+
generated_provenance_classes=generated_provenance_classes,
|
|
918
961
|
)
|
|
919
962
|
|
|
920
963
|
if args.fs:
|
ogc/na/provenance.py
CHANGED
|
@@ -4,7 +4,7 @@ import mimetypes
|
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import Union, Optional, Sequence
|
|
7
|
+
from typing import Union, Optional, Sequence, Iterable
|
|
8
8
|
|
|
9
9
|
from rdflib.term import Node
|
|
10
10
|
|
|
@@ -40,6 +40,22 @@ class ProvenanceMetadata:
|
|
|
40
40
|
activity_label: str = None
|
|
41
41
|
comment: str = None
|
|
42
42
|
|
|
43
|
+
def _add_list(self, attr: str, item: FileProvenanceMetadata | Iterable[FileProvenanceMetadata]):
|
|
44
|
+
items = [item] if isinstance(item, FileProvenanceMetadata) else [*item]
|
|
45
|
+
cur: FileProvenanceMetadata | list[FileProvenanceMetadata] | None = getattr(self, attr, None)
|
|
46
|
+
if not cur:
|
|
47
|
+
setattr(self, attr, items)
|
|
48
|
+
elif isinstance(cur, FileProvenanceMetadata):
|
|
49
|
+
setattr(self, attr, [self.used, *items])
|
|
50
|
+
else:
|
|
51
|
+
setattr(self, attr, cur + items)
|
|
52
|
+
|
|
53
|
+
def add_used(self, used: FileProvenanceMetadata | Iterable[FileProvenanceMetadata]) -> None:
|
|
54
|
+
self._add_list('used', used)
|
|
55
|
+
|
|
56
|
+
def add_generated(self, generated: FileProvenanceMetadata | Iterable[FileProvenanceMetadata]) -> None:
|
|
57
|
+
self._add_list('generated', generated)
|
|
58
|
+
|
|
43
59
|
|
|
44
60
|
def add_provenance_agent(g: Graph, module_name: str = None) -> Node:
|
|
45
61
|
agent = BNode()
|
|
@@ -133,7 +149,7 @@ def generate_provenance(g: Graph = None,
|
|
|
133
149
|
g.add((activity, PROV.used, used))
|
|
134
150
|
|
|
135
151
|
if metadata.generated:
|
|
136
|
-
for generated in metadata.
|
|
152
|
+
for generated in metadata.generated if isinstance(metadata.generated, Sequence) else (metadata.generated,):
|
|
137
153
|
generated = add_provenance_entity(g, metadata=generated,
|
|
138
154
|
root_directory=metadata.root_directory,
|
|
139
155
|
base_uri=metadata.base_uri)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ogc_na
|
|
3
|
-
Version: 0.4
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: OGC Naming Authority tools
|
|
5
5
|
Author-email: Rob Atkinson <ratkinson@ogc.org>, Piotr Zaborowski <pzaborowski@ogc.org>, Alejandro Villar <avillar@ogc.org>
|
|
6
6
|
Project-URL: Homepage, https://github.com/opengeospatial/ogc-na-tools/
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
ogc/na/__init__.py,sha256=uzcNiJ3uKFNJ1HBfKxIwgAy2HMUFsLAe5RkrUg8ncac,464
|
|
2
|
-
ogc/na/_version.py,sha256=
|
|
2
|
+
ogc/na/_version.py,sha256=yF2DwGUoQKNnLhAbpZX8kCQKjw77EZzhRk7_OTftets,511
|
|
3
3
|
ogc/na/annotate_schema.py,sha256=YtxL9pOeeVk9CubvnByUMh7nZUJYZCDQ60hXEvtiR6g,43869
|
|
4
4
|
ogc/na/domain_config.py,sha256=ORzITa1rTrD1MQdpWYrIVW5SwSa9lJd3hnyHIxNgiIU,13947
|
|
5
5
|
ogc/na/download.py,sha256=2afrLyl4WsAlxkCgXsl47fs9mNKfDmhVpeT2iwNSoq0,3354
|
|
6
6
|
ogc/na/exceptions.py,sha256=cwvnq79ih90T9lfwJww0zOx_QwuICaUvlo3Mc8m8ouA,85
|
|
7
7
|
ogc/na/gsp.py,sha256=KGa2G9i8kPefYTHNPUDoXnNyF7Tiwt8K__Ew_Qa7eeg,6048
|
|
8
|
-
ogc/na/ingest_json.py,sha256=
|
|
8
|
+
ogc/na/ingest_json.py,sha256=tCqQLxudnI7aIG9XslGm0tdvbfIY68HPrtgYfKtWO4A,37889
|
|
9
9
|
ogc/na/models.py,sha256=nGV8EALtXvmBtkUbu0FA4KOgwNUqQGWIDuMo7UGOKP8,652
|
|
10
10
|
ogc/na/profile.py,sha256=T7nesbm7azF2ijF60UenJnQQKjIgJlnJ3pUbGT5nYgM,16511
|
|
11
|
-
ogc/na/provenance.py,sha256=
|
|
11
|
+
ogc/na/provenance.py,sha256=BXiyF6zuRhCz7s_6-m8VtM1DduVo1sA6_2xCLxSM0qQ,6365
|
|
12
12
|
ogc/na/update_vocabs.py,sha256=9um_Qn3Si6yQ20qLYsFhiaXcxA2ryzduvYprNb252-U,21370
|
|
13
13
|
ogc/na/util.py,sha256=Ztju3g1YuguUDbk4n2RJfCrl_IIzNAj7linfy24T6VA,12067
|
|
14
14
|
ogc/na/validation.py,sha256=5xjHH55NZKM8HtUk8XgVzm8W5ZlZY00u_qsWfXK_8dM,3732
|
|
@@ -16,7 +16,7 @@ ogc/na/input_filters/__init__.py,sha256=AhE7n_yECwxFKwOM3Jc0ft96TtF5i_Z-fHrS4HYO
|
|
|
16
16
|
ogc/na/input_filters/csv.py,sha256=nFfB1XQF_QApcGGzMqEvzD_b3pBtCtsfUECsZ9UGE6s,2616
|
|
17
17
|
ogc/na/input_filters/xlsx.py,sha256=X9EpFgC9WwHQD8iUJRGdaDYfgiLKjXPdhTVhDmNPAQ0,2730
|
|
18
18
|
ogc/na/input_filters/xml.py,sha256=9qYjp_w5JLInFM48zB15IYH9eTafjp1Aqd_8kfuW3aA,2074
|
|
19
|
-
ogc_na-0.4.dist-info/METADATA,sha256
|
|
20
|
-
ogc_na-0.4.dist-info/WHEEL,sha256=
|
|
21
|
-
ogc_na-0.4.dist-info/top_level.txt,sha256=Kvy3KhzcIhNPT4_nZuJCmS946ptRr_MDyU4IIhZJhCY,4
|
|
22
|
-
ogc_na-0.4.dist-info/RECORD,,
|
|
19
|
+
ogc_na-0.4.1.dist-info/METADATA,sha256=bAH5KO7c58VAGevT5L4FoWzCKQU_yKSGGnco9_uc0xo,3842
|
|
20
|
+
ogc_na-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
+
ogc_na-0.4.1.dist-info/top_level.txt,sha256=Kvy3KhzcIhNPT4_nZuJCmS946ptRr_MDyU4IIhZJhCY,4
|
|
22
|
+
ogc_na-0.4.1.dist-info/RECORD,,
|
|
File without changes
|