RecursionError: maximum recursion depth exceeded while calling a Python object
sekewei opened this issue · 1 comments
sekewei commented
What could cause the following recursion limit error when executing opencc? Thank you.
/usr/local/anaconda3/bin/python -m opencc -c s2t -i testset/zhidao.test.json -o zhidao.test_tw.jsonn
Traceback (most recent call last):
File "/usr/local/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/__main__.py", line 41, in <module>
sys.exit(main())
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/__main__.py", line 32, in main
output_str = cc.convert(input_str)
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 72, in convert
result.append(self._convert(split_string_list[i], self._dict_chain_data))
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 102, in _convert
tree = StringTree(self._convert("".join(tree.inorder()), c_dict, True))
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 94, in _convert
tree.convert_tree(c_dict)
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 221, in convert_tree
self.right.convert_tree(test_dict)
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 221, in convert_tree
self.right.convert_tree(test_dict)
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 221, in convert_tree
self.right.convert_tree(test_dict)
[Previous line repeated 986 more times]
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 220, in convert_tree
self.right = StringTree(self.string[i+test_len:])
File "/usr/local/anaconda3/lib/python3.7/site-packages/opencc_python_reimplemented-0.1.5-py3.7.egg/opencc/opencc.py", line 189, in __init__
self.string_len = len(string)
RecursionError: maximum recursion depth exceeded while calling a Python object
Hopkins1 commented
I'm guessing the Chinese input file doesn't have any punctuation or spaces and it has at least 1000 characters in it. Or it has some really long punctuation-free strings of characters.
The program does the following:
- Split the input by punctuation/space into a list of strings
- Then scan a string for the longest dictionary match and replace those characters
- Repeat number 2 above on the characters before and after the match building a binary tree
- Combine the results by walking the tree to build the new string
Steps 2 and 3 are recursive.
If possible, throw some spaces into the input string. Otherwise one could add a line of code to set the recursion limit higher than the default value of 1000. (see: sys.setrecursionlimit(limit))