コード例 #1
0
def test_ambiguous_cases():
    # Quarter ( Coin ) is Untested
    # Second ( Time / Verb ) is Untested
    assert 'the 4th' == numerize('the fourth')
    assert '1/3 of' == numerize('a third of')
    assert '4th' == numerize('fourth')
    assert '2nd' == numerize('second')
    # pronouns not supported yet
    # some ambiguous cases here are untested
    # assert 'I quarter' == numerize('I quarter')
    # assert 'You quarter' == numerize('You quarter')
    # assert 'I want to quarter' == numerize('I want to quarter')
    # assert 'the 1st 1/4' == numerize('the first quarter')
    assert '1/4 pound of beef' == numerize('quarter pound of beef')
コード例 #2
0
def test_fractions_in_words():
    assert "1/2" == numerize("one half")

    assert "1/4" == numerize("1 quarter")
    assert "1/4" == numerize("one quarter")
    assert "1/4" == numerize("a quarter")
    assert "1/8" == numerize("one eighth")

    assert "3/4" == numerize("three quarters")
    assert "2/4" == numerize("two fourths")
    assert "3/8" == numerize("three eighths")
    assert "7/10" == numerize("seven tenths")
コード例 #3
0
def test_ordinal_strings():
    ords = {
        'first': '1st',
        'second': '2nd',
        'third': '3rd',
        'fourth': '4th',
        'fifth': '5th',
        'seventh': '7th',
        'eighth': '8th',
        'tenth': '10th',
        'eleventh': '11th',
        'twelfth': '12th',
        'thirteenth': '13th',
        'sixteenth': '16th',
        'twentieth': '20th',
        'twenty-third': '23rd',
        'thirtieth': '30th',
        'thirty-first': '31st',
        'fourtieth': '40th',
        'fourty ninth': '49th',
        'fiftieth': '50th',
        'sixtieth': '60th',
        'seventieth': '70th',
        'eightieth': '80th',
        'ninetieth': '90th',
        'hundredth': '100th',
        'thousandth': '1000th',
        'millionth': '1000000th',
        'billionth': '1000000000th',
        'trillionth': '1000000000000th',
        'first day month two': '1st day month 2'}
    for k, v in ords.items():
        assert v == numerize(k)
コード例 #4
0
def test_straight_parsing():
    strings = {
        1: 'one',
        5: 'five',
        10: 'ten',
        11: 'eleven',
        12: 'twelve',
        13: 'thirteen',
        14: 'fourteen',
        15: 'fifteen',
        16: 'sixteen',
        17: 'seventeen',
        18: 'eighteen',
        19: 'nineteen',
        20: 'twenty',
        27: 'twenty seven',
        31: 'thirty-one',
        37: 'thirty-seven',
        41: 'forty one',
        42: 'fourty two',
        59: 'fifty nine',
        100: ['one hundred', 'a hundred'],
        150: ['one hundred and fifty', 'one fifty'],
        200: 'two-hundred',
        500: '5 hundred',
        999: 'nine hundred and ninety nine',
        1_000: 'one thousand',
        1_200: ['twelve hundred', 'one thousand two hundred'],
        17_000: 'seventeen thousand',
        21_473: 'twentyone-thousand-four-hundred-and-seventy-three',
        74_002: 'seventy four thousand and two',
        99_999: 'ninety nine thousand nine hundred ninety nine',
        100_000: '100 thousand',
        250_000: 'two hundred fifty thousand',
        1_000_000: 'one million',
        1_250_007: 'one million two hundred fifty thousand and seven',
        1_000_000_000: 'one billion',
        1_000_000_001: 'one billion and one'
    }
    for k, v in strings.items():
        if isinstance(v, list):
            for s in v:
                assert numerize(s) == str(k)
        else:
            assert numerize(v) == str(k)
コード例 #5
0
def test_bias_ordinal():
    assert '4th' == numerize('fourth', bias='ordinal')
    assert '12th' == numerize('twelfth', bias='ordinal')
    assert '2nd' == numerize('second', bias='ordinal')
    assert 'the 4th' == numerize('the fourth', bias='ordinal')
    assert '2.75' == numerize('two and three fourths', bias='ordinal')
    assert '3/5' == numerize('three fifths', bias='ordinal')
    assert 'a 4th of' == numerize('a fourth of', bias='ordinal')
コード例 #6
0
def get_restaurant(text):
    s = numerize(text)
    choice = int(re.search("\d+", s).group(0))

    if choice <= len(slot.result.index):
        slot.restaurant = [slot.result.name.iloc[choice - 1]]
        intent.update_intent('reservation')
        setattr(slot, 'restaurant_choice', 1)
        return "You have selected {}! Would you like to make a reservation?".format(
            slot.restaurant)
    else:
        return "Sorry that's not a valid restaurant number, please select 1, 2 or 3"
コード例 #7
0
def test_bias_fractional():
    assert '1/4' == numerize('fourth', bias='fractional')
    assert '1/12' == numerize('twelfth', bias='fractional')
    assert '2nd' == numerize('second', bias='fractional')
    # assert 'the 1/4' == numerize('the fourth', bias='fractional')
    assert '2.75' == numerize('two and three fourths', bias='fractional')
    assert '3/5' == numerize('three fifths', bias='fractional')
    assert '1/4 of' == numerize('a fourth of', bias='fractional')
コード例 #8
0
def test_hyenated():
    assert numerize('forty-two') == '42'
コード例 #9
0
def test_init():
    assert numerize('forty two') == '42'
コード例 #10
0
def test_ignore():
    assert 'the second day of march' == numerize('the second day of march',
                                                 ignore=['second'])
    assert 'quarter' == numerize('quarter', ignore=['quarter'])
    assert 'the five guys' == numerize('the five guys', ignore=['five'])
    assert 'the fifty 2' == numerize('the fifty two', ignore=['fifty'])
コード例 #11
0
# distance and time calculator program
from numerizer import numerize

print('\nTime calculater constant(300000 km/s)')
try:
    from_ = input('\nfrom where:')
    to = input('To:')
    numerized_distance = numerize(input('Enter distance in km:'))
    dist = int(numerized_distance)

    # storing operations in variables

    time_taken = dist / 300000
    in_min = time_taken / 60
    in_hr = in_min / 60
    in_day = in_hr / 24
    in_year = in_day / 365

    if in_min >= 60:
        print('\nTo reach:' + str(in_hr) + ' ' +
              'hours at lightspeed to reach from ' + ' ' + from_ + "" + 'to' +
              " " + to)
    if in_hr >= 24:
        print('\nTo reach:' + str(in_day) + ' ' +
              'days at lightspeed to reach from' + ' ' + from_ + "" + 'to' +
              " " + to)
    if in_day >= 365:
        print('\n To reach:' + str(in_year) + ' ' +
              'light years to reach from' + ' ' + from_ + " " + 'to' + " " +
              to)
    else:
コード例 #12
0
from numerizer import numerize

print(numerize('two'))
print(numerize('one'))
print(numerize('five'))
print(numerize('five thousand two hundred and twenty'))
コード例 #13
0
def test_fractional_addition():
    assert "1.25" == numerize("one and a quarter")
    assert "2.375" == numerize("two and three eighths")
    assert "2.5" == numerize("two and a half")
    assert "3.5 hours" == numerize("three and a half hours")
コード例 #14
0
def test_hundreds():
    assert numerize('four hundred and forty two') == '442'
コード例 #15
0
def test_compatability():
    assert '1/2' == numerize('1/2')
    assert '05/06' == numerize('05/06')
    assert "3.5 hours" == numerize("three and a half hours")
    assert "1/2 an hour" == numerize("half an hour")
コード例 #16
0
def test_multiple_slashes_should_not_be_evaluated():
    assert '11/02/2007' == numerize('11/02/2007')
コード例 #17
0
def test_edges():
    assert "27 Oct 2006 7:30am" == numerize("27 Oct 2006 7:30am")
コード例 #18
0
ファイル: vc2.0.py プロジェクト: rudrabisht/python-fun
def voice():

    with sr.Microphone() as source:

        def animation():

            anime = 0

            while text:

                label1.config(text='Listening' + '.' * anime)

                time.sleep(0.5)

                anime += 1

                if anime == 4:
                    anime = 0

        r = sr.Recognizer()

        text = True

        ani = Thread(target=animation, daemon=True)

        ani.start()

        audio = r.listen(source)

        text0 = r.recognize_google(audio)

        text = False

        label1.config(text=text0)

        val = []

        text1 = text0.split()

        if 'hundred' in text1 or 'million' in text1 or 'billion' in text1:

            for i in range(len(text1)):

                try:
                    if not text1[i].isdigit():

                        text1[i] = numerize(text1[i]).replace(',', '')

                except:
                    pass

        try:

            if 'add' in text0:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text='Result: ' + str(sum(val)))

            if 'multiply' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=multiply(*val))

            if 'divide' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=divide(val[0], val[1]))

            if 'subtract' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=subtract(val[0], val[1]))

            if 'root' in text1:

                if numerize('million') in text1 or numerize(
                        'billion') in text1:

                    for x in range(len(text1)):

                        if text1[x].isdigit():
                            text1[x] = text1[x + 1].replace(
                                text1[x + 1][0], text1[x])

                            text1.pop()

                            break

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=square_root(val[0]))

            if 'log' in text1:

                for i in text1:

                    if numerize('million') in text1 or numerize(
                            'billion') in text1:

                        text1[1] = text1[2].replace(text1[2][0], text1[1])
                        text1.pop(2)

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                try:

                    label2.config(text=log(val[0], val[1]))

                except:

                    label2.config(text=log(val[0]))

            if 'sin' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=sin(val[0]))

            if 'cos' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=cos(val[0]))

            if 'tan' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=tan(val[0]))

            if 'cosec' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=cosec(val[0]))

            if 'sec' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=sec(val[0]))

            if 'cot' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=cot(val[0]))

            if 'raised' in text1 or 'power' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=power(val[0], val[1]))

            if 'factorial' in text1:

                for i in text1:

                    if i.replace('.', '').isdigit():

                        if '.' in i:

                            val.append(float(i))

                        else:

                            val.append(int(i))

                label2.config(text=factorial(val[0]))

        except:

            messagebox.showerror('Invalid',
                                 'Provide Valid Statement And Value')
コード例 #19
0
def test_combined_double_digits():
    assert "21" == numerize("twentyone")
    assert "37" == numerize("thirtyseven")
コード例 #20
0
def test_case_insensitive():
    assert numerize('Forty two') == '42'
    assert numerize('FORTY TWO') == '42'
    assert numerize('FORTY Second') == '42nd'
    assert numerize('Ninety Nine') == '99'
コード例 #21
0
    def replace_number(text):
        """Replace number words to digit number.
        """

        return numerize(text)
コード例 #22
0
def test_word_with_a_number():
    assert "pennyweight" == numerize("pennyweight")
コード例 #23
0
def test_fraction():
    assert numerize('half') == '1/2'
    assert numerize('quarter') == '1/4'
    assert numerize('two and a half') == '2.5'
    assert numerize('three quarters') == '3/4'
    assert numerize('two and three eighths') == '2.375'