Search in sources :

Example 91 with LiteralImpl

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

the class MongoPcjIntegrationTest method testEvaluateOneIndex.

@Test
public void testEvaluateOneIndex() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        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"));
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final CountingResultHandler crh1 = new CountingResultHandler();
        final CountingResultHandler crh2 = new CountingResultHandler();
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh1);
        PcjIntegrationTestingUtil.deleteCoreRyaTables(getMongoClient(), conf.getRyaInstanceName(), conf.getTriplesCollectionName());
        pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh2);
        assertEquals(crh1.count, crh2.count);
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) URIImpl(org.openrdf.model.impl.URIImpl) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 92 with LiteralImpl

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

the class MongoStatementMetadataNodeIT 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.
 */
@Test
public void simpleQueryWithBindingSetJoinPropertyToSubject() throws Exception {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        StatementMetadata metadata = new StatementMetadata();
        metadata.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Joe"));
        metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
        RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
        RyaStatement statement2 = new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
        dao.add(statement1);
        dao.add(statement2);
        SPARQLParser parser = new SPARQLParser();
        ParsedQuery pq = parser.parseQuery(query2, null);
        List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
        StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
        List<BindingSet> bsCollection = new ArrayList<>();
        QueryBindingSet bsConstraint1 = new QueryBindingSet();
        bsConstraint1.addBinding("y", new LiteralImpl("CoffeeShop"));
        bsConstraint1.addBinding("z", new LiteralImpl("Virginia"));
        QueryBindingSet bsConstraint2 = new QueryBindingSet();
        bsConstraint2.addBinding("y", new LiteralImpl("HardwareStore"));
        bsConstraint2.addBinding("z", new LiteralImpl("Maryland"));
        bsCollection.add(bsConstraint1);
        bsCollection.add(bsConstraint2);
        CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection);
        QueryBindingSet expected = new QueryBindingSet();
        expected.addBinding("y", new LiteralImpl("CoffeeShop"));
        expected.addBinding("x", new URIImpl("http://Joe"));
        expected.addBinding("z", new LiteralImpl("Virginia"));
        List<BindingSet> bsList = new ArrayList<>();
        while (iteration.hasNext()) {
            bsList.add(iteration.next());
        }
        Assert.assertEquals(1, bsList.size());
        Assert.assertEquals(expected, bsList.get(0));
        dao.delete(statement1, conf);
        dao.delete(statement2, 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) URIImpl(org.openrdf.model.impl.URIImpl) 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) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) Test(org.junit.Test)

Example 93 with LiteralImpl

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

the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSetCollection.

/**
 * Tests if StatementMetadataNode joins BindingSet values correctly for
 * variables appearing as the object in one of the StatementPattern
 * statements (in the case ?x appears as the Object in the statement
 * _:blankNode rdf:object ?x). StatementPattern statements have either
 * rdf:subject, rdf:predicate, or rdf:object as the predicate.
 */
@Test
public void simpleQueryWithBindingSetCollection() 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 statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
        RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
        dao.add(statement1);
        dao.add(statement2);
        SPARQLParser parser = new SPARQLParser();
        ParsedQuery pq = parser.parseQuery(query, null);
        List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
        StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
        List<BindingSet> bsCollection = new ArrayList<>();
        QueryBindingSet bsConstraint1 = new QueryBindingSet();
        bsConstraint1.addBinding("x", new LiteralImpl("CoffeeShop"));
        bsConstraint1.addBinding("z", new LiteralImpl("Virginia"));
        QueryBindingSet bsConstraint2 = new QueryBindingSet();
        bsConstraint2.addBinding("x", new LiteralImpl("HardwareStore"));
        bsConstraint2.addBinding("z", new LiteralImpl("Maryland"));
        QueryBindingSet bsConstraint3 = new QueryBindingSet();
        bsConstraint3.addBinding("x", new LiteralImpl("BurgerShack"));
        bsConstraint3.addBinding("z", new LiteralImpl("Delaware"));
        bsCollection.add(bsConstraint1);
        bsCollection.add(bsConstraint2);
        bsCollection.add(bsConstraint3);
        CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection);
        Set<BindingSet> expected = new HashSet<>();
        QueryBindingSet expected1 = new QueryBindingSet();
        expected1.addBinding("x", new LiteralImpl("CoffeeShop"));
        expected1.addBinding("y", new LiteralImpl("Joe"));
        expected1.addBinding("z", new LiteralImpl("Virginia"));
        QueryBindingSet expected2 = new QueryBindingSet();
        expected2.addBinding("x", new LiteralImpl("HardwareStore"));
        expected2.addBinding("y", new LiteralImpl("Joe"));
        expected2.addBinding("z", new LiteralImpl("Maryland"));
        expected.add(expected1);
        expected.add(expected2);
        Set<BindingSet> bsSet = new HashSet<>();
        while (iteration.hasNext()) {
            bsSet.add(iteration.next());
        }
        Assert.assertEquals(expected, bsSet);
        dao.delete(statement1, conf);
        dao.delete(statement2, 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) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 94 with LiteralImpl

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

the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSet.

@Test
public void simpleQueryWithBindingSet() 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 statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
        RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
        dao.add(statement1);
        dao.add(statement2);
        SPARQLParser parser = new SPARQLParser();
        ParsedQuery pq = parser.parseQuery(query, null);
        List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
        StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
        QueryBindingSet bsConstraint = new QueryBindingSet();
        bsConstraint.addBinding("x", new LiteralImpl("CoffeeShop"));
        bsConstraint.addBinding("z", new LiteralImpl("Virginia"));
        CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
        QueryBindingSet expected = new QueryBindingSet();
        expected.addBinding("x", new LiteralImpl("CoffeeShop"));
        expected.addBinding("y", new LiteralImpl("Joe"));
        expected.addBinding("z", new LiteralImpl("Virginia"));
        List<BindingSet> bsList = new ArrayList<>();
        while (iteration.hasNext()) {
            bsList.add(iteration.next());
        }
        Assert.assertEquals(1, bsList.size());
        Assert.assertEquals(expected, bsList.get(0));
        dao.delete(statement1, conf);
        dao.delete(statement2, 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) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) Test(org.junit.Test)

Example 95 with LiteralImpl

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

the class PcjTablesIT method createAndPopulatePcj.

/**
 * Ensure the method that creates a new PCJ table, scans Rya for matches, and
 * stores them in the PCJ table works.
 * <p>
 * The method being tested is: {@link PcjTables#createAndPopulatePcj(RepositoryConnection, Connector, String, String, String[], Optional)}
 */
@Test
public void createAndPopulatePcj() throws RepositoryException, PcjException, TableNotFoundException, BindingSetConversionException, 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 that 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 Connector accumuloConn = cluster.getConnector();
    final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), "testPcj");
    // Create and populate the PCJ table.
    final PcjTables pcjs = new PcjTables();
    pcjs.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
    // Make sure the cardinality was updated.
    final PcjMetadata metadata = pcjs.getPcjMetadata(accumuloConn, pcjTableName);
    assertEquals(3, metadata.getCardinality());
    // Scan Accumulo for the stored results.
    final Multimap<String, BindingSet> fetchedResults = loadPcjResults(accumuloConn, pcjTableName);
    // Ensure the expected results match those that were stored.
    final MapBindingSet alice = new MapBindingSet();
    alice.addBinding("name", new URIImpl("http://Alice"));
    alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final MapBindingSet bob = new MapBindingSet();
    bob.addBinding("name", new URIImpl("http://Bob"));
    bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    final MapBindingSet charlie = new MapBindingSet();
    charlie.addBinding("name", new URIImpl("http://Charlie"));
    charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
    final Set<BindingSet> results = Sets.<BindingSet>newHashSet(alice, bob, charlie);
    final Multimap<String, BindingSet> expectedResults = HashMultimap.create();
    expectedResults.putAll("name;age", results);
    expectedResults.putAll("age;name", results);
    assertEquals(expectedResults, fetchedResults);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

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