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

The following examples show how to use org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet#getValue() . 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: PCJKeyToCrossProductBindingSetIterator.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * This method compute the cross product of the BindingSet passed to the PCJ
 * and the PCJ BindingSet.  It verifies that only common variables are unassured
 * variables, and if leftBs and rightBs have distinct values for a given variable,
 * this method uses the value from leftBs in the cross product BindingSet - this
 * is effectively performing a LeftJoin.
 *
 * @param leftBs - BindingSet passed to PCJ
 * @param rightBs - PCJ BindingSet
 * @return - cross product BindingSet
 */
private BindingSet takeCrossProduct(BindingSet leftBs, BindingSet rightBs) {
	if (bindingSetsIntersect(leftBs, rightBs)) {
		return EMPTY_BINDINGSET;
	}
	QueryBindingSet bs = new QueryBindingSet(leftBs);

	//only add Bindings corresponding to variables that have no value
	//assigned.  This takes into account case where leftBs and rightBs
	//share a common, unAssuredVariable.  In this case, use value corresponding
	//to leftBs, which is effectively performing a LeftJoin.
	for(String s: rightBs.getBindingNames()) {
		if(bs.getValue(s) == null) {
			bs.addBinding(s, rightBs.getValue(s));
		}
	}
	return bs;
}
 
Example 2
Source File: StrictEvaluationStrategy.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSetAssignment bsa,
		BindingSet bindings) throws QueryEvaluationException {
	final Iterator<BindingSet> iter = bsa.getBindingSets().iterator();
	if (bindings.size() == 0) { // empty binding set
		return new CloseableIteratorIteration<>(iter);
	}

	CloseableIteration<BindingSet, QueryEvaluationException> result;

	final QueryBindingSet b = new QueryBindingSet(bindings);

	result = new LookAheadIteration<BindingSet, QueryEvaluationException>() {

		@Override
		protected BindingSet getNextElement() throws QueryEvaluationException {
			QueryBindingSet result = null;
			while (result == null && iter.hasNext()) {
				final BindingSet assignedBindings = iter.next();
				for (String name : assignedBindings.getBindingNames()) {
					final Value assignedValue = assignedBindings.getValue(name);
					if (assignedValue != null) { // can be null if set to
						// UNDEF
						// check that the binding assignment does not
						// overwrite
						// existing bindings.
						Value bValue = b.getValue(name);
						if (bValue == null || assignedValue.equals(bValue)) {
							if (result == null) {
								result = new QueryBindingSet(b);
							}
							if (bValue == null) {
								// we are not overwriting an existing
								// binding.
								result.addBinding(name, assignedValue);
							}
						} else {
							// if values are not equal there is no
							// compatible
							// merge and we should return no next element.
							result = null;
							break;
						}
					}
				}
			}
			return result;
		}

	};

	return result;
}