use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class AccumuloPcjIT method testSupportedVarOrders1.
@Test
public void testSupportedVarOrders1() throws PcjException, RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, MalformedQueryException, SailException, QueryEvaluationException {
final URI superclass = new URIImpl("uri:superclass");
final URI superclass2 = new URIImpl("uri:superclass2");
conn.add(subclass, RDF.TYPE, superclass);
conn.add(subclass2, RDF.TYPE, superclass2);
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
final String indexSparqlString = //
"" + //
"SELECT ?dog ?pig ?duck " + //
"{" + //
" ?pig a ?dog . " + //
" ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?o ?f ?e ?c ?l " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
"}";
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "dog", "pig", "duck" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais1 = new AccumuloIndexSet(conf, tablename + 1);
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "o", "f", "e", "c", "l" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais2 = new AccumuloIndexSet(conf, tablename + 2);
final Set<String> ais1Set1 = Sets.newHashSet();
ais1Set1.add("dog");
Assert.assertTrue(ais1.supportsBindingSet(ais1Set1));
ais1Set1.add("duck");
Assert.assertTrue(ais1.supportsBindingSet(ais1Set1));
ais1Set1.add("chicken");
Assert.assertTrue(ais1.supportsBindingSet(ais1Set1));
final Set<String> ais2Set1 = Sets.newHashSet();
ais2Set1.add("f");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
ais2Set1.add("e");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
ais2Set1.add("o");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
ais2Set1.add("l");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set1));
final Set<String> ais2Set2 = Sets.newHashSet();
ais2Set2.add("f");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set2));
ais2Set2.add("o");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set2));
ais2Set2.add("c");
Assert.assertTrue(!ais2.supportsBindingSet(ais2Set2));
final Set<String> ais2Set3 = Sets.newHashSet();
ais2Set3.add("c");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set3));
ais2Set3.add("e");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set3));
ais2Set3.add("l");
Assert.assertTrue(ais2.supportsBindingSet(ais2Set3));
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class AccumuloPcjIT method testEvaluateTwoIndexThreeVarOrder3ThreeBindingSet.
@Test
public void testEvaluateTwoIndexThreeVarOrder3ThreeBindingSet() throws TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, PcjException, SailException {
final URI sub3 = new URIImpl("uri:entity3");
final URI subclass3 = new URIImpl("uri:class3");
final URI obj3 = new URIImpl("uri:obj3");
final URI superclass = new URIImpl("uri:superclass");
final URI superclass2 = new URIImpl("uri:superclass2");
final URI superclass3 = new URIImpl("uri:superclass3");
conn.add(sub3, RDF.TYPE, subclass3);
conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
conn.add(sub3, talksTo, obj3);
conn.add(subclass, RDF.TYPE, superclass);
conn.add(subclass2, RDF.TYPE, superclass2);
conn.add(subclass3, RDF.TYPE, superclass3);
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
final String indexSparqlString = //
"" + //
"SELECT ?c ?e ?l " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?o ?f ?l ?e ?c " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
"}";
final String queryString = //
"" + //
"SELECT ?e ?c ?l ?f ?o " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
"}";
final CountingResultHandler crh1 = new CountingResultHandler();
final CountingResultHandler crh2 = new CountingResultHandler();
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "c", "e", "l" }, Optional.<PcjVarOrderFactory>absent());
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "o", "f", "l", "e", "c" }, Optional.<PcjVarOrderFactory>absent());
conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh1);
PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix);
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh2);
Assert.assertEquals(3, crh1.getCount());
Assert.assertEquals(3, crh2.getCount());
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class AccumuloPcjIT method testEvaluateTwoIndexThreeVarOrder6ThreeBindingSet.
@Test
public void testEvaluateTwoIndexThreeVarOrder6ThreeBindingSet() throws MalformedQueryException, RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, PcjException, TupleQueryResultHandlerException, QueryEvaluationException, SailException {
final URI sub3 = new URIImpl("uri:entity3");
final URI subclass3 = new URIImpl("uri:class3");
final URI obj3 = new URIImpl("uri:obj3");
final URI superclass = new URIImpl("uri:superclass");
final URI superclass2 = new URIImpl("uri:superclass2");
final URI superclass3 = new URIImpl("uri:superclass3");
conn.add(sub3, RDF.TYPE, subclass3);
conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
conn.add(sub3, talksTo, obj3);
conn.add(subclass, RDF.TYPE, superclass);
conn.add(subclass2, RDF.TYPE, superclass2);
conn.add(subclass3, RDF.TYPE, superclass3);
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
final String indexSparqlString = //
"" + //
"SELECT ?c ?e ?l " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?c ?l ?e ?o ?f " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
"}";
final String queryString = //
"" + //
"SELECT ?e ?c ?l ?f ?o " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
"}";
final CountingResultHandler crh1 = new CountingResultHandler();
final CountingResultHandler crh2 = new CountingResultHandler();
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "c", "e", "l" }, Optional.<PcjVarOrderFactory>absent());
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "c", "l", "e", "o", "f" }, Optional.<PcjVarOrderFactory>absent());
conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh1);
PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix);
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh2);
Assert.assertEquals(3, crh1.getCount());
Assert.assertEquals(3, crh2.getCount());
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class AccumuloIndexSetTest method accumuloIndexSetTestWithDirectProductBindingSet.
@Test
public void accumuloIndexSetTestWithDirectProductBindingSet() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
// Load some Triples into Rya.
final Set<Statement> triples = new HashSet<>();
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
for (final Statement triple : triples) {
ryaConn.add(triple);
}
// Create a PCJ table will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
// Create and populate the PCJ table.
PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs.addBinding("location", new URIImpl("http://Virginia"));
final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bs);
final QueryBindingSet alice = new QueryBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
alice.addAll(bs);
final QueryBindingSet bob = new QueryBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
bob.addAll(bs);
final QueryBindingSet charlie = new QueryBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
charlie.addAll(bs);
final Set<BindingSet> fetchedResults = new HashSet<>();
while (results.hasNext()) {
fetchedResults.add(results.next());
}
Assert.assertEquals(3, fetchedResults.size());
Assert.assertEquals(Sets.<BindingSet>newHashSet(alice, bob, charlie), fetchedResults);
}
use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.
the class AccumuloIndexSetTest method accumuloIndexSetTestWithBindingSet.
/**
* TODO doc
* @throws QueryEvaluationException
* @throws SailException
* @throws MalformedQueryException
* @throws AccumuloSecurityException
* @throws AccumuloException
*/
@Test
public void accumuloIndexSetTestWithBindingSet() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
// Load some Triples into Rya.
final Set<Statement> triples = new HashSet<>();
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
for (final Statement triple : triples) {
ryaConn.add(triple);
}
// Create a PCJ table will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
// Create and populate the PCJ table.
PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("name", new URIImpl("http://Alice"));
bs.addBinding("location", new URIImpl("http://Virginia"));
final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bs);
bs.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
Assert.assertEquals(bs, results.next());
}
Aggregations