@Override protected boolean accept(BindingSet outputBindings) throws QueryEvaluationException { return QueryResults.bindingSetsCompatible(inputBindings, outputBindings); } }
protected boolean accept(BindingSet object) throws X { if (!initialized) { // Build set of elements-to-exclude from right argument excludeSet = makeSet(getRightArg()); initialized = true; } boolean compatible = false; for (BindingSet excluded : excludeSet) { // build set of shared variable names Set<String> sharedBindingNames = makeSet(excluded.getBindingNames()); sharedBindingNames.retainAll(object.getBindingNames()); // two bindingsets that share no variables are compatible by // definition, however, the formal // definition of SPARQL MINUS indicates that such disjoint sets should // be filtered out. // See http://www.w3.org/TR/sparql11-query/#sparqlAlgebra if (!sharedBindingNames.isEmpty()) { if (QueryResults.bindingSetsCompatible(excluded, object)) { // at least one compatible bindingset has been found in the // exclude set, therefore the object is compatible, therefore it // should not be accepted. compatible = true; break; } } } return !compatible; }
@Override protected BindingSet getNextElement() throws QueryEvaluationException { BindingSet result = super.getNextElement(); // Ignore all results that are not compatible with the input bindings while (result != null && !QueryResults.bindingSetsCompatible(inputBindings, result)) { result = super.getNextElement(); } if (result != null) { // Make sure the provided problemVars are part of the returned results // (necessary in case of e.g. LeftJoin and Union arguments) QueryBindingSet extendedResult = null; for (String problemVar : problemVars) { if (!result.hasBinding(problemVar)) { if (extendedResult == null) { extendedResult = new QueryBindingSet(result); } extendedResult.addBinding(problemVar, inputBindings.getValue(problemVar)); } } if (extendedResult != null) { result = extendedResult; } } return result; }