dronefly-garden / dronefly

Red Discord Bot V3 cogs for naturalists.
Other
16 stars 3 forks source link

iNat: provide formatter to name one or more of something #43

Closed synrg closed 4 years ago

synrg commented 5 years ago

Given an input like pluralize('genus', 2), output a string with plural ending applied, using the format string specified (or default as indicated), e.g. -> "2 genera" in this case.

Capitialization, if provided, should be kept intact, e.g. pluralize('Genus') -> "Genera".

See https://github.com/synrg/quaggagriff/issues/42 which will need this formatter when describing the enumeration of child ranks, e.g.

...
rank = "species"
overflow = 50
return pluralize(
    rank,
    overflow,
    " and %d more %s",
)

-> "and 50 more species"

rank = "genus"
overflow = 1

-> "and 1 more genus"

rank = "genus"
overflow = 2

-> "and 2 more genera"

synrg commented 5 years ago

See https://docs.python.org/3/library/stdtypes.html#str.format_map but also consider https://pypi.org/project/inflect/ which may be more intelligent.

synrg commented 5 years ago

Encouraging initial test results:

>>> import inflect
>>> p = inflect.engine()
>>> p.plural("genus",50)
'genera'
>>> p.plural("species",50)
'species'
>>> p.plural("Genus")
'Genera'

There are quite a number of other methods supported for various use cases that go even beyond my simple plans above for format strings. I think we can just use inflect package instead of hand-coding something of our own.

synrg commented 4 years ago

We've used inflect for this purpose for a long time.