書き込もうとしている再帰関数に問題があります。関数が下降していないようです。エラーも何も出ていないので、何が起こっているのかよくわかりません。そこから得られる唯一の出力は、いくつかの空のリストです。基本的に、プログラムが特定の入力を介して通過できるすべてのパスを追跡し、それらすべてのパスを保持するリストを返そうとしています。私は本当に、本当に、本当にPythonに慣れていないので、知らないことがたくさんあります。私はスタックオーバーフローも初めてなので、フォーマットエラーを許してください。前もって感謝します!
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