delph-in / pydelphin

Python libraries for DELPH-IN
https://pydelphin.readthedocs.io/
MIT License
77 stars 27 forks source link

Attempting to generate from an MRS object needs a better error message #350

Closed goodmami closed 1 year ago

goodmami commented 1 year ago

ACEGenerator expects a string MRS to generate from. When working with PyDelphin's MRS objects, it may be tempting to try and generate from the MRS object without first serializing to a string. The error message for this, however, is not intuitive:

>>> from delphin import ace
>>> parser = ace.ACEParser('../erg-2018.dat')
>>> generator = ace.ACEGenerator('../erg-2018.dat', cmdargs=['-r', 'root_frag'])
>>> response = parser.interact('the phone')
>>> gresponse = generator.interact(response.result(0).mrs())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/goodmami/delphin/pydelphin/delphin/ace.py", line 255, in interact
    validated = self._validate_input(datum)
  File "/home/goodmami/delphin/pydelphin/delphin/ace.py", line 387, in _validate_input
    return _possible_mrs(datum)
  File "/home/goodmami/delphin/pydelphin/delphin/ace.py", line 624, in _possible_mrs
    for i, c in enumerate(s):
  File "/home/goodmami/delphin/pydelphin/delphin/sembase.py", line 164, in __getitem__
    return self._pidx[id]
KeyError: 0

The interact() method should perhaps through an error if the argument is not a string.

See this discourse thread.

KelsonXie commented 1 year ago

Hey, I would like to attempt to fix this issue, any recommendations on what the error message should be?

goodmami commented 1 year ago

This was closed by #351