// Filters out all partial and invalid matches
bindingsIter = new FilteringCursor<BindingSet>(bindingsIter) {
@Override
protected boolean accept(BindingSet bindingSet) {
Value context = bindingSet.getValue("context");
return bindingSet.getValue("subject") instanceof Resource
&& bindingSet.getValue("predicate") instanceof URI
&& bindingSet.getValue("object") instanceof Value
&& (context == null || context instanceof Resource);
}
@Override
public String getName() {
return "FilterOutPartialMatches";
}
};
// Convert the BindingSet objects to actual RDF statements
final ValueFactory vf = getConnection().getValueFactory();
Cursor<Statement> stIter;
stIter = new ConvertingCursor<BindingSet, Statement>(bindingsIter) {
@Override
protected Statement convert(BindingSet bindingSet) {
Resource subject = (Resource)bindingSet.getValue("subject");
URI predicate = (URI)bindingSet.getValue("predicate");
Value object = bindingSet.getValue("object");
Resource context = (Resource)bindingSet.getValue("context");
if (context == null) {
return vf.createStatement(subject, predicate, object);
}