Search in sources :

Example 16 with ValueFactoryImpl

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

the class TemporalFilterIT method showAfterWorks.

@Test
public void showAfterWorks() 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);
    // Get the RDF model objects that will be used to build the query.
    final String sparql = "PREFIX time: <http://www.w3.org/2006/time/> \n" + "PREFIX tempf: <" + TemporalURIs.NAMESPACE + ">\n" + "SELECT * \n" + "WHERE { \n" + "  <urn:time> time:atTime ?date .\n" + " FILTER(tempf:after(?date, \"" + TIME_10.toString() + "\")) " + "}";
    // Setup a topology.
    final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Create the statements that will be input into the query.
    final ValueFactory vf = new ValueFactoryImpl();
    final List<VisibilityStatement> statements = getStatements();
    // Make the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    final MapBindingSet bs = new MapBindingSet();
    bs.addBinding("date", vf.createLiteral(TIME_20.toString()));
    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) 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 17 with ValueFactoryImpl

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

the class StatementPatternProcessorIT method singlePattern_manyStatements.

@Test
public void singlePattern_manyStatements() 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> ?otherPerson }";
    final TopologyFactory factory = new TopologyFactory();
    final TopologyBuilder builder = factory.build(query, statementsTopic, resultsTopic, new RandomUUIDFactory());
    // Create some statements where some generates SP results and others do not.
    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:Alice"), vf.createURI("urn:worksAt"), vf.createURI("urn:TacoJoin")), "b"));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:talksTo"), vf.createURI("urn:Alice")), "a|b"));
    statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:worksAt"), vf.createURI("urn:BurgerJoint")), "c"));
    // Show the correct binding set results from the job.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("person", vf.createURI("urn:Alice"));
    bs.addBinding("otherPerson", vf.createURI("urn:Bob"));
    expected.add(new VisibilityBindingSet(bs, "a"));
    bs = new QueryBindingSet();
    bs.addBinding("person", vf.createURI("urn:Bob"));
    bs.addBinding("otherPerson", vf.createURI("urn:Alice"));
    expected.add(new VisibilityBindingSet(bs, "a|b"));
    // 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) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) RandomUUIDFactory(org.apache.rya.api.function.projection.RandomUUIDFactory) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with ValueFactoryImpl

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

the class BindingSetOutputFormatterTest method binaryResult.

@Test
public void binaryResult() {
    // Create the input binding set.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bindingSet = new MapBindingSet();
    bindingSet.addBinding("person", vf.createURI("urn:Alice"));
    bindingSet.addBinding("age", vf.createLiteral(34));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final BindingSetOutputFormatter formatter = new BindingSetOutputFormatter();
    formatter.init(context);
    formatter.process("key", ProcessorResult.make(new BinaryResult(Side.LEFT, visBs)));
    // Verify the mock was invoked with the expected output.
    verify(context, times(1)).forward(eq("key"), eq(visBs));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) BindingSetOutputFormatter(org.apache.rya.streams.kafka.processors.output.BindingSetOutputFormatterSupplier.BindingSetOutputFormatter) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) BinaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.BinaryResult) Test(org.junit.Test)

Example 19 with ValueFactoryImpl

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

the class BindingSetOutputFormatterTest method unaryResult.

@Test
public void unaryResult() {
    // Create the input binding set.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet bindingSet = new MapBindingSet();
    bindingSet.addBinding("person", vf.createURI("urn:Alice"));
    bindingSet.addBinding("age", vf.createLiteral(34));
    final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final BindingSetOutputFormatter formatter = new BindingSetOutputFormatter();
    formatter.init(context);
    formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
    // Verify the mock was invoked with the expected output.
    verify(context, times(1)).forward(eq("key"), eq(visBs));
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) BindingSetOutputFormatter(org.apache.rya.streams.kafka.processors.output.BindingSetOutputFormatterSupplier.BindingSetOutputFormatter) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) ValueFactory(org.openrdf.model.ValueFactory) MapBindingSet(org.openrdf.query.impl.MapBindingSet) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) Test(org.junit.Test)

Example 20 with ValueFactoryImpl

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

the class MultiProjectionProcessorTest method showProjectionFunctionIsCalled.

@Test
public void showProjectionFunctionIsCalled() throws Exception {
    // The SPARQL that will define the projection.
    final MultiProjection multiProjection = RdfTestUtil.getMultiProjection("CONSTRUCT {" + "_:b a <urn:movementObservation> ; " + "<urn:location> ?location ; " + "<urn:direction> ?direction ; " + "}" + "WHERE {" + "?thing <urn:corner> ?location ." + "?thing <urn:compass> ?direction." + "}");
    // Create a Binding Set that contains the result of the WHERE clause.
    final ValueFactory vf = new ValueFactoryImpl();
    final MapBindingSet inputBs = new MapBindingSet();
    inputBs.addBinding("location", vf.createURI("urn:corner1"));
    inputBs.addBinding("direction", vf.createURI("urn:NW"));
    final VisibilityBindingSet inputVisBs = new VisibilityBindingSet(inputBs, "a|b");
    // Make the expected results.
    final Set<VisibilityBindingSet> expected = new HashSet<>();
    final String blankNodeId = UUID.randomUUID().toString();
    final BNode blankNode = vf.createBNode(blankNodeId);
    MapBindingSet expectedBs = new MapBindingSet();
    expectedBs.addBinding("subject", blankNode);
    expectedBs.addBinding("predicate", RDF.TYPE);
    expectedBs.addBinding("object", vf.createURI("urn:movementObservation"));
    expected.add(new VisibilityBindingSet(expectedBs, "a|b"));
    expectedBs = new MapBindingSet();
    expectedBs.addBinding("subject", blankNode);
    expectedBs.addBinding("predicate", vf.createURI("urn:direction"));
    expectedBs.addBinding("object", vf.createURI("urn:NW"));
    expected.add(new VisibilityBindingSet(expectedBs, "a|b"));
    expectedBs = new MapBindingSet();
    expectedBs.addBinding("subject", blankNode);
    expectedBs.addBinding("predicate", vf.createURI("urn:location"));
    expectedBs.addBinding("object", vf.createURI("urn:corner1"));
    expected.add(new VisibilityBindingSet(expectedBs, "a|b"));
    // Mock the processor context that will be invoked.
    final ProcessorContext context = mock(ProcessorContext.class);
    // Run the test.
    final MultiProjectionProcessor processor = new MultiProjectionProcessor(MultiProjectionEvaluator.make(multiProjection, () -> blankNodeId), result -> ProcessorResult.make(new UnaryResult(result)));
    processor.init(context);
    processor.process("key", ProcessorResult.make(new UnaryResult(inputVisBs)));
    final ArgumentCaptor<ProcessorResult> results = ArgumentCaptor.forClass(ProcessorResult.class);
    verify(context, times(3)).forward(any(), results.capture());
    final Set<VisibilityBindingSet> resultBindingSets = results.getAllValues().stream().map(result -> {
        return (result.getType() == ResultType.UNARY) ? result.getUnary().getResult() : result.getBinary().getResult();
    }).collect(Collectors.toSet());
    assertEquals(expected, resultBindingSets);
}
Also used : ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) MapBindingSet(org.openrdf.query.impl.MapBindingSet) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) ResultType(org.apache.rya.streams.kafka.processors.ProcessorResult.ResultType) MultiProjectionProcessor(org.apache.rya.streams.kafka.processors.projection.MultiProjectionProcessorSupplier.MultiProjectionProcessor) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) RDF(org.openrdf.model.vocabulary.RDF) ProcessorResult(org.apache.rya.streams.kafka.processors.ProcessorResult) MultiProjection(org.openrdf.query.algebra.MultiProjection) ValueFactory(org.openrdf.model.ValueFactory) RdfTestUtil(org.apache.rya.streams.kafka.RdfTestUtil) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) BNode(org.openrdf.model.BNode) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) MultiProjectionEvaluator(org.apache.rya.api.function.projection.MultiProjectionEvaluator) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BNode(org.openrdf.model.BNode) ProcessorResult(org.apache.rya.streams.kafka.processors.ProcessorResult) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) MultiProjectionProcessor(org.apache.rya.streams.kafka.processors.projection.MultiProjectionProcessorSupplier.MultiProjectionProcessor) UnaryResult(org.apache.rya.streams.kafka.processors.ProcessorResult.UnaryResult) MapBindingSet(org.openrdf.query.impl.MapBindingSet) MultiProjection(org.openrdf.query.algebra.MultiProjection) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)190 ValueFactory (org.openrdf.model.ValueFactory)187 Test (org.junit.Test)174 Statement (org.openrdf.model.Statement)106 MapBindingSet (org.openrdf.query.impl.MapBindingSet)91 HashSet (java.util.HashSet)68 URI (org.openrdf.model.URI)67 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)66 Value (org.openrdf.model.Value)55 BindingSet (org.openrdf.query.BindingSet)43 Resource (org.openrdf.model.Resource)35 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)34 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)32 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)32 ArrayList (java.util.ArrayList)30 UUID (java.util.UUID)29 StatementImpl (org.openrdf.model.impl.StatementImpl)26 TopologyFactory (org.apache.rya.streams.kafka.topology.TopologyFactory)25 LinearRing (com.vividsolutions.jts.geom.LinearRing)24 Polygon (com.vividsolutions.jts.geom.Polygon)24