How to use the quantulum3.classes.Quantity function in quantulum3

To help you get started, we’ve selected a few quantulum3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nielstron / quantulum3 / quantulum3 / tests.py View on Github external
unit = c.Unit(
                        name=item['unit'],
                        dimensions=item['dimensions'],
                        entity=entity)
                try:
                    span = next(
                        re.finditer(re.escape(item['surface']),
                                    test['req'])).span()
                except StopIteration:
                    print('Surface mismatch for "%s"' % test['req'])
                    return
                uncert = None
                if 'uncertainty' in item:
                    uncert = item['uncertainty']
                res.append(
                    c.Quantity(
                        value=item['value'],
                        unit=unit,
                        surface=item['surface'],
                        span=span,
                        uncertainty=uncert))
            test['res'] = [i for i in res]

        return tests
github nielstron / quantulum3 / quantulum3 / _lang / en_US / parser.py View on Github external
else:
            unit = load.units(lang).names["dimensionless"]

    # Discard irrelevant txt2float extractions, cardinal numbers, codes etc.
    if (
        surface.lower() in ["a", "an", "one"]
        or re.search(r"1st|2nd|3rd|[04-9]th", surface)
        or re.search(r"\d+[A-Z]+\d+", surface)
        or re.search(r"\ba second\b", surface, re.IGNORECASE)
    ):
        _LOGGER.debug('\tMeaningless quantity ("%s"), discard', surface)
        return

    objs = []
    for value in values:
        obj = cls.Quantity(
            value=value,
            unit=unit,
            surface=surface,
            span=span,
            uncertainty=uncert,
            lang=lang,
        )
        objs.append(obj)

    return objs