BelgianBiodiversityPlatform / python-dwca-reader

🐍 A Python package to read Darwin Core Archive (DwC-A) files.
BSD 3-Clause "New" or "Revised" License
45 stars 21 forks source link

Handle dynamic properties #105

Open nickynicolson opened 7 months ago

nickynicolson commented 7 months ago

The DWCA standard supports "dynamic properties" which enable the mobilisation of "additional measurements, facts, characteristics, or assertions about the record": https://dwc.tdwg.org/terms/#dwc:dynamicProperties This feature request is perhaps connected to issue #76 (assigning of column types) but could these properties (which are recommended to be supplied in key value format) be handled by dwca reader?

niconoe commented 7 months ago

Thanks for the question/remark, @nickynicolson!

I haven't tested, but we should already be able to access the content of this field like any other one, with something like:

dynamic_properties = row.data["http://rs.tdwg.org/dwc/terms/dynamicProperties"]

The dynamic_properties will then contains the data as a simple Python string, that would need further processing by your code.

Full example, if the data contains JSON, as suggested by TDWG:

dynamic_properties_str = row.data["http://rs.tdwg.org/dwc/terms/dynamicProperties"]
dynamic_properties = json.loads(dynamic_properties_str)

In theory, python-dwca-reader could help its users by doing the json.loads() behind the scenes, but I am nor really in favor, because:

Does that help? Thanks again for reaching out!