Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys, I checked Lingua::Numbers2words module but the problem is that although i know how to use it but i dont know how to write a programme to get a text as input n changes all numbers in the text into the words as output to another file. any help n ideas?

Replies are listed 'Best First'.
Re: change numbers in a corpus into words
by kyle (Abbot) on Feb 05, 2008 at 21:42 UTC

    Off the top of my head:

    perl -MLingua::EN::Numbers -pe 's/(\d\S+)/Lingua::EN::Numbers::num2en( +$1) || $1/ge' < input_file > output_file

    This will attempt to change anything that starts with a digit. You might want a more specific pattern. Also, it uses Lingua::EN::Numbers instead of the one you listed (Lingua::Numbers2words, which I didn't find). I haven't tested this.

      tx friend, it dosnt change all numbers t words, what i get is some numbers to words and sum not.... any idea? for example for 3 : 30 it returns 3 : thirty.

        Oh, that's my pattern doing that (it requires a non-space character after the digit). Try this instead (single digits match):

        perl -MLingua::EN::Numbers -pe 's/(\d\S*)/Lingua::EN::Numbers::num2en( +$1) || $1/ge' < input_file > output_file
Re: change numbers in a corpus into words
by GrandFather (Saint) on Feb 05, 2008 at 21:45 UTC

    Maybe you could show us a small sample of the data you need to manipulate and at least write a framework for the processing you need to do? This task sounds trivial enough to be a homework exercise so we would like to see you make at least some effort and ask us how to solve a specific issue rather than write the whole application for you based on a fairly fluffy specification.


    Perl is environmentally friendly - it saves trees
      dear friend, maybe i was not clear to give some explanations, anyway the task i need to do is regarding speech recongnition n language modelling. maybe is easy task but i tried n i faild. i have a corpus n i need to change all numbers there to words. im aged enough not to need to do excercies;) the first solution also ive tried before but it dosnt change all my numbers to words but some which i donno why... any idea?

        Unless you show us what you have tried how can we know how it has failed? Better still, show us what you tried, what it generated and what you expected.

        Any pertinent information that you omit we have to guess at. If we guess wrong it wastes your time and our time. If we can't be bothered guessing you don't get answers.


        Perl is environmentally friendly - it saves trees