Package org.openrdf.query

Examples of org.openrdf.query.BooleanQuery


    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ ?p foaf:name ?name }");

    BooleanQuery query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    assertTrue(query.ask());
  }
View Full Code Here


    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ ?p foaf:name ?name }");

    BooleanQuery query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    assertTrue(query.ask());

    DatasetImpl dataset = new DatasetImpl();

    // default graph: {context1}
    dataset.addDefaultGraph(context1);
    query.setDataset(dataset);
    assertTrue(query.ask());

    // default graph: {context1, context2}
    dataset.addDefaultGraph(context2);
    query.setDataset(dataset);
    assertTrue(query.ask());

    // default graph: {context2}
    dataset.removeDefaultGraph(context1);
    query.setDataset(dataset);
    assertFalse(query.ask());

    queryBuilder.setLength(0);
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ GRAPH ?g { ?p foaf:name ?name } }");

    query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    // default graph: {context2}; named graph: {}
    query.setDataset(dataset);
    assertFalse(query.ask());

    // default graph: {context1, context2}; named graph: {context2}
    dataset.addDefaultGraph(context1);
    dataset.addNamedGraph(context2);
    query.setDataset(dataset);
    assertFalse(query.ask());

    // default graph: {context1, context2}; named graph: {context1, context2}
    dataset.addNamedGraph(context1);
    query.setDataset(dataset);
    assertTrue(query.ask());
  }
View Full Code Here

  }
 
  @Override
  public boolean sparqlAsk(String queryString) throws ModelRuntimeException {
    this.assertModel();
    BooleanQuery booleanQuery;
    try {
      booleanQuery = this.connection.prepareBooleanQuery(QueryLanguage.SPARQL, queryString);
      boolean result = booleanQuery.evaluate();
      return result;
    } catch(OpenRDFException e) {
      throw new ModelRuntimeException(e);
    }
  }
View Full Code Here

        // test snapshot connection for date2 (i.e. after base import and before updates)
        RepositoryConnection snapshot1 = repository.getSnapshot(date2);

        // query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 3
        BooleanQuery query1_1 = snapshot1.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R1> ?p ?o }");
        Assert.assertTrue("SPARQL query for R1 did not return true", query1_1.evaluate());

        // query all triples for http://marmotta.apache.org/testing/ns1/R2, should be zero
        BooleanQuery query1_2 = snapshot1.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R2> ?p ?o }");
        Assert.assertFalse("SPARQL query for R2 did not return false", query1_2.evaluate());

        snapshot1.commit();
        snapshot1.close();

        // test snapshot connection for date3 (i.e. after first update)
        RepositoryConnection snapshot2 = repository.getSnapshot(date3);

        // query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 3
        BooleanQuery query2_1 = snapshot2.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R1> ?p ?o }");
        Assert.assertTrue("SPARQL query for R1 did not return true", query2_1.evaluate());

        // query all triples for http://marmotta.apache.org/testing/ns1/R2, should be 3
        BooleanQuery query2_2 = snapshot2.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R2> ?p ?o }");
        Assert.assertTrue("SPARQL query for R2 did not return true", query2_2.evaluate());

        snapshot2.commit();
        snapshot2.close();

View Full Code Here

        queryResult = gQuery.evaluate();
        registry = RDFWriterRegistry.getInstance();
        view = GraphQueryResultView.getInstance();
      }
      else if (query instanceof BooleanQuery) {
        BooleanQuery bQuery = (BooleanQuery)query;

        queryResult = bQuery.evaluate();
        registry = BooleanQueryResultWriterRegistry.getInstance();
        view = BooleanQueryResultView.getInstance();
      }
      else {
        throw new ClientHTTPException(SC_BAD_REQUEST, "Unsupported query type: "
View Full Code Here

    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ ?p foaf:name ?name }");

    BooleanQuery query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    assertTrue(query.evaluate());
  }
View Full Code Here

    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ ?p foaf:name ?name }");

    BooleanQuery query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    assertTrue(query.evaluate());

    DatasetImpl dataset = new DatasetImpl();

    // default graph: {context1}
    dataset.addDefaultGraph(context1);
    query.setDataset(dataset);
    assertTrue(query.evaluate());

    // default graph: {context1, context2}
    dataset.addDefaultGraph(context2);
    query.setDataset(dataset);
    assertTrue(query.evaluate());

    // default graph: {context2}
    dataset.removeDefaultGraph(context1);
    query.setDataset(dataset);
    assertFalse(query.evaluate());

    queryBuilder.setLength(0);
    queryBuilder.append("PREFIX foaf: <" + FOAF_NS + "> ");
    queryBuilder.append("ASK ");
    queryBuilder.append("{ GRAPH ?g { ?p foaf:name ?name } }");

    query = testCon.prepareBooleanQuery(QueryLanguage.SPARQL, queryBuilder.toString());
    query.setBinding("name", nameBob);

    // default graph: {context2}; named graph: {}
    query.setDataset(dataset);
    assertFalse(query.evaluate());

    // default graph: {context1, context2}; named graph: {context2}
    dataset.addDefaultGraph(context1);
    dataset.addNamedGraph(context2);
    query.setDataset(dataset);
    assertFalse(query.evaluate());

    // default graph: {context1, context2}; named graph: {context1, context2}
    dataset.addNamedGraph(context1);
    query.setDataset(dataset);
    assertTrue(query.evaluate());
  }
View Full Code Here

        // test snapshot connection for date2 (i.e. after base import and before updates)
        RepositoryConnection snapshot1 = repository.getSnapshot(date2);

        // query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 3
        BooleanQuery query1_1 = snapshot1.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R1> ?p ?o }");
        Assert.assertTrue("SPARQL query for R1 did not return true", query1_1.evaluate());

        // query all triples for http://marmotta.apache.org/testing/ns1/R2, should be zero
        BooleanQuery query1_2 = snapshot1.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R2> ?p ?o }");
        Assert.assertFalse("SPARQL query for R2 did not return false", query1_2.evaluate());

        snapshot1.commit();
        snapshot1.close();

        // test snapshot connection for date3 (i.e. after first update)
        RepositoryConnection snapshot2 = repository.getSnapshot(date3);

        // query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 3
        BooleanQuery query2_1 = snapshot2.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R1> ?p ?o }");
        Assert.assertTrue("SPARQL query for R1 did not return true", query2_1.evaluate());

        // query all triples for http://marmotta.apache.org/testing/ns1/R2, should be 3
        BooleanQuery query2_2 = snapshot2.prepareBooleanQuery(QueryLanguage.SPARQL, "ASK { <http://marmotta.apache.org/testing/ns1/R2> ?p ?o }");
        Assert.assertTrue("SPARQL query for R2 did not return true", query2_2.evaluate());

        snapshot2.commit();
        snapshot2.close();

View Full Code Here

        assertTrue(connection.size() > 0);

        int count = connection.getStatements(null, null, null, false).asList().size();
        assertTrue(count > 0);

        BooleanQuery sparqlQuery = (BooleanQuery)connection.prepareQuery(QueryLanguage.SPARQL, IOUtils.toString(sparql).replaceAll("http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/rdfa1.1/","http://localhost/rdfa/"));
        assertTrue("SPARQL query evaluation for "+fileName+" failed",sparqlQuery.evaluate());

        connection.close();
        repository.shutDown();
    }
View Full Code Here

        assertTrue(connection.size() > 0);

        int count = connection.getStatements(null, null, null, false).asList().size();
        assertTrue(count > 0);

        BooleanQuery sparqlQuery = (BooleanQuery)connection.prepareQuery(QueryLanguage.SPARQL, IOUtils.toString(sparql).replaceAll("http://rdfa.digitalbazaar.com/test-suite/test-cases/xhtml1/rdfa1.1/","http://localhost/rdfa/"));
        assertTrue("SPARQL query evaluation for "+fileName+" failed",sparqlQuery.evaluate());

        connection.close();
        repository.shutDown();
    }
View Full Code Here

TOP

Related Classes of org.openrdf.query.BooleanQuery

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.