use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testNamedGraphLoadWAuth.
public void testNamedGraphLoadWAuth() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
RdfCloudTripleStore tstore = new MockRdfCloudStore();
NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
tstore.setNamespaceManager(nm);
SailRepository repo = new SailRepository(tstore);
tstore.getRyaDAO().getConf().setCv("1|2");
repo.initialize();
RepositoryConnection conn = repo.getConnection();
conn.add(stream, "", RDFFormat.TRIG);
conn.commit();
String query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + // "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
"WHERE\n" + "{\n" + " GRAPH ex:G1\n" + " {\n" + " ?m voc:name ?name ;\n" + " voc:homepage ?hp .\n" + " } .\n" + " GRAPH ex:G2\n" + " {\n" + " ?m voc:hasSkill ?skill .\n" + " } .\n" + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
// no auth
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
repo.shutDown();
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testNamedGraphLoad.
public void testNamedGraphLoad() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
RepositoryConnection conn = repository.getConnection();
conn.add(stream, "", RDFFormat.TRIG);
conn.commit();
String query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + // "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
"WHERE\n" + "{\n" + " GRAPH ex:G1\n" + " {\n" + " ?m voc:name ?name ;\n" + " voc:homepage ?hp .\n" + " } .\n" + " GRAPH ex:G2\n" + " {\n" + " ?m voc:hasSkill ?skill .\n" + " } .\n" + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
// tupleQuery.evaluate(new PrintTupleHandler());
assertEquals(1, tupleHandler.getCount());
query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX swp: <http://www.w3.org/2004/03/trix/swp-1/>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + "WHERE\n" + "{\n" + " GRAPH ex:G3\n" + " {\n" + " ?g swp:assertedBy ?w .\n" + " ?w swp:authority ex:Tom .\n" + " } .\n" + " GRAPH ?g\n" + " {\n" + " ?m voc:name ?name .\n" + " } .\n" + "}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX swp: <http://www.w3.org/2004/03/trix/swp-1/>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + "WHERE\n" + "{\n" + " GRAPH ?g\n" + " {\n" + " ?m voc:name ?name .\n" + " } .\n" + "}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
// tupleQuery.setBinding(BINDING_DISP_QUERYPLAN, VALUE_FACTORY.createLiteral(true));
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(2, tupleHandler.getCount());
conn.close();
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testNamespaceUsage.
public void testNamespaceUsage() throws Exception {
RepositoryConnection conn = repository.getConnection();
conn.setNamespace("lit", litdupsNS);
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
final URI uri1 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.commit();
String query = "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {lit:cpu lit:loadPerc ?o.}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.evaluate(new TupleQueryResultHandler() {
@Override
public void startQueryResult(List<String> strings) throws TupleQueryResultHandlerException {
}
@Override
public void endQueryResult() throws TupleQueryResultHandlerException {
}
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
assertTrue(uri1.toString().equals(bindingSet.getBinding("o").getValue().stringValue()));
}
@Override
public void handleBoolean(boolean paramBoolean) throws QueryResultHandlerException {
}
@Override
public void handleLinks(List<String> paramList) throws QueryResultHandlerException {
}
});
conn.close();
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testTransitiveProp.
public void testTransitiveProp() throws Exception {
if (internalInferenceEngine == null) {
// infer not supported;
return;
}
RepositoryConnection conn = repository.getConnection();
conn.add(new StatementImpl(vf.createURI(litdupsNS, "subRegionOf"), RDF.TYPE, OWL.TRANSITIVEPROPERTY));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "Queens"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NYC")));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "NYC"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NY")));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "NY"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "US")));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "US"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NorthAmerica")));
conn.add(new StatementImpl(vf.createURI(litdupsNS, "NorthAmerica"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "World")));
conn.commit();
conn.close();
internalInferenceEngine.refreshGraph();
conn = repository.getConnection();
String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:subRegionOf lit:NorthAmerica.}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(4, tupleHandler.getCount());
query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:subRegionOf lit:NY.}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(2, tupleHandler.getCount());
query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {lit:Queens lit:subRegionOf ?s.}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(5, tupleHandler.getCount());
query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {lit:NY lit:subRegionOf ?s.}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(3, tupleHandler.getCount());
conn.close();
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testUpdateWAuthOnConfig.
// Set the persistence visibilites on the config
public void testUpdateWAuthOnConfig() throws Exception {
String sparqlUpdate = getSparqlUpdate();
RdfCloudTripleStore tstore = new MockRdfCloudStore();
NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
tstore.setNamespaceManager(nm);
SailRepository repo = new SailRepository(tstore);
tstore.getRyaDAO().getConf().setCv("1|2");
repo.initialize();
RepositoryConnection conn = repo.getConnection();
Update u = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlUpdate);
u.execute();
String query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + // "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
"WHERE\n" + "{\n" + " GRAPH ex:G1\n" + " {\n" + " ?m voc:name ?name ;\n" + " voc:homepage ?hp .\n" + " } .\n" + " GRAPH ex:G2\n" + " {\n" + " ?m voc:hasSkill ?skill .\n" + " } .\n" + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
// no auth
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
repo.shutDown();
}
Aggregations