@Override
  public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(
      String sparqlQueryString,
      BindingSet bindings,
      String baseUri,
      QueryType type,
      Service service)
      throws QueryEvaluationException {
    RepositoryConnection conn = endpoint.getConn();
    try {
      TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, sparqlQueryString, 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 (OpenRDFException e) {
      throw new QueryEvaluationException(e);
    }
  }
Ejemplo n.º 2
0
  protected int verifyQueryResult(
      CloseableIteration<? extends BindingSet, QueryEvaluationException> resultIter,
      int expectedBindingCount)
      throws QueryEvaluationException {
    int resultCount = 0;

    while (resultIter.hasNext()) {
      BindingSet resultBindings = resultIter.next();
      resultCount++;

      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++;
      }

      assertEquals("Wrong number of bindings in binding set", expectedBindingCount, bindingCount);
    }

    return resultCount;
  }
 @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());
   }
   if (bIndex > -1) res.addAll(bindings.get(bIndex));
   return res;
 }