我正在尝试使用Spacy.io从给定的原始输入语句生成可能的排列和组合句子。首先,我生成了 Dependency Parse 树并开始遍历树。
输入语句的依赖关系树:Click here to see the Dependency Tree
以下是我用来遍历树的示例代码。
DECLARE @date DATE = GETDATE()
;WITH MonthsCTE AS (
SELECT 1 [Month], DATEADD(DAY, -DATEPART(DAY, @date)+1, @date) as 'MonthStart'
UNION ALL
SELECT [Month] + 1, DATEADD(MONTH, 1, MonthStart)
FROM MonthsCTE
WHERE [Month] < 12 )
SELECT * FROM MonthsCTE
这是代码的主要语法。虽然我的原始代码仍有很多描述。我在这里发布我的完整代码 Click here for Code。
当我运行此代码时,我收到以下回溯错误:
Traceback(最近一次调用最后一次):文件“main.py”,第183行,in
def traverse_the_tree(doc,root,init_track,call_from): generated_sentence = [[],[],[]] subjects = list(root.lefts) objects = list(root.rights) #traverse through LeftSubTree for left_ST in subjects: generated_sentence[0].append(left_ST) #append the root generated_sentence[1].append(root) #traverse through RightSubTree for right_ST in objects: #check if the SubTree if(check_if_has_subtree(right_ST)): #return True or False generated_sentence[2].append(right_ST) #write this outerfile with open("output.txt","a") as fp: fp.write("{},{},{}".format(generated_sentence[0],generated_sentence[1],generated_sentence[2])) else: traverse_the_tree(doc,right_ST,init_track,call_from)
我想从输入句子生成示例输出。 Click here to see the Docs
谢谢!