1

I was looking for a way to convert English numerics to integers and found a great post here: Scalable Regex for English Numerals which is using perl. My issue with using numify stems from the method "adding" numbers together rather than just outputting them. For example:

#!/usr/bin/perl
use strict;
use warnings;
use Lingua::EN::FindNumber;
print numify("some text and stuff house bill forty three twenty");

produces 63 rather than than what I expected was 43 20

I am at a loss, being a perl newbie on how to get around this. Is there an overrides that I can somehow tell the methods to not do addition? My only guess at this is that it's simply concatenating the string and its and integer so it adds them?? even knowing that still sadly doesn't help me. Thanks to anyone in the know.

2 Answers 2

1

I think your problem here has to do with an ambiguous definition of how a number should be interpreted.

If numify merely checks for words that represent numbers in a sequence and adds them, then there's no way you can overcome this. You can try to implement your own grammar, but I don't think it's completely trivial.

You'd have to catch the first word representing a number, and then check the following words, and try to find a match to your rule. For instance, after "forty", you can have a number from 1 to 9 (one, two, etc...), or "thousand", or... "millions"... I think you get the idea, In this case, you get "three", so... add them up, the next word is twenty, which doesn't match any rule above, so start over as a new number.

Sorry if this seems like I'm just thinking out loud. don't know if there's a library that can do this for you, it's an ambiguous problem, as usual when you're parsing natural language.

Hope it helps!

2
  • yes, I was hoping not to walk down that path. Though it would be a great learning experience for me, my timeline is tight and as most do, was looking for a quick fix. I did see in the post I referred to, some explanation of how to get your suggestion started. thanks for the input.
    – user978791
    Oct 4, 2011 at 16:24
  • I think whats gotten me so curious is that numify actually get's it right. It just does a strange addition to the integers. Like I said it seems to be a simple thing that should be overridable.
    – user978791
    Oct 4, 2011 at 20:04
0

I think the parser in Lingua::EN::FindNumber is kind of loose about what it considers a number, so that e.g. "three and twenty", "three twenty" or even "forty three twenty" as valid numbers. For that matter, looking at the source, it also seems to accept "baker's dozen", "eleventy-one" and "billiard" as numbers...

1
  • so, looking into the source did find the issue with numify off addition AND more importantly the very long regex string. This string will allow us to do what we need with the data. Thanks for the feedback
    – user978791
    Oct 4, 2011 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.