Java Code Examples for org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet#setBinding()

The following examples show how to use org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet#setBinding() . 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: BoundJoinVALUESConversionIteration.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException {
	QueryBindingSet res = new QueryBindingSet();
	int bIndex = Integer.parseInt(bIn.getBinding(INDEX_BINDING_NAME).getValue().stringValue());
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		if (b.getName().equals(INDEX_BINDING_NAME)) {
			continue;
		}
		res.addBinding(b);
	}
	for (Binding bs : bindings.get(bIndex)) {
		res.setBinding(bs);
	}
	return res;
}
 
Example 2
Source File: ProjectionIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static BindingSet project(ProjectionElemList projElemList, BindingSet sourceBindings,
		BindingSet parentBindings, boolean includeAllParentBindings) {
	final QueryBindingSet resultBindings = new QueryBindingSet();
	if (includeAllParentBindings) {
		resultBindings.addAll(parentBindings);
	}

	for (ProjectionElem pe : projElemList.getElements()) {
		Value targetValue = sourceBindings.getValue(pe.getSourceName());
		if (!includeAllParentBindings && targetValue == null) {
			targetValue = parentBindings.getValue(pe.getSourceName());
		}
		if (targetValue != null) {
			resultBindings.setBinding(pe.getTargetName(), targetValue);
		}
	}

	return resultBindings;
}
 
Example 3
Source File: GroupIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Iterator<BindingSet> createIterator() throws QueryEvaluationException {
	Collection<Entry> entries = buildEntries();
	Set<BindingSet> bindingSets = createSet("bindingsets");

	for (Entry entry : entries) {
		QueryBindingSet sol = new QueryBindingSet(parentBindings);

		for (String name : group.getGroupBindingNames()) {
			BindingSet prototype = entry.getPrototype();
			if (prototype != null) {
				Value value = prototype.getValue(name);
				if (value != null) {
					// Potentially overwrites bindings from super
					sol.setBinding(name, value);
				}
			}
		}

		entry.bindSolution(sol);

		bindingSets.add(sol);
	}

	return bindingSets.iterator();
}
 
Example 4
Source File: QueryEvaluationUtil.java    From semagrow with Apache License 2.0 6 votes vote down vote up
public static BindingSet project(ProjectionElemList projElemList,
                                 BindingSet sourceBindings,
                                 BindingSet parentBindings)
{
    QueryBindingSet resultBindings = new QueryBindingSet(parentBindings);

    for (ProjectionElem pe : projElemList.getElements()) {
        Value targetValue = sourceBindings.getValue(pe.getSourceName());
        if (targetValue != null) {
            // Potentially overwrites bindings from super
            resultBindings.setBinding(pe.getTargetName(), targetValue);
        }
    }

    return resultBindings;
}
 
Example 5
Source File: EvaluationStrategyImpl.java    From semagrow with Apache License 2.0 6 votes vote down vote up
public void bindSolution(QueryBindingSet sol) throws QueryEvaluationException {
    Iterator i$ = this.aggregates.keySet().iterator();

    while(i$.hasNext()) {
        String name = (String)i$.next();

        try {
            Value ex = ((Aggregate)this.aggregates.get(name)).getValue();
            if(ex != null) {
                sol.setBinding(name, ex);
            }
        } catch (ValueExprEvaluationException var5) {
            ;
        }
    }

}
 
Example 6
Source File: BoundJoinVALUESConversionIteration.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException {
	QueryBindingSet res = new QueryBindingSet();
	int bIndex = Integer.parseInt(bIn.getBinding(INDEX_BINDING_NAME).getValue().stringValue());
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		if (b.getName().equals(INDEX_BINDING_NAME))
			continue;
		res.addBinding(b);
	}
	for (Binding bs : bindings.get(bIndex))
		res.setBinding(bs);
	return res;
}
 
Example 7
Source File: ExtensionIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public BindingSet convert(BindingSet sourceBindings) throws QueryEvaluationException {
	QueryBindingSet targetBindings = new QueryBindingSet(sourceBindings);

	for (ExtensionElem extElem : extension.getElements()) {
		ValueExpr expr = extElem.getExpr();
		if (!(expr instanceof AggregateOperator)) {
			try {
				// we evaluate each extension element over the targetbindings, so that bindings from
				// a previous extension element in this same extension can be used by other extension elements.
				// e.g. if a projection contains (?a + ?b as ?c) (?c * 2 as ?d)
				Value targetValue = strategy.evaluate(extElem.getExpr(), targetBindings);

				if (targetValue != null) {
					// Potentially overwrites bindings from super
					targetBindings.setBinding(extElem.getName(), targetValue);
				}
			} catch (ValueExprEvaluationException e) {
				// silently ignore type errors in extension arguments. They should not cause the
				// query to fail but result in no bindings for this solution
				// see https://www.w3.org/TR/sparql11-query/#assignment
				// use null as place holder for unbound variables that must remain so
				targetBindings.setBinding(extElem.getName(), null);
			}
		}
	}

	return targetBindings;
}
 
Example 8
Source File: GroupIterator.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void bindSolution(QueryBindingSet sol) throws QueryEvaluationException {
	for (String name : getAggregates().keySet()) {
		try {
			Value value = getAggregates().get(name).getValue();
			if (value != null) {
				// Potentially overwrites bindings from super
				sol.setBinding(name, value);
			}
		} catch (ValueExprEvaluationException ex) {
			// There was a type error when calculating the value of the aggregate. We silently ignore the error,
			// resulting in no result value being bound.
		}
	}
}
 
Example 9
Source File: QueryEvaluationUtil.java    From semagrow with Apache License 2.0 5 votes vote down vote up
public static BindingSet extend(EvaluationStrategy strategy, Collection<ExtensionElem> extElems, BindingSet sourceBindings)
        throws QueryEvaluationException
{
    QueryBindingSet targetBindings = new QueryBindingSet(sourceBindings);

    for (ExtensionElem extElem : extElems) {
        ValueExpr expr = extElem.getExpr();
        if (!(expr instanceof AggregateOperator)) {
            try {
                // we evaluate each extension element over the targetbindings, so that bindings from
                // a previous extension element in this same extension can be used by other extension elements.
                // e.g. if a projection contains (?a + ?b as ?c) (?c * 2 as ?d)
                Value targetValue = strategy.evaluate(extElem.getExpr(), targetBindings);

                if (targetValue != null) {
                    // Potentially overwrites bindings from super
                    targetBindings.setBinding(extElem.getName(), targetValue);
                }
            } catch (ValueExprEvaluationException e) {
                // silently ignore type errors in extension arguments. They should not cause the
                // query to fail but just result in no additional binding.
            }
        }
    }

    return targetBindings;
}