ogc-na 0.4__tar.gz → 0.4.1__tar.gz

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.

Files changed (61) hide show
  1. {ogc_na-0.4 → ogc_na-0.4.1}/PKG-INFO +1 -1
  2. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/_version.py +2 -2
  3. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/ingest_json.py +52 -9
  4. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/provenance.py +18 -2
  5. {ogc_na-0.4 → ogc_na-0.4.1}/ogc_na.egg-info/PKG-INFO +1 -1
  6. {ogc_na-0.4 → ogc_na-0.4.1}/.github/workflows/mkdocs.yml +0 -0
  7. {ogc_na-0.4 → ogc_na-0.4.1}/.github/workflows/python-publish.yml +0 -0
  8. {ogc_na-0.4 → ogc_na-0.4.1}/.gitignore +0 -0
  9. {ogc_na-0.4 → ogc_na-0.4.1}/MANIFEST.in +0 -0
  10. {ogc_na-0.4 → ogc_na-0.4.1}/README.md +0 -0
  11. {ogc_na-0.4 → ogc_na-0.4.1}/docs/examples.md +0 -0
  12. {ogc_na-0.4 → ogc_na-0.4.1}/docs/gen_ref_pages.py +0 -0
  13. {ogc_na-0.4 → ogc_na-0.4.1}/docs/index.md +0 -0
  14. {ogc_na-0.4 → ogc_na-0.4.1}/docs/jsonld-uplift.md +0 -0
  15. {ogc_na-0.4 → ogc_na-0.4.1}/docs/tutorials.md +0 -0
  16. {ogc_na-0.4 → ogc_na-0.4.1}/mkdocs.yml +0 -0
  17. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/__init__.py +0 -0
  18. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/annotate_schema.py +0 -0
  19. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/domain_config.py +0 -0
  20. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/download.py +0 -0
  21. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/exceptions.py +0 -0
  22. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/gsp.py +0 -0
  23. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/input_filters/__init__.py +0 -0
  24. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/input_filters/csv.py +0 -0
  25. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/input_filters/xlsx.py +0 -0
  26. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/input_filters/xml.py +0 -0
  27. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/models.py +0 -0
  28. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/profile.py +0 -0
  29. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/update_vocabs.py +0 -0
  30. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/util.py +0 -0
  31. {ogc_na-0.4 → ogc_na-0.4.1}/ogc/na/validation.py +0 -0
  32. {ogc_na-0.4 → ogc_na-0.4.1}/ogc_na.egg-info/SOURCES.txt +0 -0
  33. {ogc_na-0.4 → ogc_na-0.4.1}/ogc_na.egg-info/dependency_links.txt +0 -0
  34. {ogc_na-0.4 → ogc_na-0.4.1}/ogc_na.egg-info/requires.txt +0 -0
  35. {ogc_na-0.4 → ogc_na-0.4.1}/ogc_na.egg-info/top_level.txt +0 -0
  36. {ogc_na-0.4 → ogc_na-0.4.1}/pyproject.toml +0 -0
  37. {ogc_na-0.4 → ogc_na-0.4.1}/rdf/catalog-v001.xml +0 -0
  38. {ogc_na-0.4 → ogc_na-0.4.1}/rdf/domaincfg.vocab.ttl +0 -0
  39. {ogc_na-0.4 → ogc_na-0.4.1}/requirements.txt +0 -0
  40. {ogc_na-0.4 → ogc_na-0.4.1}/setup.cfg +0 -0
  41. {ogc_na-0.4 → ogc_na-0.4.1}/setup.py +0 -0
  42. {ogc_na-0.4 → ogc_na-0.4.1}/test/__init__.py +0 -0
  43. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/empty.ttl +0 -0
  44. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/headers.csv +0 -0
  45. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/headers.xlsx +0 -0
  46. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/no-headers.csv +0 -0
  47. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/no-headers.xlsx +0 -0
  48. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/profile_tree.ttl +0 -0
  49. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/profile_tree_cyclic.ttl +0 -0
  50. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/sample-context.jsonld +0 -0
  51. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/sample-schema-prop-c.yml +0 -0
  52. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/sample-schema.yml +0 -0
  53. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/schema-anchors.json +0 -0
  54. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/schema-vocab.yml +0 -0
  55. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/two-sheets.xlsx +0 -0
  56. {ogc_na-0.4 → ogc_na-0.4.1}/test/data/uplift_context_valid.yml +0 -0
  57. {ogc_na-0.4 → ogc_na-0.4.1}/test/test_annotate_schema.py +0 -0
  58. {ogc_na-0.4 → ogc_na-0.4.1}/test/test_ingest_json.py +0 -0
  59. {ogc_na-0.4 → ogc_na-0.4.1}/test/test_input_filters_csv.py +0 -0
  60. {ogc_na-0.4 → ogc_na-0.4.1}/test/test_input_filters_xlsx.py +0 -0
  61. {ogc_na-0.4 → ogc_na-0.4.1}/test/test_profile.py +0 -0
@@ -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/
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.4'
21
- __version_tuple__ = version_tuple = (0, 4)
20
+ __version__ = version = '0.4.1'
21
+ __version_tuple__ = version_tuple = (0, 4, 1)
@@ -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) -> UpliftResult | 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.output = FileProvenanceMetadata(mime_type='text/turtle', use_bnode=False)
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.output = FileProvenanceMetadata(filename=ttl_fn,
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) -> list[UpliftResult]:
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:
@@ -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.used if isinstance(metadata.generated, Sequence) else (metadata.generated,):
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/
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes