Search in sources :

Example 36 with ValueFactory

use of org.openrdf.model.ValueFactory in project incubator-rya by apache.

the class JoinProcessorIT method manyJoins.

@Test
public void manyJoins() throws Exception {
    // Enumerate some topics that will be re-used
    final String ryaInstance = UUID.randomUUID().toString();
    final UUID queryId = UUID.randomUUID();
    final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
    final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
    // Setup a topology.
    final String query = "SELECT * WHERE { " + "?person <urn:talksTo> ?employee ." + "?employee <urn:worksAt> ?business ." + "?employee <urn:hourlyWage> ?wage ." + " }";
    final TopologyFactory factory = new TopologyFactory();
    final TopologyBuilder builder = factory.build(query, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Create some statements that generate a bunch of right SP results.
    final ValueFactory vf = new ValueFactoryImpl();
    final List<VisibilityStatement> statements = new ArrayList<>();
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob")), "a"));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:worksAt"), vf.createURI("urn:BurgerJoint")), "a"));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:hourlyWage"), vf.createLiteral(7.25)), "a"));
    // Make the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("person", vf.createURI("urn:Alice"));
    bs.addBinding("employee", vf.createURI("urn:Bob"));
    bs.addBinding("business", vf.createURI("urn:BurgerJoint"));
    bs.addBinding("wage", vf.createLiteral(7.25));
    expected.add(new VisibilityBindingSet(bs, "a"));
    // Run the test.
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) TopologyFactory(org.apache.rya.streams.kafka.topology.TopologyFactory) ValueFactory(org.openrdf.model.ValueFactory) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with ValueFactory

use of org.openrdf.model.ValueFactory in project incubator-rya by apache.

the class ProjectionProcessorIT method showProcessorWorks.

@Test
public void showProcessorWorks() throws Exception {
    // Enumerate some topics that will be re-used
    final String ryaInstance = UUID.randomUUID().toString();
    final UUID queryId = UUID.randomUUID();
    final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
    final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
    // Create a topology for the Query that will be tested.
    final String sparql = "SELECT (?person AS ?p) ?otherPerson " + "WHERE { " + "?person <urn:talksTo> ?otherPerson . " + "}";
    final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Load some data into the input topic.
    final ValueFactory vf = new ValueFactoryImpl();
    final List<VisibilityStatement> statements = new ArrayList<>();
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob")), "a"));
    // Show the correct binding set results from the job.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    final MapBindingSet expectedBs = new MapBindingSet();
    expectedBs.addBinding("p", vf.createURI("urn:Alice"));
    expectedBs.addBinding("otherPerson", vf.createURI("urn:Bob"));
    expected.add(new VisibilityBindingSet(expectedBs, "a"));
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, Sets.newHashSet(expected), VisibilityBindingSetDeserializer.class);
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) TopologyBuilder(org.apache.kafka.streams.processor.TopologyBuilder) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ArrayList(java.util.ArrayList) TopologyFactory(org.apache.rya.streams.kafka.topology.TopologyFactory) ValueFactory(org.openrdf.model.ValueFactory) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with ValueFactory

use of org.openrdf.model.ValueFactory in project incubator-rya by apache.

the class StatementPatternMatcherTest method matchesContext.

@Test
public void matchesContext() throws Exception {
    // Create a matcher against a pattern that matches a specific context.
    final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "GRAPH <urn:testGraph> {" + "?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"));
    // 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 39 with ValueFactory

use of org.openrdf.model.ValueFactory in project incubator-rya by apache.

the class StatementPatternMatcherTest method doesNotMatchPredicate.

@Test
public void doesNotMatchPredicate() throws Exception {
    // Create the matcher against a pattern that matches a specific predicate.
    final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "?s <urn:talksTo> ?o ." + "}"));
    // 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:Bob"), 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 40 with ValueFactory

use of org.openrdf.model.ValueFactory in project incubator-rya by apache.

the class StatementPatternMatcherTest method doesNotMatchContext.

@Test
public void doesNotMatchContext() throws Exception {
    // Create a matcher against a pattern that matches a specific context.
    final StatementPatternMatcher matcher = new StatementPatternMatcher(getSp("SELECT * WHERE {" + "GRAPH <urn:testGraph> {" + "?s ?p ?o ." + "}" + "}"));
    // Create a statement that does not match 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:wrong"));
    // 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)

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