akshaynagpal / w2n

Convert number words (eg. twenty one) to numeric digits (21)
http://w2n.readthedocs.io
MIT License
167 stars 78 forks source link

Return index (indices) of the index of the words of numbers #50

Open rphota opened 4 years ago

rphota commented 4 years ago

I want to start by saying that this is really a helpful library. Now, this library helps to convert words for numbers to numeric and it's great. However, thinking of an instance where I want to convert all the words for numbers in a string (e.g. in a proper sentence - These are the four items I like the most) and still have the string as a result (These are the 4 items I like the most), if this library also returns the index (indices) of the words in the original string or just return the original sentence after replacing the words for numbers with the numbers will help. Thanks. Please suggest.

weightwatchers-carlanderson commented 3 years ago

Thanks for the library. I agree with above. If I do

>>> from word2number import w2n
>>> w2n.word_to_num("1 tsp five-spice powder")
5

it would be useful to know that the number was only a subset of the string. Providing a mechanism to know the indexes of the match would provide that