use of org.openrdf.model.ValueFactory in project incubator-rya by apache.
the class StatementPatternMatcherTest method variableContext.
@Test
public void variableContext() throws Exception {
// Create a matcher against a pattern that matches a variable context.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "GRAPH ?c {" + "?s ?p ?o ." + "}" + "}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("s", vf.createURI("urn:Alice"));
expected.addBinding("p", vf.createURI("urn:talksTo"));
expected.addBinding("o", vf.createURI("urn:Bob"));
expected.addBinding("c", vf.createURI("urn:testGraph"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
use of org.openrdf.model.ValueFactory in project incubator-rya by apache.
the class StatementPatternMatcherTest method variableContext_contextFreeStatement.
@Test
public void variableContext_contextFreeStatement() throws Exception {
// Create a matcher against a pattern that matches a variable context.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "GRAPH ?c {" + "?s ?p ?o ." + "}" + "}"));
// Create a statement that does not have a context value.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
// Show the statement did not match.
final Optional<BindingSet> bs = matcher.match(statement);
assertFalse(bs.isPresent());
}
use of org.openrdf.model.ValueFactory in project incubator-rya by apache.
the class StatementPatternMatcherTest method doesNotMatchObject.
@Test
public void doesNotMatchObject() throws Exception {
// Create the matcher against a pattern that matches a specific object.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "?s ?p <urn:Bob> ." + "}"));
// Create a statement that does not match the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:knows"), vf.createURI("urn:Alice"), vf.createURI("urn:testGraph"));
// Show the statement did not match.
final Optional<BindingSet> bs = matcher.match(statement);
assertFalse(bs.isPresent());
}
use of org.openrdf.model.ValueFactory in project incubator-rya by apache.
the class StatementPatternMatcherTest method matchesSubject.
@Test
public void matchesSubject() throws Exception {
// Create the matcher against a pattern that matches a specific subject.
final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "<urn:Alice> ?p ?o ." + "}"));
// Create a statement that matches the pattern.
final ValueFactory vf = new ValueFactoryImpl();
final Statement statement = vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"), vf.createURI("urn:testGraph"));
// Create the expected resulting Binding Set.
final QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("p", vf.createURI("urn:talksTo"));
expected.addBinding("o", vf.createURI("urn:Bob"));
// Show the expected Binding Set matches the resulting Binding Set.
final Optional<BindingSet> bs = matcher.match(statement);
assertEquals(expected, bs.get());
}
use of org.openrdf.model.ValueFactory in project incubator-rya by apache.
the class MongoFreeTextIndexerIT method testSearch.
@Test
public void testSearch() throws Exception {
try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
f.setConf(conf);
f.init();
final ValueFactory vf = new ValueFactoryImpl();
final URI subject = new URIImpl("foo:subj");
final URI predicate = RDFS.LABEL;
final Value object = vf.createLiteral("this is a new hat");
final URI context = new URIImpl("foo:context");
final Statement statement = vf.createStatement(subject, predicate, object, context);
f.storeStatement(RdfToRyaConversions.convertStatement(statement));
f.flush();
assertEquals(Sets.newHashSet(), getSet(f.queryText("asdf", EMPTY_CONSTRAINTS)));
assertEquals(Sets.newHashSet(statement), getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat new", EMPTY_CONSTRAINTS)));
}
}
Aggregations