Package org.openrdf.result

Examples of org.openrdf.result.TupleResult


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

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

    TupleResult result = query.evaluate();

    try {
      assertNotNull(result);
      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));
    TupleResult result = query.evaluate();
    List<BindingSet> list = new ArrayList<BindingSet>();
    while (result.hasNext()) {
      list.add(result.next());
    }
    assertEquals(7, list.size());
  }
View Full Code Here

    testCon.add(s, p1, v1);
    testCon.add(s, p2, v2);
    testCon.add(s, p1, v3);
    String qry = "PREFIX :<urn:test:> SELECT ?s ?v1 ?v2 WHERE " + optional;
    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, qry);
    TupleResult result = query.evaluate();
    Set<List<Value>> set = new HashSet<List<Value>>();
    while (result.hasNext()) {
      BindingSet bindings = result.next();
      set.add(Arrays.asList(bindings.getValue("v1"), bindings.getValue("v2")));
    }
    result.close();
    assertTrue(set.contains(Arrays.asList(v1, v2)));
    assertTrue(set.contains(Arrays.asList(v3, null)));
  }
View Full Code Here

    URI o = vf.createURI("urn:test:o");
    testCon.add(s, p1, o);
    testCon.add(s, p2, o);
    String qry = "PREFIX :<urn:test:> SELECT ?p WHERE " + union;
    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, qry);
    TupleResult result = query.evaluate();
    List<Value> list = new ArrayList<Value>();
    while (result.hasNext()) {
      BindingSet bindings = result.next();
      list.add(bindings.getValue("p"));
    }
    result.close();
    assertTrue(list.contains(p1));
    assertTrue(list.contains(p2));
  }
View Full Code Here

    testCon.add(s, p1, one);
    testCon.add(s, p3, three);
    String qry = "PREFIX :<urn:test:>\nPREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>\n"
        + "SELECT ?s WHERE { ?s :p1 ?one ; :p3 ?three FILTER (datatype(?one / ?three) = xsd:decimal) }";
    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, qry);
    TupleResult result = query.evaluate();
    assertTrue(result.hasNext());
    result.close();
  }
View Full Code Here

    TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL,
        "select ?s where {?s ?p ?o FILTER (isBlank(?s))}");

    BNode blankNode = null;

    TupleResult result = query.evaluate();
    while (result.hasNext()) {
      BindingSet set = result.next();
      blankNode = (BNode)set.getValue("s");
    }
    result.close();

    if (blankNode != null) {
      query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "select ?s where {?s ?p ?o}");
      query.setBinding("s", blankNode);

      result = query.evaluate();
      try {
        // the query must have at least one result
        assertTrue(result.hasNext());
      }
      finally {
        result.close();
      }
    }
  }
View Full Code Here

    }

    TupleQuery tupleQuery = testCon.prepareTupleQuery(QueryLanguage.SERQL,
        "SELECT S, P, O FROM {S} P {O} WHERE P = <" + pred.stringValue() + ">", null);

    TupleResult iter;
    iter = tupleQuery.evaluate();

    try {
      assertTrue(iter.hasNext());
      BindingSet bindings = iter.next();
      assertEquals(subj, bindings.getValue("S"));
      assertEquals(pred, bindings.getValue("P"));
      assertEquals(obj, bindings.getValue("O"));
      assertFalse(iter.hasNext());
    }
    finally {
      iter.close();
    }

    tupleQuery = testCon.prepareTupleQuery(QueryLanguage.SERQL, "SELECT S, P, O FROM {S} P {O} WHERE P = <"
        + pred.stringValue() + ">", null);
    tupleQuery.setBinding("S", subj);
    tupleQuery.setBinding("P", pred);
    tupleQuery.setBinding("O", obj);

    iter = tupleQuery.evaluate();

    try {
      assertTrue(iter.hasNext());
      BindingSet bindings = iter.next();
      assertEquals(subj, bindings.getValue("S"));
      assertEquals(pred, bindings.getValue("P"));
      assertEquals(obj, bindings.getValue("O"));
      assertFalse(iter.hasNext());
    }
    finally {
      iter.close();
    }
  }
View Full Code Here

  private void testQueryResult(TupleQueryResultFormat format)
    throws IOException, QueryResultParseException, TupleQueryResultHandlerException,
    UnsupportedQueryResultFormatException, StoreException
  {
    TupleResult input = createQueryResult();
    TupleResult expected = createQueryResult();

    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    QueryResultIO.write(input, format, out);
    input.close();

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    TupleResult output = QueryResultIO.parse(in, format);

    assertTrue(QueryResultUtil.equals(expected, output));
  }
View Full Code Here

  private void testSingletonQueryResult(TupleQueryResultFormat format)
    throws StoreException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException,
    IOException, QueryResultParseException
  {
    TupleResult input = createSingletonQueryResult();
    TupleResult expected = createSingletonQueryResult();

    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    QueryResultIO.write(input, format, out);
    input.close();

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    TupleResult output = QueryResultIO.parse(in, format);

    assertTrue(QueryResultUtil.equals(expected, output));
  }
View Full Code Here

  }

  public TupleResult evaluate()
    throws StoreException
  {
    TupleResult result = getQuery().evaluate();

    Cursor<BindingSet> signedBindings = new DelegatingCursor<BindingSet>(result) {

      @Override
      public BindingSet next()
        throws StoreException
      {
        return getSigner().sign(super.next());
      }
    };

    return new TupleResultImpl(result.getBindingNames(), signedBindings);
  }
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.