请问HanLP2.0中有相似的遍历依存句法树的代码吗
def extactOpinion3(tree):
for word in tree.iterator():
if word.POSTAG == "NN":
if word.DEPREL == "ATT": # ①属性
if tree.findChildren(word.HEAD, "neg").isEmpty():
print("%s = %s" % (word.LEMMA, word.HEAD.LEMMA))
else:
print("%s = 不%s" % (word.LEMMA, word.HEAD.LEMMA))
elif word.DEPREL == "attr":
top = tree.findChildren(word.HEAD, "top") # ②主题
if not top.isEmpty():
print("%s = %s" % (word.LEMMA, top.get(0).LEMMA))