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

Add Pluralize function for strings #3992

Merged
merged 2 commits into from
Jun 11, 2020

Conversation

wilfwilson
Copy link
Member

I've done some work towards making objects correctly pluralise the word 'generator' in GAP, especially in ViewString methods.

In English, you say that you have 0 generators, 1 generator, or n generators, in the case that n > 1. Most (all?) of the methods for ViewString or ViewObj in the library do not special case 1 generator, and instead write 1 generators.

So we get, for example:

<magma with 1 generators>

rather than

<magma with 1 generator>

The wrongness grates on me, and makes GAP seem that little bit less professional. Therefore, I've gone some way to addressing this. However, I have not spent the time to finish and polish this work, because:

  1. Is there a good reason that I've missed for GAP to be this way?

  2. Will changing all of these methods break the tests of so many packages that it's not worth doing?

  3. My 'fixes' are ugly and repetitive. Really, I want a function that I can use from anyway in GAP, to return the string "generator" if the number of generators is 1, or "generators" otherwise. Any suggestions? How general should this be? That way I could adjust the string construction code to be something like:

"<group with ", nrgens, FUNC(" generator", "s", nrgens <> 1), ">";

where FUNC would print the concatenation of the first two arguments if the third is true, and only prints the first argument otherwise.

@wilfwilson wilfwilson added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) topic: library kind: discussion discussions, questions, requests for comments, and so on release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes priority: low labels Apr 28, 2020
@wilfwilson
Copy link
Member Author

wilfwilson commented Apr 28, 2020

Or maybe it should be

"<group with ", nrgens, " generator", ReturnIf(nrgens <> 1, "s"), ">";

where ReturnIf returns its second argument if the first argument is true, and returns nothing otherwise?

@ChrisJefferson
Copy link
Contributor

ChrisJefferson commented Apr 28, 2020

I think a function would be better. Looking at the examples, perhaps do:

Pluralize(count, str), which returns the plural version of str if count <> 1. Pluralize, should take an optional 3rd argument which is the plural form of str, but most of the time we will just auto-pluralise, based on a simple set of rules (which we can decide).

One advantage for this is we could for now add some option to disable pluralizing, which could be a "quick hack" to not break package testing.

@olexandr-konovalov
Copy link
Member

Agree with @ChrisJefferson. The new function could go under 27.9 Operations to Evaluate Strings.

@ChrisJefferson
Copy link
Contributor

Just as an extension, I do agree with the plan to fix the pluralisation, and agree it looks bad.

@olexandr-konovalov
Copy link
Member

That will be fun to implement properly :) https://en.wikipedia.org/wiki/English_plurals

@fingolfin
Copy link
Member

Auto pluralization heuristics can easily cover 99% of the cases, and e.g. Ruby on Rails relies on it heavily (or at least used to when I last used it). Some references:

I think the main reason this isn't done in all parts of GAP is that it's extra work; and while I also find it grating to read, I also understand that sometimes, finishing your actual work is more important than scratching these itches ;-).

@wilfwilson
Copy link
Member Author

Thanks for the input. I'll give look into adding a Pluralize function, and integrating it where possible.

I also understand that sometimes, finishing your actual work is more important than scratching these itches ;-)

Hence my "priority: low" tag ;-) But while I'm unemployed, I've decided I'll take some liberties!

@fingolfin
Copy link
Member

Oh, sure, I didn't mean to shoot this project down, to the contrary, I am happy somebody works on it :-)

@coveralls
Copy link

coveralls commented Apr 28, 2020

Coverage Status

Coverage increased (+0.003%) to 84.892% when pulling 839bf24 on wilfwilson:1-generators into 33bb643 on gap-system:master.

@wilfwilson wilfwilson changed the title Do not pluralise "1 generator", especially in ViewObj/ViewString Introduce Pluralize, and use in many ViewStrings Apr 29, 2020
@wilfwilson wilfwilson force-pushed the 1-generators branch 2 times, most recently from ce3c6a0 to d78e528 Compare April 30, 2020 09:10
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice! I'd approve, except for that TODO in the documentation ;-)

lib/string.gi Outdated Show resolved Hide resolved
lib/string.gd Outdated Show resolved Hide resolved
lib/string.gi Outdated Show resolved Hide resolved
lib/string.gi Outdated Show resolved Hide resolved
lib/string.gi Outdated Show resolved Hide resolved
lib/string.gi Outdated Show resolved Hide resolved
lib/string.gi Outdated Show resolved Hide resolved
lib/string.gd Outdated Show resolved Hide resolved
lib/string.gi Outdated Show resolved Hide resolved
@wilfwilson wilfwilson marked this pull request as ready for review April 30, 2020 19:29
@wilfwilson wilfwilson removed the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Apr 30, 2020
@wilfwilson
Copy link
Member Author

Hopefully this is now complete.

lib/addmagma.gi Outdated Show resolved Hide resolved
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I made a minor suggestion but that could be done in a future PR.

Just in case you are interested in taking this a little bit further: I found a few more things that could be adjusted to use Pluralize; I grepped for '" points' , '" vectors', '" elements', '" pts'

@wilfwilson
Copy link
Member Author

I will make the changes that you suggest.

@wilfwilson wilfwilson changed the title Introduce Pluralize, and use in many ViewStrings Introduce a Pluralize function for strings Jun 11, 2020
@wilfwilson wilfwilson removed the do not merge PRs which are not yet ready to be merged (e.g. submitted for discussion, or test results) label Jun 11, 2020
@wilfwilson
Copy link
Member Author

I've done so @fingolfin.

@fingolfin fingolfin merged commit 2c58a4b into gap-system:master Jun 11, 2020
@wilfwilson wilfwilson deleted the 1-generators branch June 11, 2020 22:16
@ThomasBreuer ThomasBreuer added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Feb 17, 2021
@fingolfin fingolfin changed the title Introduce a Pluralize function for strings Add Pluralize function for strings Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: discussion discussions, questions, requests for comments, and so on kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements kind: new feature priority: low release notes: added PRs introducing changes that have since been mentioned in the release notes topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants