Skip to content
Advertisement

Convert constituent string to Tree object (Stanza)

I am doing some experiments in Python with Stanza and I have converted a lot of sentences into ParseTree objects and saved them into a file like this:

# sent_id = Not relevant for the question
# text = Might be ok for some , but not for me
(S (NONE Might be) (OPINION_1_Negative_Standard (POLAR_EXPRESSION ok)) (NONE for some , but) (OPINION_0_Negative_Standard (POLAR_EXPRESSION not)) (NONE for) (ALL_01 (SOURCE me)))

And now I want to read that file, get the strings of the Tree and convert them again into a ParseTree object but I am not able to find how it should be done properly.

I checked Data Conversion but I can not find what I am trying to do and the Constituency Parser examples show how to get the string representation but not how to convert that string into a Tree.

Regards.

Advertisement

Answer

I have found the solution reading the source code in their GitHub.

Inside the constituency module, in the tree_reader file there is a method called read_trees(text) that it does exactly what I wanted.

Regards.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement