How to read parsing

I have a set of offers that have been pre-processed by Stanford CoreNLP systems. One of the things he provides is the Parse Tree proposal (group based). Although I can understand the parse tree when drawing (for example, a tree), I'm not sure how to read it in this format:

eg:.

(ROOT (FRAG (NP (NN sent28)) (: :) (S (NP (NNP Rome)) (VP (VBZ is) (PP (IN in) (NP (NP (NNP Lazio) (NN province)) (CC and) (NP (NP (NNP Naples)) (PP (IN in) (NP (NNP Campania)))))))) (. .))) 

Original offer:

 sent28: Rome is in Lazio province and Naples in Campania . 

How should I read this tree, or, alternatively, is there code (in python) that does this correctly? Thanks.

+5
source share
2 answers

NLTK has a class for reading parsing trees: nltk.tree.Tree . The corresponding method is called fromstring . Then you can iterate over its subtrees, leaves, etc.

Aside: you can remove the bit that sent28: says sent28: as it confuses the parser (it is also not part of the sentence). You do not get a full parse tree, but just a fragment of a sentence.

+10
source

You can simply use the stanford parser, for example:

 sentences = parser.raw_parse_sents(["Hello, My name is Melroy.", "What is your name?"]) #probably raw_parse(just a string) or parse_sents(list but has been splited) for line in sentences: for sentence in line: ***sentence.draw()*** 
-3
source

Source: https://habr.com/ru/post/1213985/


All Articles