spencermountain / compromise

modest natural-language processing
http://compromise.cool
MIT License
11.45k stars 656 forks source link

'Sixteen one' is two numbers, not one #9

Closed jacobp100 closed 9 years ago

jacobp100 commented 10 years ago

Twenty five should register as one number, Sixteen one should not.

spencermountain commented 10 years ago

good point. will fix

bayleedev commented 9 years ago

This works with numbers divisible by 10 like: 20, 30, 320. The exceptions if the last number is ten.

I'm new to this project, can you give me some direction where this is failing at? Maybe some example code?

/cc @jacobp100 @spencermountain

spencermountain commented 9 years ago

hi blaine, welcome aboard. the method is at ./src/parents/value/to_number.js

it's more a matter of knowing when it's appropriate to sum the values together. i think right now i think it refuses to sum two numbers in the 'tens' (0-20), but welcome any alternative interpretation. tests at the bottom of the file

bayleedev commented 9 years ago

This class already works like you would expect:

to_number("sixteen one")
null
to_number("twenty five")
25
spencermountain commented 9 years ago

hey guys, just took this one for a dive, here are the tests it now passes.

the big conceptual trick is that (ones/teens) and (twenties/nineties) can only repeat if there is a multiplier in between them. eg. 'five six' is bad, but 'five hundred six' is good. it totally rules now. will push it in next release, later this week. thanks for the help.

    ["twenty two thousand five hundred",22500],
    ["two thousand five hundred and sixty",2560],
    ["a hundred and two",102],
    ["a hundred",100],
    ["seven",7],
    ["seven grand",7000],
    ["half a million",500000],
    ["half-million",500000],
    ["quarter-million",250000],
    ["a quarter million",250000],
    ["a quarter-grand",250],
    ["four and a half",6],
    ["ten and a half million",15000000],
    ["104",104],
    ["13 thousand",13000],
    ["17,983",17983],
    ["12:32",null],
    ["123-1231",null],
    ["seven eleven",null],
    ["ten-four",null],
    ["one seven", null],
    ["one ten", null],
    ["one twelve", null],
    ["one thirty", null],
    ["nine fifty", null],
    ["five six", null],
    ["nine seventy", null],
    ["nine hundred", 900],
    ["nine two hundred", null],
    ["twenty one hundred", 2100],
    ["ten one", null],
    ["twelve one", null],
    ["twenty one", 21],
    ["seventy two", 72],
    ["seventy five two", null],
    ["two hundred two", 202],
    ["two hundred three hundred", null],
    ["one thousand one", 1001],
    ["minus five hundred", -500],
    ["minus fifteen", -15],
bayleedev commented 9 years ago

@spencermountain should we return a float? ["four and a half",6],

spencermountain commented 9 years ago

v. good point

spencermountain commented 9 years ago

this is fixed in v0.2.3. thanks!