UniversalDependencies / tools

Various utilities for processing the data.
GNU General Public License v2.0
203 stars 43 forks source link

remove recursion from get_projection (avoiding Python recursion depth limit exception) #84

Closed matyaskopp closed 2 years ago

matyaskopp commented 2 years ago

I am suggesting not using recursion in get_projection in validation script. The recursive call cause this exception for deep trees:

[Line 8029 Sent ParlaMint-DK_20141008130437.seg2.7]: [L0 Format some-test] Exception caught!
Traceback (most recent call last):
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 2293, in <module>
    validate(inp,out,args,tagsets,known_sent_ids)
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 1902, in validate
    tree = build_tree(sentence) # level 2 test: tree is single-rooted, connected, cycle-free
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 1117, in build_tree
    get_projection(0, tree, projection)
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 1135, in get_projection
    get_projection(child, tree, projection)
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 1135, in get_projection
    get_projection(child, tree, projection)
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 1135, in get_projection
    get_projection(child, tree, projection)
  [Previous line repeated 993 more times]
  File "/home/runner/work/ParlaMint/ParlaMint/ParlaMint/Scripts/tools/validate.py", line 1134, in get_projection
    projection.add(child)
RecursionError: maximum recursion depth exceeded while calling a Python object
Format errors: 1
*** FAILED *** with 1 errors

I am aware that there is something odd in the sentence if it has a depth of almost 1000 nodes but it shouldn't cause script failure.