Search in sources :

Example 11 with URIImpl

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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) TupleQueryResult(org.openrdf.query.TupleQueryResult) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with URIImpl

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());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 13 with URIImpl

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(""));
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) URIImpl(org.openrdf.model.impl.URIImpl) Before(org.junit.Before)

Example 14 with URIImpl

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());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 15 with URIImpl

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(""));
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) URIImpl(org.openrdf.model.impl.URIImpl) Before(org.junit.Before)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)165 Test (org.junit.Test)116 LiteralImpl (org.openrdf.model.impl.LiteralImpl)61 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 Value (org.openrdf.model.Value)21 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16