Search in sources :

Example 11 with LiteralImpl

use of org.openrdf.model.impl.LiteralImpl in project incubator-rya by apache.

the class MongoStatementMetadataNodeIT method simpleQueryWithoutBindingSet.

@Test
public void simpleQueryWithoutBindingSet() throws Exception {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        StatementMetadata metadata = new StatementMetadata();
        metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
        metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
        RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
        dao.add(statement);
        SPARQLParser parser = new SPARQLParser();
        ParsedQuery pq = parser.parseQuery(query, null);
        List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
        StatementMetadataNode<?> node = new StatementMetadataNode<>(spList, conf);
        CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(new QueryBindingSet());
        QueryBindingSet bs = new QueryBindingSet();
        bs.addBinding("x", new LiteralImpl("CoffeeShop"));
        bs.addBinding("y", new LiteralImpl("Joe"));
        List<BindingSet> bsList = new ArrayList<>();
        while (iteration.hasNext()) {
            bsList.add(iteration.next());
        }
        Assert.assertEquals(1, bsList.size());
        Assert.assertEquals(bs, bsList.get(0));
        dao.delete(statement, conf);
    } finally {
        dao.destroy();
    }
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) MongoDBRyaDAO(org.apache.rya.mongodb.MongoDBRyaDAO) RyaURI(org.apache.rya.api.domain.RyaURI) StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Example 12 with LiteralImpl

use of org.openrdf.model.impl.LiteralImpl 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 LiteralImpl

use of org.openrdf.model.impl.LiteralImpl 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 LiteralImpl

use of org.openrdf.model.impl.LiteralImpl 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 LiteralImpl

use of org.openrdf.model.impl.LiteralImpl 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

LiteralImpl (org.openrdf.model.impl.LiteralImpl)155 Test (org.junit.Test)124 URIImpl (org.openrdf.model.impl.URIImpl)62 BindingSet (org.openrdf.query.BindingSet)58 Statement (org.openrdf.model.Statement)40 ArrayList (java.util.ArrayList)34 TupleQueryResult (org.openrdf.query.TupleQueryResult)34 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)33 URI (org.openrdf.model.URI)29 IntegerLiteralImpl (org.openrdf.model.impl.IntegerLiteralImpl)23 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)22 HashSet (java.util.HashSet)21 RyaStatement (org.apache.rya.api.domain.RyaStatement)19 RyaType (org.apache.rya.api.domain.RyaType)19 RyaURI (org.apache.rya.api.domain.RyaURI)19 ParsedQuery (org.openrdf.query.parser.ParsedQuery)19 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)19 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)17 StatementImpl (org.openrdf.model.impl.StatementImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15