scrapinghub / number-parser

Parse numbers written in natural language
BSD 3-Clause "New" or "Revised" License
108 stars 23 forks source link

[Query] number parser #62

Open StarTrooper08 opened 3 years ago

StarTrooper08 commented 3 years ago

Number parser example

number parser

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

Gallaecio commented 3 years ago

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.

StarTrooper08 commented 3 years ago

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

StarTrooper08 commented 3 years ago
from num2words import num2words 
print(num2words(4, to = 'ordinal_num'))

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

Gallaecio commented 3 years ago

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.

arnavkapoor commented 3 years ago

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