Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The potato problem: pluralizing words in MultiContainerInterfaces #588

Open
bendichter opened this issue Aug 8, 2018 · 5 comments
Open
Labels
priority: low alternative solution already working and/or relevant to only specific user(s) topic: extension issues related to extensions or dynamic class generation
Milestone

Comments

@bendichter
Copy link
Contributor

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.

@ajtritt
Copy link
Member

ajtritt commented Aug 8, 2018

This is actually behavior of ObjectMapper. The class method is here:

def convert_dt_name(cls, **kwargs):

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

@bendichter
Copy link
Contributor Author

@ajtritt Could you please add comments to describe the intended transform of the name here?

s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()

I'm not up on my regular expressions syntax.

@t-b
Copy link
Collaborator

t-b commented Aug 8, 2018

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

@bendichter
Copy link
Contributor Author

@t-b Thanks that's very helpful

@ajtritt
Copy link
Member

ajtritt commented Aug 9, 2018

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

@ajtritt ajtritt added this to the NWB 2.0 Full milestone Aug 20, 2018
@ajtritt ajtritt added the topic: extension issues related to extensions or dynamic class generation label Sep 12, 2018
@bendichter bendichter modified the milestones: NWB 2.0 Full, NWB 2.x Dec 22, 2018
@bendichter bendichter removed their assignment Apr 6, 2019
@stephprince stephprince added the priority: low alternative solution already working and/or relevant to only specific user(s) label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low alternative solution already working and/or relevant to only specific user(s) topic: extension issues related to extensions or dynamic class generation
Projects
None yet
Development

No branches or pull requests

4 participants