Esempio n. 1
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    try:
        req_body = req.get_json()
    except ValueError:
        pass

    operation = req_body.get('operation')
    language = req_body.get('language')
    number = req_body.get('number')
    currency_code = req_body.get('currency_code')

    if operation and language and number:
        if operation == "currency" and currency_code:
            try:
                output = n2w(number, lang=language, to=operation, currency=currency_code)
            except ValueError:
                pass
        else:
            output = n2w(number, lang=language, to=operation)

        return func.HttpResponse(
            json.dumps({
                'status': 'success',
                'content': output
            }),
            mimetype="application/json",
            status_code=200
            )
    else:
        return func.HttpResponse(
             "Error",
             status_code=400
        )
Esempio n. 2
0
def queryPreprocess(q):
    q = q.translate(None, string.punctuation)
    q = q.lower().split()
    #    q = [spell(w) for w in q if not w.isdigit() else w]       #spelling correction

    temp = []
    for w in q:
        if w.isdigit():
            temp.extend(n2w(int(w)).lower().split())
            temp.append(w)
        else:
            try:
                temp.append(str(w2n.word_to_num(w)))

            except:
                pass
            w = spell(w)
            temp.append(w)

#    q.extend(temp)
    q = temp

    q = [w.lower() for w in q if w.lower() not in stop_words]
    wnl = nltk.WordNetLemmatizer()
    q = [wnl.lemmatize(t) for t in q]
    #    print "bye"
    return q
Esempio n. 3
0
def _repeat_interpreter(repeats):
    """ Text for damage """
    # get damage repeater text
    if repeats == 1:
        repeat_text = ''
    elif repeats == 2:
        repeat_text = ' twice' 
    elif repeats > 2:
        repeat_text = ' {} times'.format(n2w(repeats))
    return repeat_text
Esempio n. 4
0
    def post(self):
        data = self.reqparse.parse_args()

        if data['type'] == "":
            data['type'] = 'cardinal'

        if data['language'] == "":
            return {
                'language': 'No language selected!',
                'message': 'Nothing converted!',
                'status': 'ERROR'
                }
        if data['number'] == "":
            return {
                'language': data['language'],
                'message': 'No number!',
                'status': 'ERROR'
                }
        if data['type'] == 'currency' and data['language'] == 'pl':
            converted = n2w(data['number'], lang=data['language'], to=data['type'], currency='PLN')
            return {
                'language': data['language'],
                'message': converted,
                'status': 'OK'
            }
        elif data:
            converted = n2w(data['number'], lang=data['language'], to=data['type'])
            return {
                'language': data['language'],
                'message': converted,
                'status': 'OK'
            }
        else:
            return {
                'language': 'Something when wrong!',
                'message': 'Something when wrong!',
                'status': 'ERROR'
            }
Esempio n. 5
0
def numbers_to_words(word: str) -> str:
    """
	Change numbers into words, e.g. 10 -> "ten". 4-digit numbers will be treated
	as years, e.g. 1918 -> "nineteen eighteen".
	Also handles ordinals, e.g. "3rd" -> "third".

	Parameters:
	  word (str): The number, as a string, to convert to words.

	Returns:
	  Words for the number, e.g. numbers_to_words("10") returns "ten".
	  On any error, return "A".
	"""
    ordinal_number_endings = ("nd", "rd", "st", "th")

    # If the number is 4 digits, treat it as a word. Catch any exceptions.
    if word.isdigit():
        if len(word) == 4:
            try:
                word = n2w(word, to="year")
            except Exception:
                return "A"
        # It's not 4 digits, so just a normal word.
        else:
            try:
                word = n2w(word)
            except Exception:
                return "A"

    # Check if the last 2 characters are ordinals and handle that.
    if word[:-2].isdigit() and word[-2:] in ordinal_number_endings:
        word = word[-2:]
        try:
            word = n2w(word, to="ordinal")
        except Exception:
            return "A"

    return word
Esempio n. 6
0
def _backoff_log(details):
    details["tries_ordinal"] = n2w(details["tries"], ordinal=True)
    exc_typ, exc, _ = sys.exc_info()

    if isinstance(details.get("value", None), requests.Response):
        details["value"] = ppf.http_response(details["value"], inline=True)
    elif exc is not None:
        exc_fmt = traceback.format_exception_only(exc_typ, exc)[-1]
        details["value"] = exc_fmt.rstrip("\n")

    lg.debug(
        "Re-trying <<{value}>> waiting for {wait:0.1f}s before trying `{tries_ordinal}` "
        "time.".format(**details)
    )
Esempio n. 7
0
def numbersToWords(word):
    ordinal_number_endings = ("nd", "rd", "st", "th")
    if word.isdigit():
        if len(word) == 4:
            try:
                word = n2w(word, to="year")
            except Exception:
                # Hacky way of discarding candidate title
                return "1111111111"
        else:
            try:
                word = n2w(word)
            except Exception:
                # Hacky way of discarding candidate title
                return "1111111111"
    if word[:-2].isdigit() and word[-2:] in ordinal_number_endings:
        word = word[-2:]
        try:
            word = n2w(word, to="ordinal")
        except Exception:
            # Hacky way of discarding candidate title
            return "1111111111"

    return word
Esempio n. 8
0
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 10 20:28:51 2020

@author: Admin
"""

from num2words import num2words as n2w

i = 0
for _ in range(1, 1001):
    i += len(n2w(_).replace('-', '').replace(' ', ''))
print(i)
Esempio n. 9
0
        bl.append(procout(shell(cmd, shell=True, text=True).replace("\n", "")))
    if " --user" in t:
        t = t.replace(" --user", "")
        if showtokens:
            cmd = f"python3 /app/user.py {t}"
        else:
            cmd = f"python3 /app/user.py {t} h"
        ul.append(procout(shell(cmd, shell=True, text=True).replace("\n", "")))
print("processing data...")
d = {}
count = 0
if len(bl) > 0:
    bd = {}
    for i in bl:
        count = count + 1
        bd.update({n2w(count): i})
    d.update({"bots": bd})
count = 0
if len(ul) > 0:
    ud = {}
    for i in ul:
        count = count + 1
        ud.update({n2w(count): i})
    d.update({"users": ud})
with open("/app/output/output.toml", "w+") as f:
    tr = toml.dumps(d)
    toml.dump(d, f)
with open("/app/output/output.yml", "w+") as f:
    yr = yaml.dump(d)
    yaml.dump(d, f)
with open("/app/output/output.json", "w+") as f:
Esempio n. 10
0
def num2words(n):
    if n < 10:
        return n2w(n, lang='en').title()
    return str(n)
Esempio n. 11
0
def num2words(n):
    if n < 10:
        return n2w(n).title()
    return str(n)
Esempio n. 12
0
def numberLetterCount():
    return len(''.join([''.join(sym for sym in n2w(dig) if sym.isalnum()) for dig in range(1,1001)]))
Esempio n. 13
0
from num2words import num2words as n2w

print("*** Sing Along ***")

print("\n".join([
    """%s green bottles hanging on the wall,
%s green bottles hanging on the wall,
And if one green bottle should accidentally fall,
There'll be %s green bottles hanging on the wall.""" %
    (n2w(i + 1).title(), n2w(i + 1).title(), n2w(i))
    for i in range(int(input("Range: ")))[::-1]
]))  # Technically 1 line
Esempio n. 14
0
def num2words(n):
    if n < 10:
        return n2w(n).title()
    return str(n)