use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class SPARQLCSVTupleTest method bindingSetsMatch.
private static boolean bindingSetsMatch(BindingSet bs1, BindingSet bs2, Map<BNode, BNode> bNodeMapping) {
if (bs1.size() != bs2.size()) {
return false;
}
for (Binding binding1 : bs1) {
Value value1 = binding1.getValue();
Value value2 = bs2.getValue(binding1.getName());
if (value1 == null && value2 != null) {
return false;
} else if (value1 != null && value2 == null) {
return false;
} else if (value1 != null && value2 != null) {
if (!equals(value1, value2) && !value1.stringValue().equals(value2.stringValue())) {
return false;
}
}
}
return true;
}
use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class DAWGTestResultSetWriter method handleSolution.
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
try {
BNode solutionNode = vf.createBNode();
reportStatement(resultSetNode, SOLUTION, solutionNode);
for (Binding binding : bindingSet) {
BNode bindingNode = vf.createBNode();
reportStatement(solutionNode, BINDING, bindingNode);
reportStatement(bindingNode, VARIABLE, vf.createLiteral(binding.getName()));
Value value = binding.getValue();
// generated for the result format
if (value instanceof BNode) {
BNode mappedBNode = bnodeMap.get(value);
if (mappedBNode == null) {
mappedBNode = vf.createBNode();
bnodeMap.put((BNode) value, mappedBNode);
}
value = mappedBNode;
}
reportStatement(bindingNode, VALUE, value);
}
} catch (RDFHandlerException e) {
throw new TupleQueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class AbstractSPARQLXMLWriter 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");
}
xmlWriter.startTag(RESULT_TAG);
for (Binding binding : bindingSet) {
xmlWriter.setAttribute(BINDING_NAME_ATT, binding.getName());
xmlWriter.startTag(BINDING_TAG);
writeValue(binding.getValue());
xmlWriter.endTag(BINDING_TAG);
}
xmlWriter.endTag(RESULT_TAG);
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
} catch (TupleQueryResultHandlerException e) {
throw e;
} catch (QueryResultHandlerException e) {
throw new TupleQueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class AbstractHTTPUpdate method getBindingsArray.
public Binding[] getBindingsArray() {
BindingSet bindings = this.getBindings();
Binding[] bindingsArray = new Binding[bindings.size()];
Iterator<Binding> iter = bindings.iterator();
for (int i = 0; i < bindings.size(); i++) {
bindingsArray[i] = iter.next();
}
return bindingsArray;
}
use of org.eclipse.rdf4j.query.Binding in project rdf4j by eclipse.
the class SPARQLUpdateOperation method execute.
public void execute(RepositoryConnection con) throws RepositoryException {
try {
Update preparedUpdate = con.prepareUpdate(QueryLanguage.SPARQL, getUpdateString(), getBaseURI());
preparedUpdate.setIncludeInferred(isIncludeInferred());
preparedUpdate.setDataset(getDataset());
if (getBindings() != null) {
for (Binding binding : getBindings()) {
preparedUpdate.setBinding(binding.getName(), binding.getValue());
}
}
preparedUpdate.execute();
} catch (MalformedQueryException e) {
throw new RepositoryException(e);
} catch (UpdateExecutionException e) {
throw new RepositoryException(e);
}
}
Aggregations