Java Code Examples for org.eclipse.rdf4j.query.BindingSet#iterator()
The following examples show how to use
org.eclipse.rdf4j.query.BindingSet#iterator() .
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: SAILFederatedService.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean ask(Service service, BindingSet bindings, String baseUri) throws QueryEvaluationException { RepositoryConnection conn = endpoint.getConn(); try { BooleanQuery query = conn.prepareBooleanQuery(QueryLanguage.SPARQL, service.getAskQueryString(), baseUri); Iterator<Binding> bIter = bindings.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); if (service.getServiceVars().contains(b.getName())) query.setBinding(b.getName(), b.getValue()); } return query.evaluate(); } catch(Throwable e) { throw new QueryEvaluationException(e); } finally { conn.close(); } }
Example 2
Source File: SAILFederatedService.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
@Override public CloseableIteration<BindingSet, QueryEvaluationException> select(Service service, Set<String> projectionVars, BindingSet bindings, String baseUri) throws QueryEvaluationException { RepositoryConnection conn = endpoint.getConn(); try { TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, service.getSelectQueryString(projectionVars), baseUri); Iterator<Binding> bIter = bindings.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); if (service.getServiceVars().contains(b.getName())) query.setBinding(b.getName(), b.getValue()); } TupleQueryResult qRes = query.evaluate(); return new InsertBindingsIteration(qRes, bindings); } catch(Throwable e) { throw new QueryEvaluationException(e); } finally { conn.close(); } }
Example 3
Source File: RDFStoreTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int verifyQueryResult(CloseableIteration<? extends BindingSet, QueryEvaluationException> resultIter, int expectedBindingCount) throws QueryEvaluationException { int resultCount = 0; while (resultIter.hasNext()) { BindingSet resultBindings = resultIter.next(); resultCount++; Assert.assertEquals("Wrong number of binding names for binding set", expectedBindingCount, resultBindings.getBindingNames().size()); int bindingCount = 0; Iterator<Binding> bindingIter = resultBindings.iterator(); while (bindingIter.hasNext()) { bindingIter.next(); bindingCount++; } Assert.assertEquals("Wrong number of bindings in binding set", expectedBindingCount, bindingCount); } return resultCount; }
Example 4
Source File: BoundJoinVALUESConversionIteration.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException { QueryBindingSet res = new QueryBindingSet(); int bIndex = Integer.parseInt(bIn.getBinding(INDEX_BINDING_NAME).getValue().stringValue()); Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); if (b.getName().equals(INDEX_BINDING_NAME)) { continue; } res.addBinding(b); } for (Binding bs : bindings.get(bIndex)) { res.setBinding(bs); } return res; }
Example 5
Source File: GroupedCheckConversionIteration.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
@Override protected BindingSet convert(BindingSet bIn) { int bIndex = -1; Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); String name = b.getName(); bIndex = Integer.parseInt(name.substring(name.lastIndexOf("_")+1)); } return bindings.get(bIndex); }
Example 6
Source File: BoundJoinVALUESConversionIteration.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
@Override protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException { QueryBindingSet res = new QueryBindingSet(); int bIndex = Integer.parseInt(bIn.getBinding(INDEX_BINDING_NAME).getValue().stringValue()); Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); if (b.getName().equals(INDEX_BINDING_NAME)) continue; res.addBinding(b); } for (Binding bs : bindings.get(bIndex)) res.setBinding(bs); return res; }
Example 7
Source File: BoundJoinConversionIteration.java From CostFed with GNU Affero General Public License v3.0 | 5 votes |
@Override protected BindingSet convert(BindingSet bIn) { QueryBindingSet res = new QueryBindingSet(); int bIndex = -1; Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); String name = b.getName(); bIndex = Integer.parseInt(name.substring(name.lastIndexOf("_")+1)); res.addBinding(name.substring(0, name.lastIndexOf("_")), b.getValue()); } res.addAll( bindings.get(bIndex)); return res; }
Example 8
Source File: GroupedCheckConversionIteration.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException { int bIndex = -1; Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); String name = b.getName(); bIndex = Integer.parseInt(name.substring(name.lastIndexOf('_') + 1)); } return bindings.get(bIndex); }
Example 9
Source File: BoundJoinConversionIteration.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException { QueryBindingSet res = new QueryBindingSet(); int bIndex = -1; Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); String name = b.getName(); bIndex = Integer.parseInt(name.substring(name.lastIndexOf('_') + 1)); res.addBinding(name.substring(0, name.lastIndexOf('_')), b.getValue()); } res.addAll(bindings.get(bIndex)); return res; }
Example 10
Source File: AbstractSPARQLJSONWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void handleSolutionImpl(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 | QueryResultHandlerException e) { throw new TupleQueryResultHandlerException(e); } }
Example 11
Source File: ServiceJoinConversionIteration.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException { // overestimate the capacity SPARQLQueryBindingSet res = new SPARQLQueryBindingSet(bIn.size() + bindings.size()); int bIndex = -1; Iterator<Binding> bIter = bIn.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); String name = b.getName(); if (name.equals("__rowIdx")) { bIndex = Integer.parseInt(b.getValue().stringValue()); continue; } res.addBinding(b.getName(), b.getValue()); } // should never occur: in such case we would have to create the cross product (which // is dealt with in another place) if (bIndex == -1) { throw new QueryEvaluationException( "Invalid join. Probably this is due to non-standard behavior of the SPARQL endpoint. " + "Please report to the developers."); } res.addAll(bindings.get(bIndex)); return res; }
Example 12
Source File: AbstractHTTPQuery.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 13
Source File: AbstractHTTPUpdate.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }