use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class AccumuloStatementMetadataNodeTest method simpleQueryWithConstantContext.
/**
* 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. Additionally,
* this test also determines whether node uses specified context as a query
* constraint.
*
* @throws MalformedQueryException
* @throws QueryEvaluationException
* @throws RyaDAOException
*/
@Test
public void simpleQueryWithConstantContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query used to create StatementPatternMetadataNode
String contextQuery = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where { graph <http://context_1> {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }}";
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_1"), "", metadata);
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context_2"), "", metadata);
dao.add(statement1);
dao.add(statement2);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(contextQuery, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<AccumuloRdfConfiguration> 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);
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("x", new LiteralImpl("CoffeeShop"));
expected1.addBinding("y", new LiteralImpl("Joe"));
expected1.addBinding("z", new LiteralImpl("Virginia"));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(expected1, bsList.get(0));
dao.delete(statement1, conf);
dao.delete(statement2, conf);
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class AccumuloStatementMetadataNodeTest method simpleQueryWithoutBindingSet.
@Test
public void simpleQueryWithoutBindingSet() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
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());
// RyaQueryEngine<RdfCloudTripleStoreConfiguration> engine =
// (RyaQueryEngine<>) dao.getQueryEngine();
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);
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class MongoStatementMetadataIT 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 {
Sail sail = RyaSailFactory.getInstance(conf);
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final 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"));
final RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
final TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
final List<BindingSet> bsList = new ArrayList<>();
while (result.hasNext()) {
bsList.add(result.next());
}
assertEquals(0, bsList.size());
dao.delete(statement, conf);
} finally {
dao.destroy();
sail.shutDown();
}
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class MongoStatementMetadataIT method simpleQueryWithoutBindingSet.
@Test
public void simpleQueryWithoutBindingSet() throws Exception {
Sail sail = RyaSailFactory.getInstance(conf);
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final 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"));
final RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
final TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query1).evaluate();
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", new LiteralImpl("CoffeeShop"));
bs.addBinding("y", new LiteralImpl("Joe"));
final List<BindingSet> bsList = new ArrayList<>();
while (result.hasNext()) {
bsList.add(result.next());
}
assertEquals(1, bsList.size());
assertEquals(bs, bsList.get(0));
dao.delete(statement, conf);
} finally {
dao.destroy();
sail.shutDown();
}
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class MongoStatementMetadataIT 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 {
Sail sail = RyaSailFactory.getInstance(conf);
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final 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"));
final 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"));
final RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaURI("http://BurgerShack"), new RyaURI("http://context"), "", metadata1);
final RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://talksTo"), new RyaURI("http://Betty"), new RyaURI("http://context"), "", metadata1);
final RyaStatement statement3 = new RyaStatement(new RyaURI("http://Fred"), new RyaURI("http://talksTo"), new RyaURI("http://Amanda"), new RyaURI("http://context"), "", metadata1);
final RyaStatement statement4 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://talksTo"), new RyaURI("http://Wanda"), new RyaURI("http://context"), "", metadata2);
dao.add(statement1);
dao.add(statement2);
dao.add(statement3);
dao.add(statement4);
SailRepositoryConnection conn = new SailRepository(sail).getConnection();
final TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query2).evaluate();
final Set<BindingSet> expected = new HashSet<>();
final 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);
final Set<BindingSet> bsSet = new HashSet<>();
while (result.hasNext()) {
bsSet.add(result.next());
}
assertEquals(expected, bsSet);
dao.delete(statement1, conf);
dao.delete(statement2, conf);
dao.delete(statement3, conf);
dao.delete(statement4, conf);
} finally {
dao.destroy();
sail.shutDown();
}
}
Aggregations