}
public GraphResult evaluate()
throws StoreException
{
GraphQueryModel query = getParsedQuery();
Cursor<? extends BindingSet> bindingsIter = evaluate(query);
// 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);
}
else {
return vf.createStatement(subject, predicate, object, context);
}
}
@Override
protected String getName() {
return "CreateStatement";
}
};
return new GraphResultImpl(query.getQueryNamespaces(), stIter);
}