delph-in / pydelphin

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

TDL error: 'String' object does not support item assignment #293

Closed goodmami closed 4 years ago

goodmami commented 4 years ago

I'm getting an error parsing the pet/qc.tdl file of the ERG, and the error message isn't terribly indicative of the problem:

>>> from delphin import tdl
>>> list(tdl.iterparse('pet/qc.tdl'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  [...]
  File "/home/goodmami/delphin/pydelphin/delphin/tdl.py", line 207, in __setitem__
    super(AVM, self).__setitem__(key, val)
  File "/home/goodmami/delphin/pydelphin/delphin/tfs.py", line 58, in __setitem__
    subdef[subkeys[1]] = val
TypeError: 'String' object does not support item assignment

If there's a problem with the TDL there should be a TDLSyntaxError.

goodmami commented 4 years ago

The problem can be seen from the first few lines of an AVM in the file:

qc_unif_trad_pack := *top* &
[ ARGS.SYNSEM.LOCAL.CAT.HEAD "0" #| 5.1e+05 |#,
  ARGS.SYNSEM.LOCAL.CAT.VAL.COMPS "1" #| 2.7e+05 |#,
  ARGS.SYNSEM.PUNCT.RPUNCT "2" #| 1.5e+05 |#,
  ARGS.SYNSEM.LOCAL.CAT.HEAD.MOD "3" #| 1.2e+05 |#
[...]

The value of ARGS.SYNSEM.LOCAL.CAT.HEAD is the string "0", but in the fourth feature path it is treated as a sub-AVM in ARGS.SYNSEM.LOCAL.CAT.HEAD.MOD. These wouldn't unify, so I think this file is processed specially by PET.

I think an appropriate fix, then, is to return a more useful error message.