private Tree<S> parseExpr(Tree<S> tree) { String currentToken = tokens.get(currentTokenId); if (currentToken.equals("(")) { currentTokenId++; currentToken = tokens.get(currentTokenId); Tree<S> newTree = new Tree<>(nodeParser.parseNode(currentToken)); currentTokenId++; newTree = parseSequence(newTree); currentToken = tokens.get(currentTokenId); if (currentToken.equals(")")) { currentTokenId++; tree.addSubtree(newTree); return tree; } else { throw new IllegalArgumentException("Missing close parenthesis near " + currentToken); } } else { tree.addLeaf(nodeParser.parseNode(currentToken)); currentTokenId++; return tree; } }
private Tree<S> parseExpr(Tree<S> tree) { String currentToken = tokens.get(currentTokenId); if (currentToken.equals("(")) { currentTokenId++; currentToken = tokens.get(currentTokenId); Tree<S> newTree = new Tree<>(nodeParser.parseNode(currentToken)); currentTokenId++; newTree = parseSequence(newTree); currentToken = tokens.get(currentTokenId); if (currentToken.equals(")")) { currentTokenId++; tree.addSubtree(newTree); return tree; } else { throw new IllegalArgumentException("Missing close parenthesis near " + currentToken); } } else { tree.addLeaf(nodeParser.parseNode(currentToken)); currentTokenId++; return tree; } }
parent.addLeaf(leafLabel);
parent.addLeaf(leafLabel);
parent.addLeaf(leafLabel);
/** * Takes a Stanford Tree and Curator Tree and recursively populates the Curator Tree to match * the Stanford Tree. Returns the top Node of the tree. * * @param parse Stanford Tree * @return top Node of the Tree */ private static Tree<String> generateNode(edu.stanford.nlp.trees.Tree parse) { Tree<String> node = new Tree<>(parse.value()); for (edu.stanford.nlp.trees.Tree pt : parse.getChildrenAsList()) { if (pt.isLeaf()) { node.addLeaf(pt.nodeString()); } else { // generate child of parse, the current node in tree node.addSubtree(generateNode(pt)); } } return node; }
/** * Takes a Stanford Tree and Curator Tree and recursively populates the Curator Tree to match * the Stanford Tree. Returns the top Node of the tree. * * @param parse Stanford Tree * @return top Node of the Tree */ private static Tree<String> generateNode(edu.stanford.nlp.trees.Tree parse) { Tree<String> node = new Tree<>(parse.value()); for (edu.stanford.nlp.trees.Tree pt : parse.getChildrenAsList()) { if (pt.isLeaf()) { node.addLeaf(pt.nodeString()); } else { // generate child of parse, the current node in tree node.addSubtree(generateNode(pt)); } } return node; }