Search in sources :

Example 1 with StatementMetadata

use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.

the class AccumuloStatementMetadataOptimizerIT method simpleQueryWithBindingSet.

@Test
public void simpleQueryWithBindingSet() throws Exception {
    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);
    TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
    Set<BindingSet> expected = new HashSet<>();
    QueryBindingSet expected1 = new QueryBindingSet();
    expected1.addBinding("x", new LiteralImpl("CoffeeShop"));
    expected1.addBinding("y", new LiteralImpl("Joe"));
    QueryBindingSet expected2 = new QueryBindingSet();
    expected2.addBinding("x", new LiteralImpl("HardwareStore"));
    expected2.addBinding("y", new LiteralImpl("Joe"));
    expected.add(expected1);
    expected.add(expected2);
    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);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) 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 2 with StatementMetadata

use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.

the class AccumuloStatementMetadataOptimizerIT method simpleQueryWithoutBindingSetInvalidProperty.

/**
 * Tests if results are filtered correctly using the metadata properties. In
 * this case, the date for the ingested RyaStatement differs from the date
 * specified in the query.
 *
 * @throws MalformedQueryException
 * @throws QueryEvaluationException
 * @throws RyaDAOException
 */
@Test
public void simpleQueryWithoutBindingSetInvalidProperty() throws Exception {
    StatementMetadata metadata = new StatementMetadata();
    metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Doug"));
    metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-15"));
    RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
    dao.add(statement);
    TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
    List<BindingSet> bsList = new ArrayList<>();
    while (result.hasNext()) {
        bsList.add(result.next());
    }
    Assert.assertEquals(0, bsList.size());
    dao.delete(statement, (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) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) TupleQueryResult(org.openrdf.query.TupleQueryResult) Test(org.junit.Test)

Example 3 with StatementMetadata

use of org.apache.rya.api.domain.StatementMetadata 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 4 with StatementMetadata

use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.

the class AccumuloStatementMetadataOptimizerIT method simpleQueryWithoutBindingSet.

@Test
public void simpleQueryWithoutBindingSet() throws Exception {
    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);
    TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", new LiteralImpl("CoffeeShop"));
    bs.addBinding("y", new LiteralImpl("Joe"));
    List<BindingSet> bsList = new ArrayList<>();
    while (result.hasNext()) {
        bsList.add(result.next());
    }
    System.out.println(bsList);
    Assert.assertEquals(1, bsList.size());
    Assert.assertEquals(bs, bsList.get(0));
    dao.delete(statement, (AccumuloRdfConfiguration) conf);
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) 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) TupleQueryResult(org.openrdf.query.TupleQueryResult) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 5 with StatementMetadata

use of org.apache.rya.api.domain.StatementMetadata in project incubator-rya by apache.

the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSetJoinOnProperty.

/**
 * Tests if the StatementMetadataNode joins BindingSet correctly for
 * variables appearing in metadata statements. In this case, the metadata
 * statements are (_:blankNode <http://createdOn 2017-01-04 ) and
 * (_:blankNode <http://createdBy> ?y). The variable ?y appears as the
 * object in the above metadata statement and its values are joined to the
 * constraint BindingSets in the example below.
 */
@Test
public void simpleQueryWithBindingSetJoinOnProperty() 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);
        dao.add(statement1);
        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("y", new LiteralImpl("Doug"));
        CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
        List<BindingSet> bsList = new ArrayList<>();
        while (iteration.hasNext()) {
            bsList.add(iteration.next());
        }
        Assert.assertEquals(0, bsList.size());
        dao.delete(statement1, 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)

Aggregations

StatementMetadata (org.apache.rya.api.domain.StatementMetadata)37 RyaStatement (org.apache.rya.api.domain.RyaStatement)36 RyaURI (org.apache.rya.api.domain.RyaURI)35 RyaType (org.apache.rya.api.domain.RyaType)34 Test (org.junit.Test)30 BindingSet (org.openrdf.query.BindingSet)28 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)28 ArrayList (java.util.ArrayList)25 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)20 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 ParsedQuery (org.openrdf.query.parser.ParsedQuery)20 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)20 LiteralImpl (org.openrdf.model.impl.LiteralImpl)17 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)15 URIImpl (org.openrdf.model.impl.URIImpl)11 MongoDBRyaDAO (org.apache.rya.mongodb.MongoDBRyaDAO)10 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)8 TupleQueryResult (org.openrdf.query.TupleQueryResult)8 HashSet (java.util.HashSet)7 MongoDBRdfConfiguration (org.apache.rya.mongodb.MongoDBRdfConfiguration)5