Package org.openrdf.result

Examples of org.openrdf.result.TupleResult


    request.sendQueryString(Arrays.asList(pair));

    try {
      request.acceptTupleQueryResult();
      execute(request);
      TupleResult result = request.getTupleQueryResult();
      try {
        if (result.hasNext()) {
          BindingSet bindings = result.next();
          return (BNode)bindings.getValue(BNODE);
        }
        return null;
      }
      finally {
        result.close();
      }
    }
    catch (IOException e) {
      throw new StoreException(e);
    }
View Full Code Here


  private BNode loadBNodes()
    throws StoreException, QueryResultParseException, NoCompatibleMediaType
  {
    BNode bnode;
    TupleResult result = client.post(amount *= 2);
    try {
      if (!result.hasNext()) {
        throw new StoreException("No BNodes");
      }
      bnode = (BNode)result.next().getValue(BNODE);
      while (result.hasNext()) {
        queue.add((BNode)result.next().getValue(BNODE));
      }
    }
    finally {
      result.close();
    }
    return bnode;
  }
View Full Code Here

    verifyIsOpen();

    flush();
    List<Resource> contextList = new ArrayList<Resource>();

    TupleResult contextIDs = client.contexts().list();
    try {
      while (contextIDs.hasNext()) {
        BindingSet bindingSet = contextIDs.next();
        Value context = bindingSet.getValue("contextID");

        if (context instanceof Resource) {
          contextList.add((Resource)context);
        }
      }
    }
    finally {
      contextIDs.close();
    }

    return new ContextResultImpl(new CollectionCursor<Resource>(contextList));
  }
View Full Code Here

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

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

      TupleResult tupleQueryResult = con.prepareTupleQuery(ql, queryString).evaluate();

      try {
        int resultCount = 0;
        List<String> bindingNames = tupleQueryResult.getBindingNames();

        if (bindingNames.isEmpty()) {
          while (tupleQueryResult.hasNext()) {
            tupleQueryResult.next();
            resultCount++;
          }
        }
        else {
          int columnWidth = (consoleWidth - 1) / bindingNames.size() - 3;

          // Build table header
          StringBuilder sb = new StringBuilder(consoleWidth);
          for (String bindingName : bindingNames) {
            sb.append("| ").append(bindingName);
            StringUtil.appendN(' ', columnWidth - bindingName.length(), sb);
          }
          sb.append("|");
          String header = sb.toString();

          // Build separator line
          sb.setLength(0);
          for (int i = bindingNames.size(); i > 0; i--) {
            sb.append('+');
            StringUtil.appendN('-', columnWidth + 1, sb);
          }
          sb.append('+');
          String separatorLine = sb.toString();

          // Write table header
          writeln(separatorLine);
          writeln(header);
          writeln(separatorLine);

          // Write table rows

          while (tupleQueryResult.hasNext()) {
            BindingSet bindingSet = tupleQueryResult.next();
            resultCount++;

            sb.setLength(0);
            for (String bindingName : bindingNames) {
              Value value = bindingSet.getValue(bindingName);
              String valueStr = getStringRepForValue(value, namespaces);

              sb.append("| ").append(valueStr);
              StringUtil.appendN(' ', columnWidth - valueStr.length(), sb);
            }
            sb.append("|");
            writeln(sb.toString());
          }

          writeln(separatorLine);
        }

        long endTime = System.nanoTime();
        writeln(resultCount + " result(s) (" + (endTime - startTime) / 1000000 + " ms)");
      }
      finally {
        tupleQueryResult.close();
      }
    }
    finally {
      con.close();
    }
View Full Code Here

   * send SeRQL-select queries.
   */
  public void testSeRQLselect()
    throws Exception
  {
    TupleResult queryResult = evaluate(TestServer.REPOSITORY_URL, "select * from {X} P {Y}",
        QueryLanguage.SERQL);
    QueryResultIO.write(queryResult, TupleQueryResultFormat.SPARQL, System.out);
  }
View Full Code Here

      preparedQuery.setDataset(dataset);
      preparedQuery.setIncludeInferred(includeInferred);


//      long startTime = System.nanoTime();
      TupleResult result = preparedQuery.evaluate();
//      long endTime = System.nanoTime();
//      System.out.println("Received response in " + (endTime - startTime) / 1000000);
      return new InsertBindingSetCursor(result, bindings);
    }
  }
View Full Code Here

    throws StoreConfigException
  {
    List<RepositoryInfo> result = new ArrayList<RepositoryInfo>();

    try {
      TupleResult responseFromServer = client.repositories().list();
      while (responseFromServer.hasNext()) {
        BindingSet bindingSet = responseFromServer.next();
        RepositoryInfo repInfo = new RepositoryInfo();

        String id = LiteralUtil.getLabel(bindingSet.getValue("id"), null);

        if (skipSystemRepo && id.equals(SystemRepository.ID)) {
View Full Code Here

  }

  public <H extends TupleQueryResultHandler> H evaluate(H handler)
    throws StoreException, TupleQueryResultHandlerException
  {
    TupleResult queryResult = evaluate();
    QueryResultUtil.report(queryResult, handler);
    return handler;
  }
View Full Code Here

    String query = "SELECT DISTINCT manifestFile FROM {x} rdf:first {manifestFile} "
        + "USING NAMESPACE mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleResult manifestResults = con.prepareTupleQuery(QueryLanguage.SERQL, query, MANIFEST_FILE).evaluate();

    while (manifestResults.hasNext()) {
      BindingSet bindingSet = manifestResults.next();
      String manifestFile = bindingSet.getValue("manifestFile").toString();
      suite.addTest(SPARQLQueryTest.suite(manifestFile, factory));
    }

    manifestResults.close();
    con.close();
    manifestRep.shutDown();

    logger.info("Created aggregated test suite with " + suite.countTestCases() + " test cases.");
    return suite;
View Full Code Here

    ManifestTest.addTurtle(con, manifest, MANIFEST_FILE);

    logger.info("Searching for sub-manifests");
    List<String> subManifestList = new ArrayList<String>();

    TupleResult subManifests = con.prepareTupleQuery(QueryLanguage.SERQL, SUBMANIFEST_QUERY).evaluate();
    while (subManifests.hasNext()) {
      BindingSet bindings = subManifests.next();
      subManifestList.add(bindings.getValue("subManifest").toString());
    }
    subManifests.close();

    logger.info("Found {} sub-manifests", subManifestList.size());

    for (String subManifest : subManifestList) {
      logger.info("Loading sub manifest {}", subManifest);
      con.clear();

      URL subManifestURL = new URL(subManifest);
      ManifestTest.addTurtle(con, subManifestURL, subManifest);

      TestSuite subSuite = new TestSuite(subManifest.substring(HOST.length()));

      logger.info("Creating test cases for {}", subManifest);
      TupleResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, TESTCASE_QUERY).evaluate();
      while (tests.hasNext()) {
        BindingSet bindingSet = tests.next();

        String testURI = bindingSet.getValue("TestURI").toString();
        String testName = bindingSet.getValue("Name").toString();
        String testAction = bindingSet.getValue("Action").toString();
        boolean positiveTest = bindingSet.getValue("Type").toString().equals(
            "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#PositiveSyntaxTest");

        subSuite.addTest(factory.createSPARQLSyntaxTest(testURI, testName, testAction, positiveTest));
      }
      tests.close();

      suite.addTest(subSuite);
    }

    con.close();
View Full Code Here

TOP

Related Classes of org.openrdf.result.TupleResult

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.