Search in sources :

Example 1 with ConvertingIteration

use of org.eclipse.rdf4j.common.iteration.ConvertingIteration in project rdf4j by eclipse.

the class SPARQLConnection method toStatementIteration.

/**
 * Converts a {@link TupleQueryResult} resulting from the {@link #EVERYTHING_WITH_GRAPH} to a statement by
 * using the respective values from the {@link BindingSet} or (if provided) the ones from the arguments.
 *
 * @param iter
 *        the {@link TupleQueryResult}
 * @param subj
 *        the subject {@link Resource} used as input or <code>null</code> if wildcard was used
 * @param pred
 *        the predicate {@link IRI} used as input or <code>null</code> if wildcard was used
 * @param obj
 *        the object {@link Value} used as input or <code>null</code> if wildcard was used
 * @return the converted iteration
 */
protected Iteration<Statement, QueryEvaluationException> toStatementIteration(TupleQueryResult iter, final Resource subj, final IRI pred, final Value obj) {
    return new ConvertingIteration<BindingSet, Statement, QueryEvaluationException>(iter) {

        @Override
        protected Statement convert(BindingSet b) throws QueryEvaluationException {
            Resource s = subj == null ? (Resource) b.getValue("s") : subj;
            IRI p = pred == null ? (IRI) b.getValue("p") : pred;
            Value o = obj == null ? b.getValue("o") : obj;
            Resource ctx = (Resource) b.getValue("ctx");
            return SimpleValueFactory.getInstance().createStatement(s, p, o, ctx);
        }
    };
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) ConvertingIteration(org.eclipse.rdf4j.common.iteration.ConvertingIteration) ExceptionConvertingIteration(org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value)

Aggregations

ConvertingIteration (org.eclipse.rdf4j.common.iteration.ConvertingIteration)1 ExceptionConvertingIteration (org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration)1 IRI (org.eclipse.rdf4j.model.IRI)1 Resource (org.eclipse.rdf4j.model.Resource)1 Value (org.eclipse.rdf4j.model.Value)1 BindingSet (org.eclipse.rdf4j.query.BindingSet)1