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

The following examples show how to use org.eclipse.rdf4j.query.algebra.QueryModelNode#replaceWith() . 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: OrderLimitOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void meet(Order node) {
	for (OrderElem e : node.getElements()) {
		e.visit(this);
	}
	if (variablesProjected) {
		QueryModelNode parent = node.getParentNode();
		if (projection == parent) {
			node.replaceWith(node.getArg().clone());
			node.setArg(projection.clone());
			Order replacement = node.clone();
			projection.replaceWith(replacement);
			QueryModelNode distinct = replacement.getParentNode();
			if (distinct instanceof Distinct) {
				distinct.replaceWith(new Reduced(replacement.clone()));
			}
		}
	}
}
 
Example 2
Source File: AbstractExternalSetOptimizer.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void meetNode(QueryModelNode node) {

    if (checkNode(node)) {
        QuerySegment<T> segment = factory.getQuerySegment(node);
        ExternalSetProvider<T> provider = getProvider();
        ExternalSetMatcher<T> matcher = getMatcher(segment);
        QuerySegment<T> tempSeg = null;
        if(useOptimal) {
            tempSeg = matcher.match(provider.getExternalSetCombos(segment), getNodeListRater(segment));
        } else {
            tempSeg = matcher.match(provider.getExternalSets(segment));
        }
        
        TupleExprAndNodes tups = tempSeg.getQuery();
        node.replaceWith(tups.getTupleExpr());
        Set<TupleExpr> unmatched = getUnMatchedArgNodes(tups.getNodes());
        PCJOptimizerUtilities.relocateFilters(tups.getFilters());

        for (final TupleExpr tupleExpr : unmatched) {
            tupleExpr.visit(this);
        }
    } else {
        super.meetNode(node);
    }
}
 
Example 3
Source File: AbstractSearchQueryEvaluator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void replaceQueryPatternsWithResults(final BindingSetAssignment bsa) {
	final QueryModelNode placeholder = removeQueryPatterns();
	if (bsa != null && bsa.getBindingSets() != null && bsa.getBindingSets().iterator().hasNext()) {
		placeholder.replaceWith(bsa);
	} else {
		placeholder.replaceWith(new EmptySet());
	}
}
 
Example 4
Source File: SpinConstructRule.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public void meetNode(QueryModelNode node) {
    if (typeRequirement != null) {
        if (node instanceof TupleExpr && ((TupleExpr) node).getBindingNames().contains(varName)) {
            final Join withType = new Join((TupleExpr) node.clone(), typeRequirement);
            node.replaceWith(withType);
        }
        else {
            node.visitChildren(this);
        }
    }
}
 
Example 5
Source File: QuerySpec.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Replace the given pattern with a new instance of the given replacement type.
 *
 * @param pattern     the pattern to remove
 * @param replacement the replacement type
 */
private void replace(QueryModelNode pattern, Supplier<? extends QueryModelNode> replacement) {
	if (pattern != null) {
		pattern.replaceWith(replacement.get());
	}
}