pynwb icon indicating copy to clipboard operation
pynwb copied to clipboard

The potato problem: pluralizing words in MultiContainerInterfaces

Open bendichter opened this issue 7 years ago • 5 comments

MultiContainerInterface attempts to pluralize the term for the objects it contains, however it does not always do this correctly. As a result, a user must use the incorrect pluralization of some words in order to get a MultiContainerInterface extension to work. See extensions tutorial and #585. I'm not sure where this behavior is defined.

English morphology is irregular and difficult, and it will be hard to get this right every time without adding unnecessary dependencies or complicated code. I propose that we stop attempting to pluralize words and just use the singular form as they are entered. Another option that could work would be to have the user explicitly enter the plural form of the word they wish to use instead of attempting to automatically pluralize the word.

bendichter avatar Aug 08 '18 14:08 bendichter

This is actually behavior of ObjectMapper. The class method is here: https://github.com/NeurodataWithoutBorders/pynwb/blob/a4fc53d80010075fc33623a8ede2fee99bf9c612/src/pynwb/form/build/map.py#L385

This change seems reasonable. My only request is existing classes that depend on this behavior do not change relevant attribute names to accommodate the change in the default behavior of ObjectMapper. Two options for addressing this after removing pluralizing from ObjectMapper.convert_dt_name

  1. Extend ObjectMapper to override convert_dt_name to pluralize, and register this new subclass as the mapper for those classes that relied on this behavior.
  2. Extend ObjectMapper (specifically, the constructor) on a per class basis, and use ObjectMapper.map_spec in the constructor to map the relevant specifications/attributes

ajtritt avatar Aug 08 '18 15:08 ajtritt

@ajtritt Could you please add comments to describe the intended transform of the name here? https://github.com/NeurodataWithoutBorders/pynwb/blob/a4fc53d80010075fc33623a8ede2fee99bf9c612/src/pynwb/form/build/map.py#L394-L395 I'm not up on my regular expressions syntax.

bendichter avatar Aug 08 '18 19:08 bendichter

@bendichter You can feed it into https://regex101.com/ as well.

t-b avatar Aug 08 '18 19:08 t-b

@t-b Thanks that's very helpful

bendichter avatar Aug 08 '18 20:08 bendichter

@bendichter that converts camel case to underscored eg TimeSeries to time_series

ajtritt avatar Aug 09 '18 05:08 ajtritt