number-parser icon indicating copy to clipboard operation
number-parser copied to clipboard

[Query] number parser

Open StarTrooper08 opened this issue 4 years ago • 5 comments

Number parser example

number parser

can we make that 1 as 1st . Something like this 🤔 np2

StarTrooper08 avatar Mar 21 '21 19:03 StarTrooper08

I guess we could have a parameter that allows to determine whether ordinals are turned into ordinals or cardinals. Maybe ordinal syntax would be a better default.

I also wonder if there are languages out there without an shorthand symbol to append to cardinal numbers to mark them as ordinals. If so, it may also be useful to provide a way to format these numbers with additional flexibility, e.g. allowing to define a custom string to use as suffix, or providing a callback parameter to do custom, complex formatting of these.

Gallaecio avatar Mar 22 '21 09:03 Gallaecio

There is one easy way to do it. I mean there is one python function which can do that changes in easy way.

StarTrooper08 avatar Mar 22 '21 13:03 StarTrooper08

from num2words import num2words 
print(num2words(4, to = 'ordinal_num'))

Can we use this code to make the following changes 🤔 .

StarTrooper08 avatar Mar 22 '21 14:03 StarTrooper08

https://github.com/savoirfairelinux/num2words looks good for that use case, yes. They seem well maintained, and support multiple locales. If we need any functionality they already have, like in here, I think we should just add them as a dependency rather than reimplement the functionality ourselves.

Gallaecio avatar Mar 22 '21 15:03 Gallaecio

From my experience by working on this project last year there are a number of tools that do allow you to go from Number -> Words like the num2words library, however the other way around Words -> Number is trickier with less support.

Hence the primary challenge becomes to identify that the word 'First' (and other ordinal numbers in different languages) are actually referring to an ordinal number. You can see see more detailed discussions on this issue at #6

arnavkapoor avatar Mar 22 '21 15:03 arnavkapoor