Search in sources :

Example 41 with ValueFactory

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());
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 42 with ValueFactory

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());
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 43 with ValueFactory

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());
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 44 with ValueFactory

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());
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 45 with ValueFactory

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)));
    }
}
Also used : Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) URIImpl(org.openrdf.model.impl.URIImpl) ValueFactory(org.openrdf.model.ValueFactory) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Aggregations

ValueFactory (org.openrdf.model.ValueFactory)230 Test (org.junit.Test)195 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)187 Statement (org.openrdf.model.Statement)114 MapBindingSet (org.openrdf.query.impl.MapBindingSet)99 URI (org.openrdf.model.URI)83 HashSet (java.util.HashSet)72 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)66 Value (org.openrdf.model.Value)57 BindingSet (org.openrdf.query.BindingSet)51 Resource (org.openrdf.model.Resource)39 ArrayList (java.util.ArrayList)35 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)35 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)34 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)33 UUID (java.util.UUID)29 StatementImpl (org.openrdf.model.impl.StatementImpl)27 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)25 LinearRing (com.vividsolutions.jts.geom.LinearRing)24 Polygon (com.vividsolutions.jts.geom.Polygon)24