Java Code Examples for org.eclipse.rdf4j.common.iteration.Iteration#next()

The following examples show how to use org.eclipse.rdf4j.common.iteration.Iteration#next() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HasAllObjects.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
	QueryPreparer qp = getCurrentQueryPreparer();
	if (args.length != 3) {
		throw new ValueExprEvaluationException(
				String.format("%s requires 3 argument, got %d", getURI(), args.length));
	}
	Resource subj = (Resource) args[0];
	IRI pred = (IRI) args[1];
	Resource list = (Resource) args[2];
	try {
		Iteration<Value, QueryEvaluationException> iter = TripleSources.list(list, qp.getTripleSource());
		while (iter.hasNext()) {
			Value obj = iter.next();
			if (TripleSources.single(subj, pred, obj, qp.getTripleSource()) == null) {
				return BooleanLiteral.FALSE;
			}
		}
	} catch (QueryEvaluationException e) {
		throw new ValueExprEvaluationException(e);
	}
	return BooleanLiteral.TRUE;
}
 
Example 2
Source File: SpinParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Projection visitResultNodes(Resource resultNodes) throws RDF4JException {
	ProjectionElemList projElemList = new ProjectionElemList();
	Iteration<Resource, QueryEvaluationException> iter = TripleSources.listResources(resultNodes,
			store);
	while (iter.hasNext()) {
		Resource r = iter.next();
		ProjectionElem projElem = visitResultNode(r);
		projElemList.addElement(projElem);
	}

	Projection proj = new Projection();
	proj.setProjectionElemList(projElemList);

	tupleRoot = new DescribeOperator(proj);
	return proj;
}
 
Example 3
Source File: SpinParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Projection visitResultVariables(Resource resultVars, Map<String, ProjectionElem> previousProjElems)
		throws RDF4JException {
	ProjectionElemList projElemList = new ProjectionElemList();
	Iteration<Resource, QueryEvaluationException> iter = TripleSources.listResources(resultVars,
			store);
	while (iter.hasNext()) {
		Resource r = iter.next();
		ProjectionElem projElem = visitResultVariable(r, previousProjElems);
		projElemList.addElement(projElem);
	}

	Projection proj = new Projection();
	proj.setProjectionElemList(projElemList);

	tupleRoot = proj;
	return proj;
}
 
Example 4
Source File: RDFStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private <T> T first(Iteration<T, ?> iter) throws Exception {
	try {
		if (iter.hasNext()) {
			return iter.next();
		}
	} finally {
		Iterations.closeCloseable(iter);
	}

	return null;
}
 
Example 5
Source File: RDFStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int countElements(Iteration<?, ?> iter) throws Exception {
	int count = 0;

	try {
		while (iter.hasNext()) {
			iter.next();
			count++;
		}
	} finally {
		Iterations.closeCloseable(iter);
	}

	return count;
}
 
Example 6
Source File: SpinParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private TupleExpr visitHaving(Resource having) throws RDF4JException {
	UnaryTupleOperator op = (UnaryTupleOperator) group.getParentNode();
	op.setArg(new Extension(group));
	Iteration<Resource, QueryEvaluationException> iter = TripleSources.listResources(having, store);
	while (iter.hasNext()) {
		Resource r = iter.next();
		ValueExpr havingExpr = visitExpression(r);
		Filter filter = new Filter(op.getArg(), havingExpr);
		op.setArg(filter);
		op = filter;
	}
	return op;
}
 
Example 7
Source File: SpinParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Order visitOrderBy(Resource orderby) throws RDF4JException {
	Order order = new Order();
	Iteration<Resource, QueryEvaluationException> iter = TripleSources.listResources(orderby, store);
	while (iter.hasNext()) {
		Resource r = iter.next();
		OrderElem orderElem = visitOrderByCondition(r);
		order.addElement(orderElem);
	}
	return order;
}
 
Example 8
Source File: SpinParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void visitInsert(Resource insert) throws RDF4JException {
	Iteration<Resource, QueryEvaluationException> groupIter = TripleSources.listResources(insert,
			store);
	while (groupIter.hasNext()) {
		Resource r = groupIter.next();
		Value type = TripleSources.singleValue(r, RDF.TYPE, store);
		visitPattern(r, (type != null) ? Collections.singleton((IRI) type) : Collections.<IRI>emptySet(), null);
	}
}
 
Example 9
Source File: SpinParser.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void visitDelete(Resource delete) throws RDF4JException {
	Iteration<Resource, QueryEvaluationException> groupIter = TripleSources.listResources(delete,
			store);
	while (groupIter.hasNext()) {
		Resource r = groupIter.next();
		Value type = TripleSources.singleValue(r, RDF.TYPE, store);
		visitPattern(r, (type != null) ? Collections.singleton((IRI) type) : Collections.<IRI>emptySet(), null);
	}
}