[GLLUG] Changing words into numbers

Stewart Webb stew at messeduphare.co.uk
Tue Aug 14 10:09:46 UTC 2018


Try Python:
https://pypi.org/project/word2number/

I'm sure other popular scripting languages would have similar
tools/libs

Stew

On Tue, 2018-08-14 at 10:46 +0100, John Levin via GLLUG wrote:
> Dear list,
> 
> A problem which I think has a philosophical side as much as a
> practical one:
> What is the best way (or what are the ways) to replace numbers
> written 
> out in words with digits?
> (e.g. "the year one thousand eight hundred and seventy six" to 1776,
> or 
> "nine hundred and ninety pounds" to 999 pounds).
> 
> One obvious solution I've thought of is to automatically generate a
> list 
> of all numbers spelled out from one to n, pair them with the
> numerical 
> value, then simply loop through the list and target texts
> substituting 
> the former with the latter. But this strikes me as very blunt and
> very 
> uneconomical. And probably impracical in that the top most number may
> be 
> very high (I don't know what the highest number in the texts I have
> is, 
> though I have seen 'thirty-eight million nine hundred and ninety-
> seven').
> 
> Could there be a regex solution that generates the number from the
> words?
> 
> What other approaches could I take?
> 
> Thanks in advance,
> 
> John
> 
> -- 
> 
> John Levin
> http://www.anterotesis.com
> http://twitter.com/anterotesis
> https://hcommons.org/members/johnlevin/
> 




More information about the GLLUG mailing list