use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithBindingSetConstantContext.
@Test
public void simpleQueryWithBindingSetConstantContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph <uri:context1> {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("x", new URIImpl("uri:Doug"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("x", new URIImpl("uri:Doug"));
Assert.assertEquals(expected, bsList.get(0));
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithBindingSets.
@Test
public void simpleQueryWithBindingSets() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph ?c {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Eric"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context3"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("c", new URIImpl("uri:context2"));
QueryBindingSet bsConstraint2 = new QueryBindingSet();
bsConstraint2.addBinding("c", new URIImpl("uri:context1"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1, bsConstraint2));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(2, bsList.size());
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("x", new URIImpl("uri:Joe"));
expected1.addBinding("c", new URIImpl("uri:context1"));
QueryBindingSet expected2 = new QueryBindingSet();
expected2.addBinding("x", new URIImpl("uri:Doug"));
expected2.addBinding("c", new URIImpl("uri:context2"));
Set<BindingSet> expected = new HashSet<>(Arrays.asList(expected1, expected2));
Set<BindingSet> actual = new HashSet<>(bsList);
Assert.assertEquals(expected, actual);
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class RdfFileInputFormatTest method testStatementInput.
@Test
public void testStatementInput() throws Exception {
RdfFileInputFormat.setRDFFormat(job, RDFFormat.NTRIPLES);
init(NT_INPUT);
String prefix = "urn:lubm:rdfts#";
URI[] gs = { new URIImpl(prefix + "GraduateStudent01"), new URIImpl(prefix + "GraduateStudent02"), new URIImpl(prefix + "GraduateStudent03"), new URIImpl(prefix + "GraduateStudent04") };
URI hasFriend = new URIImpl(prefix + "hasFriend");
Statement[] statements = { new StatementImpl(gs[0], hasFriend, gs[1]), new StatementImpl(gs[1], hasFriend, gs[2]), new StatementImpl(gs[2], hasFriend, gs[3]) };
int count = 0;
while (reader.nextKeyValue()) {
Assert.assertEquals(statements[count], RyaToRdfConversions.convertStatement(reader.getCurrentValue().getRyaStatement()));
count++;
Assert.assertEquals(count, reader.getCurrentKey().get());
}
Assert.assertEquals(3, count);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class FluoStringConverterTest method stringToStatementPattern.
@Test
public void stringToStatementPattern() {
// Setup the String representation of a statement pattern.
final String patternString = "x:::" + "-const-http://worksAt<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + "-const-http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI";
// Convert it to a StatementPattern.
final StatementPattern statementPattern = FluoStringConverter.toStatementPattern(patternString);
// Enusre it converted to the expected result.
final Var subject = new Var("x");
final Var predicate = new Var("-const-http://worksAt", new URIImpl("http://worksAt"));
predicate.setConstant(true);
final Var object = new Var("-const-http://Chipotle", new URIImpl("http://Chipotle"));
object.setConstant(true);
final StatementPattern expected = new StatementPattern(subject, predicate, object);
assertEquals(expected, statementPattern);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class FluoStringConverterTest method toVar_uri.
@Test
public void toVar_uri() {
// Setup the string representation of the variable.
final String varString = "-const-http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI";
// Convert it to a Var object.
final Var var = FluoStringConverter.toVar(varString);
// Ensure it converted to the expected result.
final Var expected = new Var("-const-http://Chipotle", new URIImpl("http://Chipotle"));
expected.setConstant(true);
assertEquals(expected, var);
}
Aggregations