use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class AccumuloStatementMetadataOptimizerIT method simpleQueryWithBindingSetJoinPropertyToSubject.
/**
* Tests to see if correct result is passed back when a metadata statement
* is joined with a StatementPattern statement (i.e. a common variable
* appears in a StatementPattern statement and a metadata statement).
* StatementPattern statements have either rdf:subject, rdf:predicate, or
* rdf:object as the predicate while a metadata statement is any statement
* in the reified query whose predicate is not rdf:type and not a
* StatementPattern predicate.
*
* @throws MalformedQueryException
* @throws QueryEvaluationException
* @throws RyaDAOException
*/
@Test
public void simpleQueryWithBindingSetJoinPropertyToSubject() throws Exception {
StatementMetadata metadata1 = new StatementMetadata();
metadata1.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Doug"));
metadata1.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
StatementMetadata metadata2 = new StatementMetadata();
metadata2.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Bob"));
metadata2.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-04"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaURI("http://BurgerShack"), new RyaURI("http://context"), "", metadata1);
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://talksTo"), new RyaURI("http://Betty"), new RyaURI("http://context"), "", metadata1);
RyaStatement statement3 = new RyaStatement(new RyaURI("http://Fred"), new RyaURI("http://talksTo"), new RyaType("http://Amanda"), new RyaURI("http://context"), "", metadata1);
RyaStatement statement4 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://talksTo"), new RyaType("http://Wanda"), new RyaURI("http://context"), "", metadata2);
dao.add(statement1);
dao.add(statement2);
dao.add(statement3);
dao.add(statement4);
TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query2).evaluate();
Set<BindingSet> expected = new HashSet<>();
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("b", new URIImpl("http://Betty"));
expected1.addBinding("a", new URIImpl("http://Joe"));
expected1.addBinding("c", new URIImpl("http://Doug"));
expected.add(expected1);
Set<BindingSet> bsSet = new HashSet<>();
while (result.hasNext()) {
bsSet.add(result.next());
}
Assert.assertEquals(expected, bsSet);
dao.delete(statement1, (AccumuloRdfConfiguration) conf);
dao.delete(statement2, (AccumuloRdfConfiguration) conf);
dao.delete(statement3, (AccumuloRdfConfiguration) conf);
dao.delete(statement4, (AccumuloRdfConfiguration) conf);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class AccumuloConstantPcjIT method testEvaluateThreeIndexVarInstantiate.
@Test
public void testEvaluateThreeIndexVarInstantiate() throws PcjException, RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, MalformedQueryException, SailException, QueryEvaluationException, TupleQueryResultHandlerException {
final URI superclass = new URIImpl("uri:superclass");
final URI superclass2 = new URIImpl("uri:superclass2");
final URI sub = new URIImpl("uri:entity");
subclass = new URIImpl("uri:class");
obj = new URIImpl("uri:obj");
talksTo = new URIImpl("uri:talksTo");
final URI howlsAt = new URIImpl("uri:howlsAt");
final URI subType = new URIImpl("uri:subType");
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(sub, howlsAt, superclass);
conn.add(superclass, subType, obj);
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 . " + //
"}";
final String indexSparqlString3 = //
"" + //
"SELECT ?wolf ?sheep ?chicken " + //
"{" + //
" ?wolf <uri:howlsAt> ?sheep . " + //
" ?sheep <uri:subType> ?chicken. " + //
"}";
final String queryString = //
"" + //
"SELECT ?c ?l ?f ?o " + //
"{" + //
" <uri:entity> a ?c . " + //
" <uri:entity> <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" <uri:entity> <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + //
" ?c a ?f . " + //
" <uri:entity> <uri:howlsAt> ?f. " + //
" ?f <uri:subType> <uri:obj>. " + //
"}";
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "dog", "pig", "duck" }, Optional.<PcjVarOrderFactory>absent());
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "o", "f", "e", "c", "l" }, Optional.<PcjVarOrderFactory>absent());
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 3, indexSparqlString3, new String[] { "wolf", "sheep", "chicken" }, Optional.<PcjVarOrderFactory>absent());
final CountingResultHandler crh1 = new CountingResultHandler();
final CountingResultHandler crh2 = new CountingResultHandler();
conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh1);
PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix);
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh2);
Assert.assertEquals(crh1.getCount(), crh2.getCount());
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PCJOptionalTestIT method init.
@Before
public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, TableNotFoundException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException {
repo = PcjIntegrationTestingUtil.getAccumuloNonPcjRepo(tablePrefix, "instance");
conn = repo.getConnection();
pcjRepo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance");
pcjConn = pcjRepo.getConnection();
sub = new URIImpl("uri:entity");
subclass = new URIImpl("uri:class");
obj = new URIImpl("uri:obj");
talksTo = new URIImpl("uri:talksTo");
conn.add(sub, RDF.TYPE, subclass);
conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
conn.add(sub, talksTo, obj);
sub2 = new URIImpl("uri:entity2");
subclass2 = new URIImpl("uri:class2");
obj2 = new URIImpl("uri:obj2");
sub3 = new URIImpl("uri:entity3");
subclass3 = new URIImpl("uri:class3");
conn.add(sub2, RDF.TYPE, subclass2);
conn.add(sub2, RDFS.LABEL, new LiteralImpl("label2"));
conn.add(sub2, talksTo, obj2);
conn.add(sub3, RDF.TYPE, subclass3);
conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
accCon = new MockInstance("instance").getConnector("root", new PasswordToken(""));
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PrecompJoinOptimizerIT method testEvaluateSingeFilterWithLeftJoin.
@Test
public void testEvaluateSingeFilterWithLeftJoin() throws TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException, PcjException, InferenceEngineException, NumberFormatException, UnknownHostException {
final String indexSparqlString1 = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" Filter(?l = \"label3\") " + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final URI sub3 = new URIImpl("uri:entity3");
final URI subclass3 = new URIImpl("uri:class3");
conn.add(sub3, RDF.TYPE, subclass3);
conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablePrefix + "INDEX_1", indexSparqlString1, new String[] { "e", "l", "c" }, Optional.<PcjVarOrderFactory>absent());
final String queryString = //
"" + //
"SELECT ?e ?c ?o ?m ?l" + //
"{" + //
" Filter(?l = \"label3\") " + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" OPTIONAL { ?e <uri:talksTo> ?o . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?m }" + //
"}";
final CountingResultHandler crh = new CountingResultHandler();
PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, tablePrefix);
PcjIntegrationTestingUtil.closeAndShutdown(conn, repo);
repo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance");
conn = repo.getConnection();
conn.add(sub, talksTo, obj);
conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
Assert.assertEquals(1, crh.getCount());
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PrecompJoinOptimizerIT method init.
@Before
public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, TableNotFoundException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException {
repo = PcjIntegrationTestingUtil.getAccumuloNonPcjRepo(tablePrefix, "instance");
conn = repo.getConnection();
pcjRepo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance");
pcjConn = pcjRepo.getConnection();
sub = new URIImpl("uri:entity");
subclass = new URIImpl("uri:class");
obj = new URIImpl("uri:obj");
talksTo = new URIImpl("uri:talksTo");
conn.add(sub, RDF.TYPE, subclass);
conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
conn.add(sub, talksTo, obj);
sub2 = new URIImpl("uri:entity2");
subclass2 = new URIImpl("uri:class2");
obj2 = new URIImpl("uri:obj2");
conn.add(sub2, RDF.TYPE, subclass2);
conn.add(sub2, RDFS.LABEL, new LiteralImpl("label2"));
conn.add(sub2, talksTo, obj2);
accCon = new MockInstance("instance").getConnector("root", new PasswordToken(""));
}
Aggregations