21 Takes in a string and tests to see if it is a number. 23 text (str): string to test if a number 25 (bool): True if a number, else False 38 This function takes a list made by fraction & determines if a fraction. 41 split_list (list): list created by splitting on '/' 43 (bool): False if not a fraction, otherwise True 47 if len(split_list) == 2:
55 short_scale=
True, ordinals=
False):
57 Takes in a string and extracts a list of numbers. 58 Language agnostic, per language parsers need to be provided 61 text (str): the string to extract a number from 62 pronounce_handler (function): function that pronounces a number 63 extract_handler (function): function that extracts the last number 65 short_scale (bool): Use "short scale" or "long scale" for large 66 numbers -- over a million. The default is short scale, which 67 is now common in most English speaking countries. 68 See https://en.wikipedia.org/wiki/Names_of_large_numbers 69 ordinals (bool): consider ordinal numbers, e.g. third=3 instead of 1/3 71 list: list of extracted numbers as floats 75 extract = extract_handler(normalized, short_scale, ordinals)
78 numbers.append(extract)
80 num_txt = pronounce_handler(extract)
81 extract = str(extract)
82 if extract.endswith(
".0"):
83 extract = extract[:-2]
86 def replace_right(source, target, replacement, replacements=None):
87 return replacement.join(source.rsplit(target, replacements))
89 normalized = replace_right(normalized, num_txt, extract, 1)
92 to_parse = replace_right(to_parse, num_txt, extract, 1)
93 to_parse = replace_right(to_parse, extract,
" ", 1)
101 extract = extract_handler(to_parse, short_scale, ordinals)
def extract_numbers_generic(text, pronounce_handler, extract_handler, short_scale=True, ordinals=False)
def is_numeric(input_str)
def look_for_fractions(split_list)