use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class SPARQLCSVTupleBackgroundTest method matchBindingSets.
private boolean matchBindingSets(List<? extends BindingSet> queryResult1, Iterable<? extends BindingSet> queryResult2, Map<BNode, BNode> bNodeMapping, int idx) {
boolean result = false;
if (idx < queryResult1.size()) {
BindingSet bs1 = queryResult1.get(idx);
List<BindingSet> matchingBindingSets = findMatchingBindingSets(bs1, queryResult2, bNodeMapping);
for (BindingSet bs2 : matchingBindingSets) {
// Map bNodes in bs1 to bNodes in bs2
Map<BNode, BNode> newBNodeMapping = new HashMap<BNode, BNode>(bNodeMapping);
for (Binding binding : bs1) {
if (binding.getValue() instanceof BNode) {
newBNodeMapping.put((BNode) binding.getValue(), (BNode) bs2.getValue(binding.getName()));
}
}
// FIXME: this recursive implementation has a high risk of
// triggering a stack overflow
// Enter recursion
result = matchBindingSets(queryResult1, queryResult2, newBNodeMapping, idx + 1);
if (result == true) {
// models match, look no further
break;
}
}
} else {
// All statements have been mapped successfully
result = true;
}
return result;
}
use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class SPARQLCSVTupleTest method matchBindingSets.
private boolean matchBindingSets(List<? extends BindingSet> queryResult1, Iterable<? extends BindingSet> queryResult2, Map<BNode, BNode> bNodeMapping, int idx) {
boolean result = false;
if (idx < queryResult1.size()) {
BindingSet bs1 = queryResult1.get(idx);
List<BindingSet> matchingBindingSets = findMatchingBindingSets(bs1, queryResult2, bNodeMapping);
for (BindingSet bs2 : matchingBindingSets) {
// Map bNodes in bs1 to bNodes in bs2
Map<BNode, BNode> newBNodeMapping = new HashMap<BNode, BNode>(bNodeMapping);
for (Binding binding : bs1) {
if (binding.getValue() instanceof BNode) {
newBNodeMapping.put((BNode) binding.getValue(), (BNode) bs2.getValue(binding.getName()));
}
}
// FIXME: this recursive implementation has a high risk of
// triggering a stack overflow
// Enter recursion
result = matchBindingSets(queryResult1, queryResult2, newBNodeMapping, idx + 1);
if (result == true) {
// models match, look no further
break;
}
}
} else {
// All statements have been mapped successfully
result = true;
}
return result;
}
use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method handleSolution.
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
try {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
if (!headerComplete) {
endHeader();
}
if (!tupleVariablesFound) {
throw new IllegalStateException("Must call startQueryResult before handleSolution");
}
firstTupleWritten = true;
jg.writeStartObject();
Iterator<Binding> bindingIter = bindingSet.iterator();
while (bindingIter.hasNext()) {
Binding binding = bindingIter.next();
jg.writeFieldName(binding.getName());
writeValue(binding.getValue());
}
jg.writeEndObject();
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
} catch (TupleQueryResultHandlerException e) {
throw e;
} catch (QueryResultHandlerException e) {
throw new TupleQueryResultHandlerException(e);
}
}
Aggregations