Skip to content

Commit

Permalink
BDRSPS-1152 Update site visit data mapping for re-usable sites
Browse files Browse the repository at this point in the history
  • Loading branch information
Lincoln-GR committed Jan 14, 2025
1 parent ba18fa9 commit 23f8a3a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
surveyID,siteID,siteIDSource,existingBDRSiteIRI,siteVisitID,siteVisitStart,siteVisitEnd,visitOrgs,visitObservers,condition,targetTaxonomicScope,protocolName,protocolDescription,samplingEffortValue,samplingEffortUnit
TIS-24-03,P1,WAM,,TIS-24-03-P1-01,2024-03-12,2024-04-04,WAM | DBCA,ORCID00001 | ORCID00002,dry,new_taxon,wet pitfall trap,10 x square buckets of size 20 x 20 x 15 cm. Propylene glycol.,240,trap nights
TIS-24-03,P1,WAM,,TIS-24-03-P1-02,2024-03-12,2024-03-12,WAM,ORCID00001,moist leaf litter after recent rain,invertebrate,litter sifting,50 cm diameter sifter with 5 mm mesh. Litter samles taken ~1 metre from each pitfall trap,10,sifts
TIS-24-03,P1,WAM,,TIS-24-03-P1-03,2024-03-12,,WAM,ORCID00003,,bird,human observation,,,
TIS-24-03,P1,WAM,https://example.com/site/P1,TIS-24-03-P1-01,2024-03-12,2024-04-04,WAM | DBCA,ORCID00001 | ORCID00002,dry,new_taxon,wet pitfall trap,10 x square buckets of size 20 x 20 x 15 cm. Propylene glycol.,240,trap nights
TIS-24-03,,,https://example.com/site/P2,TIS-24-03-P2-01,2024-03-12,2024-03-12,WAM,ORCID00001,moist leaf litter after recent rain,invertebrate,litter sifting,50 cm diameter sifter with 5 mm mesh. Litter samles taken ~1 metre from each pitfall trap,10,sifts
TIS-24-03,P3,WAM,,TIS-24-03-P3-01,2024-03-12,,WAM,ORCID00003,,bird,human observation,,,
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisitCollection/samplingEffort/10-sifts> a schema:Collection ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> ;
schema:member <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P1-02> ;
schema:member <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P2-01> ;
schema:name "Site Visit Collection - Sampling Effort - 10 sifts" ;
tern:hasAttribute <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/attribute/samplingEffort/10-sifts> .

Expand All @@ -22,13 +22,13 @@

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisitCollection/targetTaxonomicScope/bird> a schema:Collection ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> ;
schema:member <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P1-03> ;
schema:member <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P3-01> ;
schema:name "Site Visit Collection - Target Taxonomic Scope - bird" ;
tern:hasAttribute <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/attribute/targetTaxonomicScope/bird> .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisitCollection/targetTaxonomicScope/invertebrate> a schema:Collection ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> ;
schema:member <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P1-02> ;
schema:member <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P2-01> ;
schema:name "Site Visit Collection - Target Taxonomic Scope - invertebrate" ;
tern:hasAttribute <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/attribute/targetTaxonomicScope/invertebrate> .

Expand All @@ -43,17 +43,22 @@
skos:prefLabel "WAM Site ID" ;
prov:qualifiedAttribution <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/attribution/WAM/resourceProvider> .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P1-03> a tern:SiteVisit ;
<https://example.com/site/P1> a tern:Site ;
schema:identifier "P1"^^<https://linked.data.gov.au/dataset/bdr/datatypes/siteID/WAM> .

<https://example.com/site/P2> a tern:Site .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P3-01> a tern:SiteVisit ;
time:hasTime [ a time:TemporalEntity ;
time:hasBeginning [ a time:Instant ;
time:inXSDDate "2024-03-12"^^xsd:date ] ] ;
prov:hadPlan <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P1-03> ;
prov:hadPlan <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P3-01> ;
prov:wasAssociatedWith <https://linked.data.gov.au/dataset/bdr/org/WAM>,
<https://linked.data.gov.au/dataset/bdr/person/ORCID00003> ;
schema:identifier "TIS-24-03-P1-03" ;
schema:identifier "TIS-24-03-P3-01" ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000>,
<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Survey/TIS-24-03> ;
tern:hasSite <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Site/P1> .
tern:hasSite <https://linked.data.gov.au/dataset/bdr/site/WAM/P3> .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/attribute/samplingEffort/10-sifts> a tern:Attribute ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> ;
Expand Down Expand Up @@ -136,12 +141,12 @@
schema:description "10 x square buckets of size 20 x 20 x 15 cm. Propylene glycol." ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P1-02> a prov:Plan ;
<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P2-01> a prov:Plan ;
sosa:usedProcedure <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/bdr-cv/attribute/protocolName/litter-sifting> ;
schema:description "50 cm diameter sifter with 5 mm mesh. Litter samles taken ~1 metre from each pitfall trap" ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P1-03> a prov:Plan ;
<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P3-01> a prov:Plan ;
sosa:usedProcedure <http://linked.data.gov.au/def/tern-cv/ea1d6342-1901-4f88-8482-3111286ec157> ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> .

Expand All @@ -157,6 +162,8 @@
prov:Person ;
schema:name "ORCID00003" .

<https://linked.data.gov.au/dataset/bdr/site/WAM/P3> a tern:Site .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P1-01> a tern:SiteVisit ;
time:hasTime [ a time:TemporalEntity ;
time:hasBeginning [ a time:Instant ;
Expand All @@ -171,32 +178,28 @@
schema:identifier "TIS-24-03-P1-01" ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000>,
<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Survey/TIS-24-03> ;
tern:hasSite <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Site/P1> ;
tern:hasSite <https://example.com/site/P1> ;
tern:siteDescription "dry" .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P1-02> a tern:SiteVisit ;
<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/SiteVisit/TIS-24-03-P2-01> a tern:SiteVisit ;
time:hasTime [ a time:TemporalEntity ;
time:hasBeginning [ a time:Instant ;
time:inXSDDate "2024-03-12"^^xsd:date ] ;
time:hasEnd [ a time:Instant ;
time:inXSDDate "2024-03-12"^^xsd:date ] ] ;
prov:hadPlan <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P1-02> ;
prov:hadPlan <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/visit/plan/TIS-24-03-P2-01> ;
prov:wasAssociatedWith <https://linked.data.gov.au/dataset/bdr/org/WAM>,
<https://linked.data.gov.au/dataset/bdr/person/ORCID00001> ;
schema:identifier "TIS-24-03-P1-02" ;
schema:identifier "TIS-24-03-P2-01" ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000>,
<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Survey/TIS-24-03> ;
tern:hasSite <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Site/P1> ;
tern:hasSite <https://example.com/site/P2> ;
tern:siteDescription "moist leaf litter after recent rain" .

<https://linked.data.gov.au/dataset/bdr/person/ORCID00001> a prov:Agent,
prov:Person ;
schema:name "ORCID00001" .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Site/P1> a tern:Site ;
schema:identifier "P1"^^<https://linked.data.gov.au/dataset/bdr/datatypes/siteID/WAM> ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> .

<https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000/Survey/TIS-24-03> a tern:Survey ;
schema:isPartOf <https://linked.data.gov.au/dataset/bdr/00000000-0000-0000-0000-000000000000> .

Expand Down
33 changes: 18 additions & 15 deletions abis_mapping/templates/survey_site_visit_data_v3/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,9 @@ def apply_mapping_row(
# variables starting with uri_ are constructed URIs.

row_site_visit_id: str | None = row["siteVisitID"]
row_site_id: str | None = row["siteID"]
# should always have these mandatory fields, skip if not
if not row_site_visit_id:
return
if not row_site_id:
return

# Part 1: Construct URIs from Row

Expand All @@ -258,7 +255,16 @@ def apply_mapping_row(

# TERN.Site subject IRI - Note this needs to match the iri construction of the
# survey site and occurrence template mapping, ensuring they will resolve properly.
uri_site = utils.iri_patterns.legacy_site_iri(base_iri, row_site_id)
# If existingBDRSiteIRI is specified, just use that as-is for the IRI.
row_site_id: str | None = row["siteID"]
row_site_id_source: str | None = row["siteIDSource"]
row_existing_site_iri: str | None = row["existingBDRSiteIRI"]
if row_existing_site_iri:
uri_site = rdflib.URIRef(row_existing_site_iri)
elif row_site_id and row_site_id_source:
uri_site = utils.iri_patterns.site_iri(row_site_id_source, row_site_id)
else:
raise ValueError("Invalid row missing SiteID and existingBDRSiteIRI")

# Create TERN survey IRI from surveyID field
row_survey_id: str = row["surveyID"]
Expand All @@ -267,9 +273,9 @@ def apply_mapping_row(
# URI for the Site Visit Plan
uri_site_visit_plan = utils.iri_patterns.plan_iri(base_iri, "visit", row_site_visit_id)

# URIs based on the siteIDSource
row_site_id_source: str | None = row["siteIDSource"]
if row_site_id_source:
# When both existingBDRSiteIRI and siteID+siteIDSource are provided,
# the site gets a schema:identifier with this datatype.
if row_existing_site_iri and row_site_id and row_site_id_source:
uri_site_id_datatype = utils.iri_patterns.datatype_iri("siteID", row_site_id_source)
uri_site_id_datatype_attribution = utils.iri_patterns.attribution_iri(
base_iri, "resourceProvider", row_site_id_source
Expand Down Expand Up @@ -372,7 +378,6 @@ def apply_mapping_row(
self.add_site(
uri=uri_site,
uri_site_id_datatype=uri_site_id_datatype,
dataset=dataset,
row=row,
graph=graph,
)
Expand Down Expand Up @@ -560,7 +565,6 @@ def add_site(
*,
uri: rdflib.URIRef,
uri_site_id_datatype: rdflib.URIRef | None,
dataset: rdflib.URIRef,
row: frictionless.Row,
graph: rdflib.Graph,
) -> None:
Expand All @@ -576,12 +580,11 @@ def add_site(
# Add class
graph.add((uri, a, utils.namespaces.TERN.Site))

# Add siteID literal
dt = uri_site_id_datatype or rdflib.XSD.string
graph.add((uri, rdflib.SDO.identifier, rdflib.Literal(row["siteID"], datatype=dt)))

# Add to dataset
graph.add((uri, rdflib.SDO.isPartOf, dataset))
# Add siteID schema:identifier property, only when both existingBDRSiteIRI
# and siteID+siteIDSource are provided.
row_site_id: str | None = row["siteID"]
if row_site_id and uri_site_id_datatype is not None:
graph.add((uri, rdflib.SDO.identifier, rdflib.Literal(row_site_id, datatype=uri_site_id_datatype)))

def add_site_id_datatype(
self,
Expand Down

0 comments on commit 23f8a3a

Please sign in to comment.