for subtree3 in tree.subtrees():
if subtree3.label() == 'CLAUSE':
print(subtree3)
print subtree3.leaves()
Using this code I able to extract the leaves of the tree. Which are:
[('talking', 'VBG'), ('constantly', 'RB')]
for a certain example. That is perfectly correct. Now I want this Tree elements to convert into string or in list for some further processing. How can I do that?
What I tried
for subtree3 in tree.subtrees():
if subtree3.label() == 'CLAUSE':
print(subtree3)
print subtree3.leaves()
fo.write(subtree3.leaves())
fo.close()
But it throws an error :
Traceback (most recent call last):
File "C:\Python27\Association_verb_adverb.py", line 35, in <module>
fo.write(subtree3.leaves())
TypeError: expected a character buffer object
I just want to store the leaves in a text file.