parse-tree

NLTK tree data structure, finding a node, it's parent or children

强颜欢笑 提交于 2019-11-27 21:38:41
I am using nltk's Tree data structure to work with parsetree strings. from nltk.tree import Tree parsed = Tree('(ROOT (S (NP (PRP It)) (VP (VBZ is) (ADJP (RB so) (JJ nice))) (. .)))') The data structure, however, seems to be limited. Is it possible to get a node by it's string value and then navigate to top or bottom? For example suppose you want to get the node with string value 'nice' and then see what's its parent, children, etc. Is it achievable via nltk's Tree? For NLTK 3.0, you want to use the ParentedTree subclass. http://www.nltk.org/api/nltk.html#nltk.tree.ParentedTree Using the

What's the difference between parse trees and abstract syntax trees?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 19:49:11
问题 I found the two terms in a compiler design book, and I'd like to know what each stands for, and how they are different. I searched on the internet and found that parse trees are also called concrete syntax trees (CSTs). 回答1: This is based on the Expression Evaluator grammar by Terrence Parr. The grammar for this example: grammar Expr002; options { output=AST; ASTLabelType=CommonTree; // type of $stat.tree ref etc... } prog : ( stat )+ ; stat : expr NEWLINE -> expr | ID '=' expr NEWLINE -> ^('

Stanford NLP parse tree format

為{幸葍}努か 提交于 2019-11-27 16:57:21
问题 This may be a silly question, but how does one iterate through a parse tree as an output of an NLP parser (like Stanford NLP)? It's all nested brackets, which is neither an array nor a dictionary or any other collection type I've used. (ROOT\n (S\n (PP (IN As)\n (NP (DT an) (NN accountant)))\n (NP (PRP I))\n (VP (VBP want)\n (S\n (VP (TO to)\n (VP (VB make)\n (NP (DT a) (NN payment)))))))) 回答1: This particular output format of the Stanford Parser is call the "bracketed parse (tree)". It is

antlr3 - Generating a Parse Tree

我与影子孤独终老i 提交于 2019-11-26 21:25:58
问题 I'm having trouble figuring out the antlr3 API so I can generate and use a parse tree in some javascript code. When I open the grammar file using antlrWorks (their IDE), the interpreter is able to show me the parse tree, and it's even correct. I'm having a lot of difficulties tracking down resources on how to get this parse tree in my code using the antlr3 runtime. I've been messing around with the various functions in the runtime and Parser files but to no avail: var input = "(PR=5000)",

NLTK tree data structure, finding a node, it's parent or children

岁酱吖の 提交于 2019-11-26 20:45:14
问题 I am using nltk's Tree data structure to work with parsetree strings. from nltk.tree import Tree parsed = Tree('(ROOT (S (NP (PRP It)) (VP (VBZ is) (ADJP (RB so) (JJ nice))) (. .)))') The data structure, however, seems to be limited. Is it possible to get a node by it's string value and then navigate to top or bottom? For example suppose you want to get the node with string value 'nice' and then see what's its parent, children, etc. Is it achievable via nltk's Tree? 回答1: For NLTK 3.0, you

What's the difference between parse tree and AST?

爱⌒轻易说出口 提交于 2019-11-26 17:29:57
问题 Are they generated by different phases of a compiling process? Or are they just different names for the same thing? 回答1: This is based on the Expression Evaluator grammar by Terrence Parr. The grammar for this example: grammar Expr002; options { output=AST; ASTLabelType=CommonTree; // type of $stat.tree ref etc... } prog : ( stat )+ ; stat : expr NEWLINE -> expr | ID '=' expr NEWLINE -> ^('=' ID expr) | NEWLINE -> ; expr : multExpr (( '+'^ | '-'^ ) multExpr)* ; multExpr : atom ('*'^ atom)* ;