From 7a673ee7ffc6a71f7c1f095255e60e6196fe302d Mon Sep 17 00:00:00 2001 From: Lincoln Puzey Date: Tue, 19 Nov 2024 11:43:49 +0800 Subject: [PATCH] BDRSPS-1038 Ensure that every chunk has a dataset type triple Every chunk of RDF output should include a `<...> a tern:Dataset` triple, to make them valid RDF --- .../templates/incidental_occurrence_data_v3/mapping.py | 9 +++++++-- abis_mapping/templates/survey_metadata_v2/mapping.py | 7 +++++-- .../templates/survey_occurrence_data_v2/mapping.py | 9 +++++++-- abis_mapping/templates/survey_site_data_v2/mapping.py | 7 +++++-- .../templates/survey_site_visit_data_v2/mapping.py | 9 +++++++-- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/abis_mapping/templates/incidental_occurrence_data_v3/mapping.py b/abis_mapping/templates/incidental_occurrence_data_v3/mapping.py index ea1f5902..a7a8fdf1 100644 --- a/abis_mapping/templates/incidental_occurrence_data_v3/mapping.py +++ b/abis_mapping/templates/incidental_occurrence_data_v3/mapping.py @@ -188,8 +188,11 @@ def apply_mapping( graph = utils.rdf.create_graph() # Check if Dataset IRI Supplied - if not dataset_iri: - # Create Dataset IRI + if dataset_iri: + # If supplied, add just the dataset type. + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) + else: + # If not supplied, create example "default" Dataset IRI dataset_iri = utils.rdf.uri(f"dataset/{self.DATASET_DEFAULT_NAME}", base_iri) # Add Example Default Dataset if not Supplied @@ -221,6 +224,8 @@ def apply_mapping( # Initialise New Graph graph = utils.rdf.create_graph() + # Every chunk should have this node + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) # Yield yield graph diff --git a/abis_mapping/templates/survey_metadata_v2/mapping.py b/abis_mapping/templates/survey_metadata_v2/mapping.py index b13d5add..74385830 100644 --- a/abis_mapping/templates/survey_metadata_v2/mapping.py +++ b/abis_mapping/templates/survey_metadata_v2/mapping.py @@ -146,8 +146,11 @@ def apply_mapping( graph = utils.rdf.create_graph() # Check if Dataset IRI Supplied - if not dataset_iri: - # Create Dataset IRI + if dataset_iri: + # If supplied, add just the dataset type. + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) + else: + # If not supplied, create example "default" Dataset IRI dataset_iri = utils.rdf.uri(f"dataset/{self.DATASET_DEFAULT_NAME}", base_iri) # Add the default dataset diff --git a/abis_mapping/templates/survey_occurrence_data_v2/mapping.py b/abis_mapping/templates/survey_occurrence_data_v2/mapping.py index c7d93876..2085e3d5 100644 --- a/abis_mapping/templates/survey_occurrence_data_v2/mapping.py +++ b/abis_mapping/templates/survey_occurrence_data_v2/mapping.py @@ -311,8 +311,11 @@ def apply_mapping( graph = utils.rdf.create_graph() # Check if Dataset IRI Supplied - if not dataset_iri: - # Create Dataset IRI + if dataset_iri: + # If supplied, add just the dataset type. + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) + else: + # If not supplied, create example "default" Dataset IRI dataset_iri = utils.rdf.uri(f"dataset/{self.DATASET_DEFAULT_NAME}", base_iri) # Add Example Default Dataset if not Supplied @@ -346,6 +349,8 @@ def apply_mapping( # Initialise New Graph graph = utils.rdf.create_graph() + # Every chunk should have this node + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) # Yield yield graph diff --git a/abis_mapping/templates/survey_site_data_v2/mapping.py b/abis_mapping/templates/survey_site_data_v2/mapping.py index 796d608c..4fb5838e 100644 --- a/abis_mapping/templates/survey_site_data_v2/mapping.py +++ b/abis_mapping/templates/survey_site_data_v2/mapping.py @@ -228,8 +228,11 @@ def apply_mapping( graph = utils.rdf.create_graph() # Check if Dataset IRI Supplied - if not dataset_iri: - # Create Dataset IRI + if dataset_iri: + # If supplied, add just the dataset type. + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) + else: + # If not supplied, create example "default" Dataset IRI dataset_iri = utils.rdf.uri(f"dataset/{self.DATASET_DEFAULT_NAME}", base_iri) # Add the default dataset diff --git a/abis_mapping/templates/survey_site_visit_data_v2/mapping.py b/abis_mapping/templates/survey_site_visit_data_v2/mapping.py index 9a16bb2c..8cb27c1f 100644 --- a/abis_mapping/templates/survey_site_visit_data_v2/mapping.py +++ b/abis_mapping/templates/survey_site_visit_data_v2/mapping.py @@ -249,8 +249,11 @@ def apply_mapping( graph_has_data: bool = False # Check if Dataset IRI Supplied - if not dataset_iri: - # Create Dataset IRI + if dataset_iri: + # If supplied, add just the dataset type. + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) + else: + # If not supplied, create example "default" Dataset IRI dataset_iri = utils.rdf.uri(f"dataset/{self.DATASET_DEFAULT_NAME}", base_iri) # Add the default dataset @@ -280,6 +283,8 @@ def apply_mapping( # Initialise New Graph for next chunk graph = utils.rdf.create_graph() graph_has_data = False + # Every chunk should have this node + graph.add((dataset_iri, a, utils.namespaces.TERN.Dataset)) # yield final chunk, or whole graph if not chunking. if chunk_size is None or graph_has_data: