def parse(text, verbose=False):
    """Extract all quantities from unstructured text."""
    log_format = ('%(asctime)s --- %(message)s')
    logging.basicConfig(format=log_format)
    root = logging.getLogger()

    if verbose:
        level = root.level
        root.setLevel(logging.DEBUG)
        logging.debug(u'Verbose mode')

    if isinstance(text, str):
        text = text.decode('utf-8')
        logging.debug(u'Converted string to unicode (assume utf-8 encoding)')

    orig_text = text
    logging.debug(u'Original text: "%s"', orig_text)

    text = clean_text(text)
    values = extract_spellout_values(text)
    text, shifts = substitute_values(text, values)

    quantities = []
    for item in r.REG_DIM.finditer(text):

        groups = dict([i for i in item.groupdict().items() if i[1] and
                       i[1].strip()])
        logging.debug(u'Quantity found: %s', groups)

        try:
            uncert, values = get_values(item)
        except ValueError as err:
            logging.debug(u'Could not parse quantity: %s', err)

        unit = get_unit(item, text)
        surface, span = get_surface(shifts, orig_text, item, text)
        objs = build_quantity(orig_text, text, item, values, unit, surface,
                              span, uncert)
        if objs is not None:
            quantities += objs

    if verbose:
        root.level = level

    return quantities
Extract all quantities from unstructured text.