Package org.openrdf.query

Examples of org.openrdf.query.GraphQueryResult


    setContentDisposition(model, response, rdfFormat);

    OutputStream out = response.getOutputStream();
    try {
      RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
      GraphQueryResult graphQueryResult = (GraphQueryResult)model.get(QUERY_RESULT_KEY);
      QueryResultUtil.report(graphQueryResult, rdfWriter);
    }
    catch (QueryEvaluationException e) {
      logger.error("Query evaluation error", e);
      response.sendError(SC_INTERNAL_SERVER_ERROR, "Query evaluation error: " + e.getMessage());
View Full Code Here


      writeln("Evaluating query...");
      long startTime = System.currentTimeMillis();

      Collection<Namespace> namespaces = con.getNamespaces().addTo(new ArrayList<Namespace>());

      GraphQueryResult queryResult = con.prepareGraphQuery(ql, queryString).evaluate();

      try {
        int resultCount = 0;

        while (queryResult.hasNext()) {
          Statement st = queryResult.next();
          resultCount++;

          write(getStringRepForValue(st.getSubject(), namespaces));
          write("   ");
          write(getStringRepForValue(st.getPredicate(), namespaces));
          write("   ");
          write(getStringRepForValue(st.getObject(), namespaces));
          writeln();
        }

        long endTime = System.currentTimeMillis();
        writeln(resultCount + " results (" + (endTime - startTime) + " ms)");
      }
      finally {
        queryResult.close();
      }
    }
    finally {
      con.close();
    }
View Full Code Here

    queryBuilder.append(" USING NAMESPACE foaf = <" + FOAF_NS + ">");

    GraphQuery query = testCon.prepareGraphQuery(QueryLanguage.SERQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    GraphQueryResult result = query.evaluate();

    try {
      assertTrue(result != null);
      assertTrue(result.hasNext());

      while (result.hasNext()) {
        Statement st = result.next();
        assertTrue(name.equals(st.getPredicate()) || mbox.equals(st.getPredicate()));
        if (name.equals(st.getPredicate())) {
          assertTrue("unexpected value for name: " + st.getObject(), nameBob.equals(st.getObject()));
        }
        else {
          assertTrue(mbox.equals(st.getPredicate()));
          assertTrue("unexpected value for mbox: " + st.getObject(), mboxBob.equals(st.getObject()));
        }

      }
    }
    finally {
      result.close();
    }
  }
View Full Code Here

        // Graph queryGraph = RepositoryUtil.asGraph(queryResult);
        // Graph expectedGraph = readExpectedTupleQueryResult();
        // compareGraphs(queryGraph, expectedGraph);
      }
      else if (query instanceof GraphQuery) {
        GraphQueryResult gqr = ((GraphQuery)query).evaluate();
        Set<Statement> queryResult = Iterations.asSet(gqr);

        Set<Statement> expectedResult = readExpectedGraphQueryResult();

        compareGraphs(queryResult, expectedResult);
View Full Code Here

    for (String graphName : graphNames) {
      dataCon.add(new URL(graphName), null, RDFFormat.forFileName(graphName), new URIImpl(graphName));
    }

    // Evaluate the query on the query data
    GraphQueryResult result = dataCon.prepareGraphQuery(QueryLanguage.SERQL, query).evaluate();
    Collection<Statement> actualStatements = Iterations.addAll(result, new ArrayList<Statement>(1));
    result.close();

    dataCon.close();
    dataRep.shutDown();

    // Create a repository with the expected result data
View Full Code Here

    queryBuilder.append(" CONSTRUCT *");
    queryBuilder.append(" FROM {} foaf:name {name};");
    queryBuilder.append("         foaf:mbox {mbox}");
    queryBuilder.append(" USING NAMESPACE foaf = <" + FOAF_NS + ">");

    GraphQueryResult result = testCon.prepareGraphQuery(QueryLanguage.SERQL, queryBuilder.toString()).evaluate();

    try {
      assertTrue(result != null);
      assertTrue(result.hasNext());

      while (result.hasNext()) {
        Statement st = result.next();
        if (name.equals(st.getPredicate())) {
          assertTrue(nameAlice.equals(st.getObject()) || nameBob.equals(st.getObject()));
        }
        else {
          assertTrue(mbox.equals(st.getPredicate()));
          assertTrue(mboxAlice.equals(st.getObject()) || mboxBob.equals(st.getObject()));
        }
      }
    }
    finally {
      result.close();
    }
  }
View Full Code Here

        filteredQuery = _SPARQL.replace("?instance", "_:" + selected.toString());
      } else {
        filteredQuery = _SPARQL.replace("?instance", "<" + selected.toString() + ">");
      }

      GraphQueryResult graphResult = conn.prepareGraphQuery(QueryLanguage.SPARQL, filteredQuery).evaluate();
      while (graphResult.hasNext()) {
        statements.add(graphResult.next());
      }
      graphResult.close();
      conn.close();
    } catch (RepositoryException e) {
      throw new InvalidResultSetException("Repository exception encountered selecting statements", e);
    } catch (MalformedQueryException e) {
      throw new InvalidResultSetException("Bad query encountered selecting statements using " + this._SPARQL, e);
View Full Code Here

    return construct(sparql, null, mapper);
  }
 
  public <T> List<T> construct(String sparql,  Map<String, Object> args, GraphMapper<T> mapper) {
    Connection connection = dataSource.getConnection();
    GraphQueryResult result = null;
    try {
      GraphQuery query = connection.graph(sparql);
     
      if (args != null) {
        for (Entry<String, Object> arg : args.entrySet()) {          
          query.parameter(arg.getKey(), arg.getValue());
        }
      }
     
      ArrayList<T> list = new ArrayList<T>();
     
      result = query.execute();
     
      // return empty lists for empty queries
      if (result == null) {
        return list;
      }
     
      while (result.hasNext()) {
        list.add(mapper.mapRow(result.next()));
      }

      return list;
    } catch (StardogException e) {
      log.error("Error sending construct query to Stardog", e);
      throw new RuntimeException(e);
    } catch (QueryEvaluationException e) {
      log.error("Error evaluating SPARQL construct query", e);
      throw new RuntimeException(e);
    } finally {
      if (result != null) {
        try {
          result.close();
        }
        catch (QueryEvaluationException e) { }
      }
      dataSource.releaseConnection(connection);
    }
View Full Code Here

    return (Value[][]) results.toArray(new Value[0][0]);
  }

  private static Graph doGraphQuery(RepositoryConnection con, String query) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    GraphQuery resultsTable = con.prepareGraphQuery(QueryLanguage.SPARQL, query);
    GraphQueryResult statements = resultsTable.evaluate();
    Graph g = new GraphImpl();

    Vector<Value[]> results = new Vector<Value[]>();
    for (int row = 0; statements.hasNext(); row++) {
      Statement pairs = statements.next();
      g.add(pairs);
//      List<String> names = statements.getBindingNames();
//      Value[] rv = new Value[names.size()];
//      for (int i = 0; i < names.size(); i++) {
//        String name = names.get(i);
View Full Code Here

    return (Value[][]) results.toArray(new Value[0][0]);
  }

  private static Graph doGraphQuery(RepositoryConnection con, String query) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
    GraphQuery resultsTable = con.prepareGraphQuery(QueryLanguage.SPARQL, query);
    GraphQueryResult statements = resultsTable.evaluate();
    Graph g = new GraphImpl();

    Vector<Value[]> results = new Vector<Value[]>();
    for (int row = 0; statements.hasNext(); row++) {
      Statement pairs = statements.next();
      g.add(pairs);
//      List<String> names = statements.getBindingNames();
//      Value[] rv = new Value[names.size()];
//      for (int i = 0; i < names.size(); i++) {
//        String name = names.get(i);
View Full Code Here

TOP

Related Classes of org.openrdf.query.GraphQueryResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.