Skip to content

Commit

Permalink
made mapping changes to the newest occurrence templates, to allow ide…
Browse files Browse the repository at this point in the history
…ntifier rdf changes.
  • Loading branch information
joecrowleygaia committed Sep 2, 2024
1 parent 9bbaf2f commit e204a2a
Show file tree
Hide file tree
Showing 7 changed files with 658 additions and 453 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Dockerfile
# Generated documents for testing
/result.csv
/result.md
/tests/templates/**/*-result.ttl
/docs/pages/**/*.md
!/docs/pages/index.md
/docs/pages/index.html
Expand Down

Large diffs are not rendered by default.

117 changes: 49 additions & 68 deletions abis_mapping/templates/incidental_occurrence_data_v3/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
CONCEPT_CONSERVATION_JURISDICTION = rdflib.URIRef("http://linked.data.gov.au/def/tern-cv/755b1456-b76f-4d54-8690-10e41e25c5a7") # noqa: E501

# Roles
ROLE_ORIGINATOR = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/originator") # noqa: E501
ROLE_RIGHTS_HOLDER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/rightsHolder") # noqa: E501
ROLE_RESOURCE_PROVIDER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/resourceProvider") # noqa: E501
ROLE_CUSTODIAN = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/custodian") # noqa: E501
ROLE_STAKEHOLDER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/stakeholder") # noqa: E501
ROLE_OWNER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/owner") # noqa: E501
CI_ROLECODE_ORIGINATOR = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/originator") # noqa: E501
CI_ROLECODE_RIGHTS_HOLDER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/rightsHolder") # noqa: E501
CI_ROLECODE_RESOURCE_PROVIDER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/resourceProvider") # noqa: E501
CI_ROLECODE_CUSTODIAN = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/custodian") # noqa: E501
CI_ROLECODE_STAKEHOLDER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/stakeholder") # noqa: E501
CI_ROLECODE_OWNER = rdflib.URIRef("http://def.isotc211.org/iso19115/-1/2018/CitationAndResponsiblePartyInformation/code/CI_RoleCode/owner") # noqa: E501
DATA_ROLE_RESOURCE_PROVIDER = rdflib.URIRef("https://linked.data.gov.au/def/data-roles/resourceProvider")
DATA_ROLE_OWNER = rdflib.URIRef("https://linked.data.gov.au/def/data-roles/owner")


class IncidentalOccurrenceMapper(base.mapper.ABISMapper):
Expand Down Expand Up @@ -282,14 +284,14 @@ def apply_mapping_row(
conservation_jurisdiction_value = utils.rdf.uri(f"value/conservationJurisdiction/{row_num}", base_iri)
provider_determined_by = utils.rdf.uri(f"provider/{row['threatStatusDeterminedBy']}", base_iri)
provider_record_id_datatype = utils.rdf.uri(
internal_id=f"datatype/providerRecordID/{row['providerRecordIDSource']}",
internal_id=f"datatype/recordID/{row['providerRecordIDSource']}",
namespace=base_iri,
)
provider_record_id_agent = utils.rdf.uri(f"agent/{row['providerRecordIDSource']}", base_iri)

# Conditionally create uris dependent on ownerRecordIDSource field
if owner_record_id_source := row["ownerRecordIDSource"]:
owner_record_id_datatype = utils.rdf.uri(f"datatype/ownerRecordID/{owner_record_id_source}", base_iri)
owner_record_id_datatype = utils.rdf.uri(f"datatype/recordID/{owner_record_id_source}", base_iri)
owner_record_id_provider = utils.rdf.uri(f"provider/{row['ownerRecordIDSource']}", base_iri)
else:
owner_record_id_datatype = None
Expand All @@ -314,7 +316,7 @@ def apply_mapping_row(
# Conditionally create uris dependent on otherCatalogNumbersSource field.
if other_catalog_numbers_source := row["otherCatalogNumbersSource"]:
other_catalog_numbers_datatype = utils.rdf.uri(
internal_id=f"datatype/otherCatalogNumbers/{other_catalog_numbers_source}",
internal_id=f"datatype/catalogNumber/{other_catalog_numbers_source}",
namespace=base_iri,
)
other_catalog_numbers_provider = utils.rdf.uri(f"provider/{other_catalog_numbers_source}", base_iri)
Expand Down Expand Up @@ -346,6 +348,7 @@ def apply_mapping_row(
self.add_record_number_datatype(
uri=record_number_datatype,
provider=provider_recorded_by,
value=recorded_by,
graph=graph,
)

Expand All @@ -357,9 +360,11 @@ def apply_mapping_row(
)

# Add owner record id datatype
self.add_owner_record_id_datatype(
self.add_record_id_datatype(
uri=owner_record_id_datatype,
provider=owner_record_id_provider,
value=owner_record_id_source,
provider_role_type=DATA_ROLE_OWNER,
graph=graph,
)

Expand All @@ -386,9 +391,11 @@ def apply_mapping_row(
)

# Add provider record ID datatype
self.add_provider_record_id_datatype(
self.add_record_id_datatype(
uri=provider_record_id_datatype,
agent=provider_record_id_agent,
provider=provider_record_id_agent,
value=provider_record_id_datatype,
provider_role_type=DATA_ROLE_RESOURCE_PROVIDER,
graph=graph,
)

Expand All @@ -415,6 +422,7 @@ def apply_mapping_row(
self.add_catalog_number_datatype(
uri=catalog_number_datatype,
provider=catalog_number_provider,
value=catalog_number_source,
graph=graph,
)

Expand All @@ -426,9 +434,10 @@ def apply_mapping_row(
)

# Add other catalog numbers datatype
self.add_other_catalog_numbers_datatype(
self.add_catalog_number_datatype(
uri=other_catalog_numbers_datatype,
provider=other_catalog_numbers_provider,
value=other_catalog_numbers_source,
graph=graph,
)

Expand Down Expand Up @@ -1062,32 +1071,44 @@ def add_provider_recorded_by_agent(
# Add name
graph.add((uri, rdflib.SDO.name, rdflib.Literal(row['recordedBy'])))

def add_owner_record_id_datatype(
def add_record_id_datatype(
self,
uri: rdflib.URIRef | None,
provider: rdflib.URIRef | None,
value: str | None,
provider_role_type: rdflib.URIRef,
graph: rdflib.Graph,
) -> None:
"""Adds the owner record id datatype to the graph.
Args:
uri (rdflib.URIRef): Subject of the node.
provider (rdflib.URIRef): Provider of the datatype.
value (str | None): Raw value provided for the record id source.
provider_role_type (rdflib.URIRef): Role type of provider.
graph (rdflid.Graph): Graph to be modified.
"""
# Check to see subject provided
# Check to see subject provided.
if uri is None:
return

# Add type
graph.add((uri, a, rdflib.RDFS.Datatype))

# Add label
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal("ownerRecordID source")))
if value is not None:
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal(f"{value} recordID")))

# Add definition
graph.add((uri, rdflib.SKOS.definition, rdflib.Literal("An identifier for the record")))

# Add attribution
if provider is not None:
graph.add((uri, rdflib.PROV.wasAttributedTo, provider))
qualified_attribution = rdflib.BNode()
graph.add((qualified_attribution, a, rdflib.PROV.Attribution))
graph.add((qualified_attribution, rdflib.PROV.agent, provider))
graph.add((qualified_attribution, rdflib.PROV.hadRole, provider_role_type))
graph.add((uri, rdflib.PROV.qualifiedAttribution, qualified_attribution))

def add_owner_record_id_provider(
self,
Expand Down Expand Up @@ -1229,28 +1250,6 @@ def add_sampling_field(
# Add Basis Of Record Attribute
graph.add((uri, utils.namespaces.TERN.hasAttribute, basis))

def add_provider_record_id_datatype(
self,
uri: rdflib.URIRef,
agent: rdflib.URIRef,
graph: rdflib.Graph,
) -> None:
"""Adds the provider record id datatype to the graph.
Args:
uri (rdflib.URIRef): Subject of the node.
agent (rdflib.URIRef): Provider agent URI.
graph (rdflib.Graph): Graph to be modified.
"""
# Add the type
graph.add((uri, a, rdflib.RDFS.Datatype))

# Add label
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal("providerRecordID source")))

# Add attribution
graph.add((uri, rdflib.PROV.wasAttributedTo, agent))

def add_provider_record_id_agent(
self,
uri: rdflib.URIRef,
Expand Down Expand Up @@ -1409,13 +1408,15 @@ def add_catalog_number_datatype(
self,
uri: rdflib.URIRef | None,
provider: rdflib.URIRef | None,
value: str | None,
graph: rdflib.Graph,
) -> None:
"""Adds catalog number datatype to the graph.
Args:
uri (rdflib.URIRef | None): Subject of the node.
provider (rdflib.URIRef | None): Corresponding provider.
value (str | None): Catalog number source name obtained from raw data.
graph (rdflib.Graph): Graph to be modified.
"""
# Check subject was provided
Expand All @@ -1426,7 +1427,11 @@ def add_catalog_number_datatype(
graph.add((uri, a, rdflib.RDFS.Datatype))

# Add label
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal("catalogNumber source")))
if value is not None:
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal(f"{value} catalogNumber")))

# Add definition
graph.add((uri, rdflib.SKOS.definition, rdflib.Literal("A catalog number for the sample")))

# Add attribution
if provider is not None:
Expand Down Expand Up @@ -1455,33 +1460,6 @@ def add_catalog_number_provider(
# Add name
graph.add((uri, rdflib.SDO.name, rdflib.Literal(row["catalogNumberSource"])))

def add_other_catalog_numbers_datatype(
self,
uri: rdflib.URIRef | None,
provider: rdflib.URIRef | None,
graph: rdflib.Graph,
) -> None:
"""Adds other catalog numbers datatype to the graph.
Args:
uri (rdflib.URIRef | None): Subject of the node.
provider (rdflib.URIRef | None): Corresponding provider.
graph (rdflib.Graph): Graph to be modified.
"""
# Check subject provided
if uri is None:
return

# Add type
graph.add((uri, a, rdflib.RDFS.Datatype))

# Add label
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal("otherCatalogNumbers source")))

# Add attribution
if provider is not None:
graph.add((uri, rdflib.PROV.wasAttributedTo, provider))

def add_other_catalog_numbers_provider(
self,
uri: rdflib.URIRef | None,
Expand Down Expand Up @@ -1697,6 +1675,7 @@ def add_record_number_datatype(
self,
uri: rdflib.URIRef | None,
provider: rdflib.URIRef | None,
value: str | None,
graph: rdflib.Graph,
) -> None:
"""Adds record number datatype to the graph.
Expand All @@ -1706,6 +1685,7 @@ def add_record_number_datatype(
or None if uri wasn't created.
provider (rdflib.URIRef | None): The corresponding
provider uri.
value (str | None): Raw value provided in row.
graph (rdflib.Graph): Graph to be modified.
"""
# Check subject provided
Expand All @@ -1716,7 +1696,8 @@ def add_record_number_datatype(
graph.add((uri, a, rdflib.RDFS.Datatype))

# Add label
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal("recordNumber source")))
if value is not None:
graph.add((uri, rdflib.SKOS.prefLabel, rdflib.Literal(f"{value} recordNumber")))

# Add attribution
if provider is not None:
Expand Down
Loading

0 comments on commit e204a2a

Please sign in to comment.