我在尝试编写递归函数时遇到问题。看起来函数只是没有下降。我没有收到任何错误或任何东西,所以我真的不明白发生了什么。我得到的唯一输出是一些空列表。本质上,我试图跟踪我的程序可以通过某些给定输入采取的所有路径,并返回一个包含所有这些路径的列表。我对 python 非常非常非常陌生,所以有很多我不知道的。我对stackoverflow也很陌生,所以请原谅格式错误。提前致谢!
def Process ( fst, input, start_state, current_path=[], input_index=0 ):
current_line = input.replace('"', '')
current_state = start_state
probability = 1
result = []
state_paths = []
this_path = current_path
paths_found = []
epsilon_paths_found = []
temp_list = []
index = input_index
if not index < len( current_line ):
return this_path
item = current_line[index]
if not item.isspace():
for edge in fst.transitions[current_state]:
next_state = current_state
if item == edge.input:
paths_found.append( edge )
index += 1
for x in paths_found:
temp_list = this_path
temp_list.append( x )
temp_entry = Process( fst, input, x.target_state, temp_list, index )
state_paths.append( temp_entry )
#epsilon returns a list
epsilon = EpsilonStates( fst.transitions[current_state] )
if epsilon:
index -= 1
for i in epsilon:
epsilon_paths_found.append( i )
for y in epsilon_paths_found:
temp_list = this_path
temp_list.append( y )
state_paths.append( Process( fst, input, y.target_state, temp_list, index ) )
return state_paths