python-dwca-reader icon indicating copy to clipboard operation
python-dwca-reader copied to clipboard

Handle dynamic properties

Open nickynicolson opened this issue 1 year ago • 1 comments

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?

nickynicolson avatar Feb 06 '24 10:02 nickynicolson

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:

  • That would indeed imply that https://dwc.tdwg.org/terms/#dwc:dynamicProperties is implemented first
  • What if another structured than JSON is used (it's only a suggestion according to TDWG)? That would need more and more fragile additions to python-dwca-reader, which is not great for the long-term maintenance.

Does that help? Thanks again for reaching out!

niconoe avatar Feb 08 '24 11:02 niconoe