Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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