Boavizta / ict-sustainability-tools

0 stars 5 forks source link

How to manage constraint and represent mutilple values in the same field #12

Open demeringo opened 4 months ago

demeringo commented 4 months ago

Some fields may allow multiple values (e.g. the environmental_indicators column may need to accept several environmental indicators).

We need to understand how to represent this in the frictionless table schema. https://specs.frictionlessdata.io/table-schema/

We can already apply constraint the values of unitary fileds by using enums in the schema. But we may need to find a different way to model fields that have multiple values (i.e. collection / arrays)

💡 If this is too complex to model, edit or validate, an alternative would be to add more columns, one for each indicator and use it a a boolean (true/false) colum.

demeringo commented 4 months ago

https://github.com/frictionlessdata/datapackage/pull/38/files/3c2a9b421a967b638c27316b47f9302914b5ce97#diff-85c641a79af3c7529a7f7ab6b850399e37c504fe44516add84d7b4f5a6c39049

demeringo commented 3 months ago

The answer depends on the context !

When validating the data:

  1. The field has to be modeled as a String.
  2. We decide to use a custom separator (e.g. + or |char) between values
  3. We use a custom validation pattern (regexp) to validate the content

See https://github.com/Boavizta/ict-sustainability-tools/blob/ebf00928a128e499c69c00bb4238a2cd8b11c953/old-examples/project-list/data/project-list.resources.yaml#L39

When displaying / editing the data in the widget:

  1. We declare the field (and its allowed values) as a string with an enum constraint in the table-schema . https://github.com/Boavizta/ict-sustainability-tools/blob/ebf00928a128e499c69c00bb4238a2cd8b11c953/old-examples/project-list/model/project-list.frictionless-table-schema.json#L27
  2. We define the type of the field as tags (âš  plural form) instead of tag (singular) in the widget config (custom field properties) https://github.com/Boavizta/ict-sustainability-tools/blob/ebf00928a128e499c69c00bb4238a2cd8b11c953/old-examples/project-list/widget/project-list.fields-custom-properties.json#L19
  3. We explicit the choosen separator in the widget config (custom field properties) We define the type of the field as tags (âš  plural form) instead of tag (singular) in the widget config (custom field properties) https://github.com/Boavizta/ict-sustainability-tools/blob/ebf00928a128e499c69c00bb4238a2cd8b11c953/old-examples/project-list/widget/project-list.fields-custom-properties.json#L20
demeringo commented 3 months ago

Close this issue after this is reported to the documentation.