nielstron / quantulum3

Library for unit extraction - fork of quantulum for python3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError when parsing string with date

SabeehY opened this issue · comments

Describe the bug
When a string is parsed which contains text in the format '30/2020' or something similar followed an "and" it breaks with a KeyError.

To Reproduce
Steps to reproduce the behavior:

  1. from quantulum3 import parser
  2. parser.parse('30/2030 and')
  3. See error

Expected behavior
Should have given no results if this is not a quantity.

Screenshots

Traceback (most recent call last):
File "stnl-oms-kY71tOmQ/lib/python3.8/site-packages/quantulum3/_lang/en_US/parser.py", line 78, in extract_spellout_values
float(
ValueError: could not convert string to float: '30/2030'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/sabeehyunus/.pyenv/versions/3.8.2/lib/python3.8/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "extract_data.py", line 564, in extract_values
extracted = extract(text_list)
File "extract_data.py", line 549, in extract
value = func(line, *args)
File "extract_data.py", line 474, in match_area
area = parse_area(line)
File "extract_data.py", line 222, in parse_area
quants = parser.parse(string)
File "stnl-oms-kY71tOmQ/lib/python3.8/site-packages/quantulum3/parser.py", line 435, in parse
values = extract_spellout_values(text, lang)
File "stnl-oms-kY71tOmQ/lib/python3.8/site-packages/quantulum3/parser.py", line 37, in extract_spellout_values
return _get_parser(lang).extract_spellout_values(text)
File "stnl-oms-kY71tOmQ/lib/python3.8/site-packages/quantulum3/_lang/en_US/parser.py", line 87, in extract_spellout_values
scale, increment = reg.numberwords(lang)[word.lower()]
KeyError: '30/2030'

Additional information:

  • Python Version: 3.8.2
  • Classifier activated/ sklearn installed: no
  • OS: MacOS Mojave

Thanks for pointing this out. Even though the input is not sensible, at least no error should be thrown.

fixed by #171