Java Code Examples for org.eclipse.rdf4j.query.algebra.QueryModelNode#visit()

The following examples show how to use org.eclipse.rdf4j.query.algebra.QueryModelNode#visit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneralizedExternalProcessor.java    From rya with Apache License 2.0 6 votes vote down vote up
private static boolean isTupleValid(QueryModelNode node) {

        ValidQueryVisitor vqv = new ValidQueryVisitor();
        node.visit(vqv);

        Set<String> spVars = getVarNames(getQNodes("sp", node));

        if (vqv.isValid() && spVars.size() > 0) {

            FilterCollector fvis = new FilterCollector();
            node.visit(fvis);
            List<QueryModelNode> fList = fvis.getFilters();
            return fList.size() == Sets.newHashSet(fList).size() && getVarNames(fList).size() <= spVars.size();

        } else {
            return false;
        }
    }
 
Example 2
Source File: GeneralizedExternalProcessor.java    From rya with Apache License 2.0 6 votes vote down vote up
private static Set<QueryModelNode> getQNodes(QueryModelNode queryNode) {
    Set<QueryModelNode> rtns = new HashSet<QueryModelNode>();

    StatementPatternCollector spc = new StatementPatternCollector();
    queryNode.visit(spc);
    rtns.addAll(spc.getStatementPatterns());

    FilterCollector fvis = new FilterCollector();
    queryNode.visit(fvis);
    rtns.addAll(fvis.getFilters());

    ExternalTupleCollector eVis = new ExternalTupleCollector();
    queryNode.visit(eVis);
    rtns.addAll(eVis.getExtTup());

    return rtns;
}
 
Example 3
Source File: GeneralizedExternalProcessor.java    From rya with Apache License 2.0 6 votes vote down vote up
private static Set<QueryModelNode> getQNodes(String node, QueryModelNode queryNode) {

        if (node.equals("sp")) {
            Set<QueryModelNode> eSet = new HashSet<QueryModelNode>();
            StatementPatternCollector spc = new StatementPatternCollector();
            queryNode.visit(spc);
            List<StatementPattern> spList = spc.getStatementPatterns();
            eSet.addAll(spList);
            // returns empty set if list contains duplicate StatementPatterns
            if (spList.size() > eSet.size()) {
                return Sets.newHashSet();
            } else {
                return eSet;
            }
        } else if (node.equals("filter")) {

            FilterCollector fvis = new FilterCollector();
            queryNode.visit(fvis);

            return Sets.newHashSet(fvis.getFilters());
        } else {

            throw new IllegalArgumentException("Invalid node type.");
        }
    }
 
Example 4
Source File: GeneralizedExternalProcessor.java    From rya with Apache License 2.0 5 votes vote down vote up
private static void organizeBSAs(QueryModelNode node) {

        BindingSetAssignmentCollector bsac = new BindingSetAssignmentCollector();
        node.visit(bsac);

        if (bsac.containsBSAs()) {
            Set<QueryModelNode> bsaSet = bsac.getBindingSetAssignments();
            BindingSetAssignmentExchangeVisitor bsaev = new BindingSetAssignmentExchangeVisitor(bsaSet);
            node.visit(bsaev);
        }
    }
 
Example 5
Source File: GeneralizedExternalProcessor.java    From rya with Apache License 2.0 5 votes vote down vote up
private static void organizeExtTuples(QueryModelNode node) {

            ExternalTupleCollector eVis = new ExternalTupleCollector();
            node.visit(eVis);

            ExtTupleExchangeVisitor oev = new ExtTupleExchangeVisitor(eVis.getExtTup());
            node.visit(oev);
        }
 
Example 6
Source File: BindingSetAssignmentCollector.java    From semagrow with Apache License 2.0 4 votes vote down vote up
public static List<BindingSetAssignment> process(QueryModelNode node) {
    BindingSetAssignmentCollector collector = new BindingSetAssignmentCollector();
    node.visit(collector);
    return collector.getBindingSetAssigments();
}
 
Example 7
Source File: BasicGraphPatternExtractor.java    From CostFed with GNU Affero General Public License v3.0 4 votes vote down vote up
public static List<TupleExpr> process(QueryModelNode node) {
	BasicGraphPatternExtractor ex = new BasicGraphPatternExtractor();
	node.visit(ex);
	return ex.bgpList;
}
 
Example 8
Source File: QuantifierCollector.java    From semagrow with Apache License 2.0 4 votes vote down vote up
static Collection<Quantifier.Var> process(QueryModelNode node) {
    QuantifierCollector collector = new QuantifierCollector();
    node.visit(collector);
    return collector.vars;
}
 
Example 9
Source File: QueryVariableNormalizer.java    From rya with Apache License 2.0 4 votes vote down vote up
public static List<QueryModelNode> process(QueryModelNode node) {
    FilterVarValueCollector collector = new FilterVarValueCollector();
    node.visit(collector);
    return collector.getVars();
}
 
Example 10
Source File: QueryVariableNormalizer.java    From rya with Apache License 2.0 4 votes vote down vote up
public static List<Var> processVar(QueryModelNode node) {
    VarCollector collector = new VarCollector();
    node.visit(collector);
    return collector.getVars();
}
 
Example 11
Source File: QueryVariableNormalizer.java    From rya with Apache License 2.0 4 votes vote down vote up
public static List<String> process(QueryModelNode node) {
    VarCollector collector = new VarCollector();
    node.visit(collector);
    return collector.getVarNames();
}
 
Example 12
Source File: SparqlFluoQueryBuilder.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public void meet(final Reduced node) {
    //create id, initialize ConstructQueryMetadata builder, register ConstructQueryMetadata
    //builder with FluoQueryBuilder, and add metadata that we currently have
    final String constructId = nodeIds.getOrMakeId(node);

    ConstructQueryMetadata.Builder constructBuilder = fluoQueryBuilder.getConstructQueryBuilder().orNull();
    if(constructBuilder == null) {
        constructBuilder = ConstructQueryMetadata.builder();
        constructBuilder.setNodeId(constructId);
        fluoQueryBuilder.setConstructQueryMetadata(constructBuilder);
    }

    //get child node
    QueryModelNode child = node.getArg();
    Preconditions.checkArgument(child instanceof Projection || child instanceof MultiProjection);
    final UnaryTupleOperator unary = (UnaryTupleOperator) child;

    //get ProjectionElemList to build ConstructGraph
    final List<ProjectionElemList> projections = new ArrayList<>();
    if(unary instanceof Projection) {
        projections.add(((Projection) unary).getProjectionElemList());
    } else {
        projections.addAll(((MultiProjection)unary).getProjections());
    }

    //get ExtensionElems to build ConstructGraph
    final QueryModelNode grandChild = unary.getArg();
    Preconditions.checkArgument(grandChild instanceof Extension);
    final Extension extension = (Extension) grandChild;
    final List<ExtensionElem> extensionElems = extension.getElements();
    final ConstructGraph graph = getConstructGraph(projections, extensionElems);
    constructBuilder.setConstructGraph(graph);

    //set child to the next node we care about in Fluo
    //if Extension's arg is a Group node, then it is an Aggregation, so set child to Extension
    //otherwise set child to Extension's child (only care about Extensions if they are Aggregations)
    if(extension.getArg() instanceof Group) {
        child = extension;
    } else {
        child = extension.getArg();
    }

    //Set the child node in the ConstructQueryMetadataBuilder
    final String childNodeId = nodeIds.getOrMakeId(child);
    constructBuilder.setChildNodeId(childNodeId);

    // Update the child node's metadata.
    final Set<String> childVars = getVars((TupleExpr)child);
    final VariableOrder childVarOrder = new VariableOrder(childVars);
    setChildMetadata(fluoQueryBuilder, childNodeId, childVarOrder, constructId);

    //fast forward visitor to next node we care about
    child.visit(this);
}
 
Example 13
Source File: TripleRefCollector.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Map<String, Object> process(QueryModelNode node) {
	TripleRefCollector collector = new TripleRefCollector();
	node.visit(collector);
	return collector.getTripleRefs();
}
 
Example 14
Source File: VarNameCollector.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Set<String> process(QueryModelNode node) {
	VarNameCollector collector = new VarNameCollector();
	node.visit(collector);
	return collector.getVarNames();
}
 
Example 15
Source File: QueryModelNodeReplacer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void replaceChildNode(QueryModelNode parent, QueryModelNode former, QueryModelNode replacement) {
	this.former = former;
	this.replacement = replacement;
	parent.visit(this);
}
 
Example 16
Source File: StatementPatternCollector.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static List<StatementPattern> process(QueryModelNode node) {
	StatementPatternCollector collector = new StatementPatternCollector();
	node.visit(collector);
	return collector.getStatementPatterns();
}
 
Example 17
Source File: BGPCollector.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void meetNode(QueryModelNode node) throws X {
	// resume previous visitor
	node.visit(visitor);
}
 
Example 18
Source File: QueryModelTreePrinter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static String printTree(QueryModelNode node) {
	QueryModelTreePrinter treePrinter = new QueryModelTreePrinter();
	node.visit(treePrinter);
	return treePrinter.getTreeString();
}