Search in sources :

Example 1 with Binding

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;
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) Value(org.eclipse.rdf4j.model.Value)

Example 2 with Binding

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);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) BNode(org.eclipse.rdf4j.model.BNode) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) Value(org.eclipse.rdf4j.model.Value)

Example 3 with Binding

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);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Example 4 with Binding

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;
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) BindingSet(org.eclipse.rdf4j.query.BindingSet)

Example 5 with Binding

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);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) UpdateExecutionException(org.eclipse.rdf4j.query.UpdateExecutionException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) Update(org.eclipse.rdf4j.query.Update)

Aggregations

Binding (org.eclipse.rdf4j.query.Binding)18 Value (org.eclipse.rdf4j.model.Value)6 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 BNode (org.eclipse.rdf4j.model.BNode)4 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)4 IRI (org.eclipse.rdf4j.model.IRI)3 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)3 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)3 SimpleBinding (org.eclipse.rdf4j.query.impl.SimpleBinding)3 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Literal (org.eclipse.rdf4j.model.Literal)2 QueryResultHandlerException (org.eclipse.rdf4j.query.QueryResultHandlerException)2 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)2 SAXException (org.xml.sax.SAXException)2 ClearNamespacesOperation (org.eclipse.rdf4j.http.protocol.transaction.operations.ClearNamespacesOperation)1 RemoveNamespaceOperation (org.eclipse.rdf4j.http.protocol.transaction.operations.RemoveNamespaceOperation)1 SPARQLUpdateOperation (org.eclipse.rdf4j.http.protocol.transaction.operations.SPARQLUpdateOperation)1 SetNamespaceOperation (org.eclipse.rdf4j.http.protocol.transaction.operations.SetNamespaceOperation)1