in reply to Parsing human notations of numbers

For general numbers there is Lingua::EN::FindNumber. Here's an example from its POD:

use Lingua::EN::FindNumber; my $text = "Fourscore and seven years ago, our four fathers..."; numify($text); # "87 years ago, our 4 fathers..." @numbers = extract_numbers($text); # "Fourscore and seven", "four"

It's pretty easy to use, and surprisingly thorough, though I haven't had a chance to test if it handles fractions.


Dave

Replies are listed 'Best First'.
Re^2: Parsing human notations of numbers
by nothingmuch (Priest) on Jan 16, 2005 at 07:40 UTC
    It's actually based on Lingua::EN::Words2Nums, which is sort of what I really want. It doesn't support fractions and and decimal-point notations yet.

    I might be tempted to patch it given some spare time.

    Thanks!

    -nuffin
    zz zZ Z Z #!perl

      I just checked Lingua::EN::Numericalize, and found that it doesn't properly support fractions either. "Three fourths" parses as 12... which is actually 3*4. That seems kinda wierd, but thems the breaks.


      Dave

        I think I will try to use Lingua::EN::Words2Nums in conjunction with Math::Expr to create atoms of a string that looks like "1/4" out of "one fourth", which it seems that it can do, and evaluate that string as an expression. I might even be tempted to just eval it, but i'm not sure about that, as it is user data.

        -nuffin
        zz zZ Z Z #!perl