Package org.openrdf.query

Examples of org.openrdf.query.TupleQueryResult


    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append(" SELECT person");
    queryBuilder.append(" FROM {person} foaf:name {").append(Александър.getLabel()).append("}");
    queryBuilder.append(" USING NAMESPACE foaf = <" + FOAF_NS + ">");

    TupleQueryResult result = testCon.prepareTupleQuery(QueryLanguage.SERQL, queryBuilder.toString()).evaluate();

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

      while (result.hasNext()) {
        BindingSet solution = result.next();
        assertTrue(solution.hasBinding("person"));
        assertEquals(alexander, solution.getValue("person"));
      }
    }
    finally {
      result.close();
    }
  }
View Full Code Here


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

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

    TupleQueryResult result = query.evaluate();

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

      while (result.hasNext()) {
        BindingSet solution = result.next();
        assertTrue(solution.hasBinding("name"));
        assertTrue(solution.hasBinding("mbox"));

        Value nameResult = solution.getValue("name");
        Value mboxResult = solution.getValue("mbox");

        assertTrue("unexpected value for name: " + nameResult, nameBob.equals(nameResult));
        assertTrue("unexpected value for mbox: " + mboxResult, mboxBob.equals(mboxResult));
      }
    }
    finally {
      result.close();
    }
  }
View Full Code Here

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

    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SERQL, queryBuilder.toString());
    query.setBinding("name", Александър);

    TupleQueryResult result = query.evaluate();

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

      while (result.hasNext()) {
        BindingSet solution = result.next();
        assertTrue(solution.hasBinding("person"));
        assertEquals(alexander, solution.getValue("person"));
      }
    }
    finally {
      result.close();
    }
  }
View Full Code Here

    xcal.setMonth(11);
    xcal.setDay(6);
    xcal.setTimezone(OFFSET);
    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, SELECT_BY_DATE);
    query.setBinding("date", vf.createLiteral(xcal));
    TupleQueryResult result = query.evaluate();
    List list = new ArrayList();
    while (result.hasNext()) {
      list.add(result.next());
    }
    assertEquals(7, list.size());
  }
View Full Code Here

      if (dataset != null) {
        query.setDataset(dataset);
      }

      if (query instanceof TupleQuery) {
        TupleQueryResult queryResult = ((TupleQuery)query).evaluate();

        TupleQueryResult expectedResult = readExpectedTupleQueryResult();
        compareTupleQueryResults(queryResult, expectedResult);

        // Graph queryGraph = RepositoryUtil.asGraph(queryResult);
        // Graph expectedGraph = readExpectedTupleQueryResult();
        // compareGraphs(queryGraph, expectedGraph);
View Full Code Here

    TupleQueryResultFormat tqrFormat = QueryResultIO.getParserFormatForFileName(resultFileURL);

    if (tqrFormat != null) {
      InputStream in = new URL(resultFileURL).openStream();
      try {
        TupleQueryResult tqr = QueryResultIO.parse(in, tqrFormat);
        // return RepositoryUtil.asGraph(tqr);
        return tqr;
      }
      finally {
        in.close();
View Full Code Here

    query.append(" USING NAMESPACE ");
    query.append(" qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
    TupleQuery namedGraphsQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());

    logger.debug("evaluating query..");
    TupleQueryResult testCases = testCaseQuery.evaluate();
    while (testCases.hasNext()) {
      BindingSet bindingSet = testCases.next();

      String testURI = bindingSet.getValue("testURI").toString();
      String testName = bindingSet.getValue("testName").toString();
      String resultFile = bindingSet.getValue("resultFile").toString();
      String queryFile = bindingSet.getValue("queryFile").toString();
      URI defaultGraphURI = (URI)bindingSet.getValue("defaultGraph");
      Value action = bindingSet.getValue("action");

      logger.debug("found test case : {}", testName);

      // Query named graphs
      namedGraphsQuery.setBinding("action", action);
      TupleQueryResult namedGraphs = namedGraphsQuery.evaluate();

      DatasetImpl dataset = null;

      if (defaultGraphURI != null || namedGraphs.hasNext()) {
        dataset = new DatasetImpl();

        if (defaultGraphURI != null) {
          dataset.addDefaultGraph(defaultGraphURI);
        }

        while (namedGraphs.hasNext()) {
          BindingSet graphBindings = namedGraphs.next();
          URI namedGraphURI = (URI)graphBindings.getValue("graph");
          dataset.addNamedGraph(namedGraphURI);
        }
      }
View Full Code Here

  {
    // Try to extract suite name from manifest file
    TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL,
        "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}");
    manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createURI(manifestFileURL));
    TupleQueryResult manifestNames = manifestNameQuery.evaluate();
    try {
      if (manifestNames.hasNext()) {
        return manifestNames.next().getValue("ManifestName").stringValue();
      }
    }
    finally {
      manifestNames.close();
    }

    // Derive name from manifest URL
    int lastSlashIdx = manifestFileURL.lastIndexOf('/');
    int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1);
View Full Code Here

  }

  private boolean evaluateSparql(String qry) throws RepositoryException,
      MalformedQueryException, QueryEvaluationException {
    TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, qry);
    TupleQueryResult evaluate = query.evaluate();
    try {
      return evaluate.hasNext();
    } finally {
      evaluate.close();
    }
  }
View Full Code Here

        + "        mf:action {} qt:query {query}; " + "                     qt:data {input} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>, "
        + "  tck = <urn:openrdf.org:sesame:tests#> ";

    TupleQueryResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = ((Literal)testBindings.getValue("testName")).getLabel();
      String inputFile = testBindings.getValue("input").toString();
      String queryFile = testBindings.getValue("query").toString();
      String resultFile = testBindings.getValue("result").toString();
      String entailment = ((Literal)testBindings.getValue("entailment")).getLabel();

      query = "SELECT graph " + "FROM {} mf:name {testName}; "
          + "        mf:action {} qt:graphData {graph} " + "WHERE testName = \""
          + SeRQLUtil.encodeString(testName) + "\" " + "USING NAMESPACE"
          + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>,"
          + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

      List<String> graphNames = new ArrayList<String>();

      TupleQueryResult graphs = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
      while (graphs.hasNext()) {
        BindingSet graphBindings = graphs.next();
        graphNames.add(graphBindings.getValue("graph").toString());
      }
      graphs.close();

      suite.addTest(new SeRQLQueryTest(testName, inputFile, graphNames, queryFile, resultFile, entailment));
    }

    tests.close();
View Full Code Here

TOP

Related Classes of org.openrdf.query.TupleQueryResult

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.