private Evaluator<Boolean> buildBooleanEvaluator(final Tree tree) { switch (tree.getType()) { case TRUE: return addToken(new BooleanLiteralEvaluator(true), "true"); case FALSE: return addToken(new BooleanLiteralEvaluator(false), "true"); } throw new AttributeExpressionLanguageParsingException("Cannot build Boolean evaluator from tree " + tree.toString()); }
throw new AttributeExpressionLanguageParsingException("Expected a Function-type expression but got " + tree.toString());
return addToken(new MultiMatchAttributeEvaluator(attributeNames, ANY_MATCHING_ATTRIBUTE), "anyMatchingAttribute"); default: throw new AssertionError("Illegal Multi-Attribute Reference: " + functionTypeTree.toString()); throw new AttributeExpressionLanguageParsingException("Unexpected token: " + tree.toString());
final StringBuilder sb = new StringBuilder(); for ( final Tree t : tree.getLeaves() ) { sb.append(t.toString()).append(" "); }
public String toString() { StringBuffer result = new StringBuffer(); for (Tree t : db) { result.append(t.toString()).append("\n"); } return result.toString(); }
public void printTree(CommonTree t, int indent) { if ( t != null ) { StringBuffer sb = new StringBuffer(indent); for ( int i = 0; i < indent; i++ ) sb = sb.append(" "); for ( int i = 0; i < t.getChildCount(); i++ ) { System.out.println("" + i + sb.toString() + t.getChild(i).toString()); printTree((CommonTree)t.getChild(i), indent+1); } } }
public void printTree(CommonTree t, int indent) { if ( t != null ) { StringBuffer sb = new StringBuffer(indent); for ( int i = 0; i < indent; i++ ) sb = sb.append(" "); for ( int i = 0; i < t.getChildCount(); i++ ) { System.out.println("" + i + sb.toString() + t.getChild(i).toString()); printTree((CommonTree)t.getChild(i), indent+1); } } }
1 2 3 4 5 6 Depth first - 1 2 4 5 3 6 Breadth first - 1 2 3 4 5 6 //For depth first public void traverseTree(Tree tree){ System.out.println(tree.toString()); for (int x = 0; x < tree.getChildCount(); x++) traverseTree(tree.getChild(x)); }
int counter = 0; public void traverseTree(Tree tree) { for (int i=0; i<tree.getChildCount(); i++) { Tree child = tree.getChild(i); System.out.println(tree.toString() + counter++); traverseTree(tree); } }
private String getDefaultFieldText(Tree tree) throws QueryParseException { String val = tree.getChild(0).toString(); if (val.startsWith("\"") && val.endsWith("\"") && val.length() >= 2) { val = val.substring(1, val.length() - 1); } if (!isValidExpression(val)) { throw new QueryParseException("Invalid query at " + tree.getCharPositionInLine() + ": " + tree.getText()); } return Query.sanitizeValue(val); }
public void traverseTree(Tree tree) { // print, increment counter, whatever System.out.println(tree.toString()); // traverse children int childCount = tree.getChildCount(); if (childCount == 0) { // leaf node, we're done } else { for (int i = 0; i < childCount; i++) { Tree child = tree.getChild(i); traverseTree(child); } } }
public static void dfs(Tree node, Tree parent, HeadFinder headFinder) { if (node == null || node.isLeaf()) { return; } //if node is a NP - Get the terminal nodes to get the words in the NP if(node.value().equals("NP") ) { System.out.println(" Noun Phrase is "); List<Tree> leaves = node.getLeaves(); for(Tree leaf : leaves) { System.out.print(leaf.toString()+" "); } System.out.println(); System.out.println(" Head string is "); System.out.println(node.headTerminal(headFinder, parent)); } for(Tree child : node.children()) { dfs(child, node, headFinder); } }
private void updateOuterASTDuplicateAliases(ASTNode node, Map<String, List<String>> aliasMap) { if (node.getToken().getType() == HiveParser.DOT) { String col = node.getChild(1).toString(); for (Map.Entry<String, List<String>> entry : aliasMap.entrySet()) { if (entry.getValue().contains(col)) { try { node.setChild(1, HQLParser.parseExpr(entry.getKey())); } catch (LensException e) { log.error("Unable to parse select expression: {}.", entry.getKey()); } } } } for (int i = 0; i < node.getChildCount(); i++) { ASTNode child = (ASTNode) node.getChild(i); updateOuterASTDuplicateAliases(child, aliasMap); } }
/** * Update alias in all AST trees * * @param tree */ protected void replaceAlias(ASTNode tree) { if (TOK_TABLE_OR_COL == tree.getToken().getType()) { ASTNode alias = (ASTNode) tree.getChild(0); if (mapAliases.get(tree.getChild(0).toString()) != null) { alias.getToken().setText(mapAliases.get(tree.getChild(0).toString())); } else { alias.getToken().setText(tree.getChild(0).toString()); } } for (int i = 0; i < tree.getChildCount(); i++) { replaceAlias((ASTNode) tree.getChild(i)); } }
/** * Get columns used in ASTNode * * @param node * @param msrs * @return */ private Set<String> getAllColumnsOfNode(ASTNode node, Set<String> msrs, StorageCandidateHQLContext sc) { if (node.getToken().getType() == HiveParser.DOT) { String col = node.getChild(1).toString(); msrs.addAll(getSourceColumnOfRefColumn(col, sc)); } for (int i = 0; i < node.getChildCount(); i++) { ASTNode child = (ASTNode) node.getChild(i); getAllColumnsOfNode(child, msrs, sc); } return msrs; }