From john at technolalia.org Tue Aug 14 09:46:23 2018 From: john at technolalia.org (John Levin) Date: Tue, 14 Aug 2018 09:46:23 -0000 Subject: [GLLUG] Changing words into numbers Message-ID: <705deea5-7ea6-63dc-ce8c-07c0574d7117@technolalia.org> 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/ From jason at ukpost.com Tue Aug 14 10:03:59 2018 From: jason at ukpost.com (Jason Clifford) Date: Tue, 14 Aug 2018 10:03:59 -0000 Subject: [GLLUG] Changing words into numbers In-Reply-To: <705deea5-7ea6-63dc-ce8c-07c0574d7117@technolalia.org> References: <705deea5-7ea6-63dc-ce8c-07c0574d7117@technolalia.org> Message-ID: <16537e44c8a.1138aab13198370.6866415373495674861@ukpost.com> I'm fairly sure there is already a Perl module that does this ---- On Tue, 14 Aug 2018 10:46:18 +0100 gllug at mailman.lug.org.uk 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/ -- GLLUG mailing list GLLUG at mailman.lug.org.uk https://mailman.lug.org.uk/mailman/listinfo/gllug -------------- next part -------------- An HTML attachment was scrubbed... URL: From stew at messeduphare.co.uk Tue Aug 14 10:09:46 2018 From: stew at messeduphare.co.uk (Stewart Webb) Date: Tue, 14 Aug 2018 10:09:46 -0000 Subject: [GLLUG] Changing words into numbers In-Reply-To: <705deea5-7ea6-63dc-ce8c-07c0574d7117@technolalia.org> References: <705deea5-7ea6-63dc-ce8c-07c0574d7117@technolalia.org> Message-ID: <5bd8b34a98a379d7de8e37cc2af825f78376db6d.camel@messeduphare.co.uk> 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/ > From john at technolalia.org Tue Aug 14 10:11:13 2018 From: john at technolalia.org (John Levin) Date: Tue, 14 Aug 2018 10:11:13 -0000 Subject: [GLLUG] Changing words into numbers In-Reply-To: <16537e44c8a.1138aab13198370.6866415373495674861@ukpost.com> References: <705deea5-7ea6-63dc-ce8c-07c0574d7117@technolalia.org> <16537e44c8a.1138aab13198370.6866415373495674861@ukpost.com> Message-ID: <634554a1-e640-d468-882f-43fc4fd5f417@technolalia.org> On 14/08/2018 11:03, Jason Clifford via GLLUG wrote: > I'm fairly sure there is already a Perl module that does this > > This? https://metacpan.org/pod/Lingua::EN::Words2Nums Thanks v much! (Seems like Perl is a very good language for text manipulation.) John > ---- On Tue, 14 Aug 2018 10:46:18 +0100 *gllug at mailman.lug.org.uk * > 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). > -- John Levin http://www.anterotesis.com http://twitter.com/anterotesis https://hcommons.org/members/johnlevin/