Search in sources :

Example 1 with ValueFactoryImpl

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

the class AccumuloFreeTextIndexerTest method testContextSearch.

@Test
public void testContextSearch() throws Exception {
    try (AccumuloFreeTextIndexer f = new AccumuloFreeTextIndexer()) {
        f.setConf(conf);
        f.setMultiTableBatchWriter(ConfigUtils.createMultitableBatchWriter(conf));
        f.init();
        ValueFactory vf = new ValueFactoryImpl();
        URI subject = new URIImpl("foo:subj");
        URI predicate = new URIImpl(RDFS.COMMENT.toString());
        Value object = vf.createLiteral("this is a new hat");
        URI context = new URIImpl("foo:context");
        Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement));
        f.flush();
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("hat", new StatementConstraints().setContext(vf.createURI("foo:context2")))));
    }
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) 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) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Test(org.junit.Test)

Example 2 with ValueFactoryImpl

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

the class AccumuloTemporalIndexerTest method testQueryWithMultiplePredicates.

/**
 * Test instant after a given instant WITH two different predicates as constraints.
 */
@Test
public void testQueryWithMultiplePredicates() throws IOException, QueryEvaluationException {
    // tiB02_E30 read as: Begins 2 seconds, ends at 30 seconds
    // these should not match as they are not instances.
    tIndexer.storeStatement(convertStatement(spo_B03_E20));
    tIndexer.storeStatement(convertStatement(spo_B02_E30));
    tIndexer.storeStatement(convertStatement(spo_B02_E40));
    tIndexer.storeStatement(convertStatement(spo_B02_E31));
    tIndexer.storeStatement(convertStatement(spo_B30_E32));
    // seriesSpo[s] and seriesTs[s] are statements and instant for s seconds after the uniform time.
    int searchForSeconds = 4;
    int expectedResultCount = 9;
    for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
        // <== logic here
        tIndexer.storeStatement(convertStatement(seriesSpo[s]));
    }
    ValueFactory vf = new ValueFactoryImpl();
    // this one to ignore.
    URI pred3_CIRCA_ = vf.createURI(URI_PROPERTY_CIRCA);
    URI pred2_eventTime = vf.createURI(URI_PROPERTY_EVENT_TIME);
    URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
    // add the predicate = EventTime ; Store in an array for verification.
    Statement[] SeriesTs_EventTime = new Statement[expectedResultCount + 1];
    for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
        // <== logic here
        Statement statement = new StatementImpl(vf.createURI("foo:EventTimeSubj0" + s), pred2_eventTime, vf.createLiteral(seriesTs[s].getAsReadable()));
        tIndexer.storeStatement(convertStatement(statement));
        if (s > searchForSeconds)
            SeriesTs_EventTime[s - searchForSeconds - 1] = statement;
    }
    // add the predicate = CIRCA ; to be ignored because it is not in the constraints.
    for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) {
        // <== logic here
        Statement statement = new StatementImpl(vf.createURI("foo:CircaEventSubj0" + s), pred3_CIRCA_, vf.createLiteral(seriesTs[s].getAsReadable()));
        tIndexer.storeStatement(convertStatement(statement));
    }
    tIndexer.flush();
    CloseableIteration<Statement, QueryEvaluationException> iter;
    StatementConstraints constraints = new StatementConstraints();
    constraints.setPredicates(new HashSet<URI>(Arrays.asList(pred2_eventTime, pred1_atTime)));
    // EMPTY_CONSTRAINTS);//
    iter = tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], constraints);
    int count_AtTime = 0;
    int count_EventTime = 0;
    while (iter.hasNext()) {
        Statement s = iter.next();
        // System.out.println("testQueryWithMultiplePredicates result="+s);
        // <== logic here
        Statement nextExpectedStatement = seriesSpo[searchForSeconds + count_AtTime + 1];
        if (s.getPredicate().equals(pred1_atTime)) {
            assertTrue("Should match atTime: " + nextExpectedStatement + " == " + s, nextExpectedStatement.equals(s));
            count_AtTime++;
        } else if (s.getPredicate().equals(pred2_eventTime)) {
            assertTrue("Should match eventTime: " + SeriesTs_EventTime[count_EventTime] + " == " + s, SeriesTs_EventTime[count_EventTime].equals(s));
            count_EventTime++;
        } else {
            assertTrue("This predicate should not be returned: " + s, false);
        }
    }
    Assert.assertEquals("Should find count of atTime    rows.", expectedResultCount, count_AtTime);
    Assert.assertEquals("Should find count of eventTime rows.", expectedResultCount, count_EventTime);
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 3 with ValueFactoryImpl

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

the class AccumuloTemporalIndexerTest method testStoreStatementWithInterestingLiterals.

@Test
public void testStoreStatementWithInterestingLiterals() throws Exception {
    ValueFactory vf = new ValueFactoryImpl();
    URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME);
    tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral("A number of organizations located, gathered, or classed together. [Derived from Concise Oxford English Dictionary, 11th Edition, 2008]"))));
    int rowsStoredActual = printTables("junit testing: Temporal entities stored in testStoreStatement", null, null);
    // 4 index entries per statement
    Assert.assertEquals("Number of rows stored.", 0, rowsStoredActual);
}
Also used : StatementImpl(org.openrdf.model.impl.StatementImpl) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 4 with ValueFactoryImpl

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

the class VisibilityStatementSerdeTest method serializeAndDeserialize.

@Test
public void serializeAndDeserialize() {
    // Create the object that will be serialized.
    final ValueFactory vf = new ValueFactoryImpl();
    final Statement statement = vf.createStatement(vf.createURI("urn:person1"), vf.createURI("urn:hasName"), vf.createLiteral("alice"), vf.createURI("urn:testContext"));
    final VisibilityStatement original = new VisibilityStatement(statement, "a|b|c");
    // Serialize it.
    try (final Serde<VisibilityStatement> serde = new VisibilityStatementSerde()) {
        final byte[] bytes = serde.serializer().serialize("topic", original);
        // Deserialize it.
        final VisibilityStatement deserialized = serde.deserializer().deserialize("topic", bytes);
        // Show the deserialized value matches the original.
        assertEquals(original, deserialized);
    }
}
Also used : Statement(org.openrdf.model.Statement) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) Test(org.junit.Test)

Example 5 with ValueFactoryImpl

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

the class KafkaGetQueryResultStreamIT method fromStart_visibilityStatements.

@Test
public void fromStart_visibilityStatements() throws Exception {
    // Create an ID for the query.
    final String ryaInstance = UUID.randomUUID().toString();
    final UUID queryId = UUID.randomUUID();
    // Create some statements that will be written to the result topic.
    final List<VisibilityStatement> original = new ArrayList<>();
    final ValueFactory vf = new ValueFactoryImpl();
    original.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob")), "a"));
    original.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(63)), "b"));
    original.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral("urn:34")), ""));
    // Write the entries to the query result topic in Kafka.
    try (final Producer<?, VisibilityStatement> producer = KafkaTestUtil.makeProducer(kafka, StringSerializer.class, VisibilityStatementSerializer.class)) {
        final String resultTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
        for (final VisibilityStatement visStmt : original) {
            producer.send(new ProducerRecord<>(resultTopic, visStmt));
        }
    }
    // Use the interactor that is being tested to read all of the visibility binding sets.
    final GetQueryResultStream<VisibilityStatement> interactor = new KafkaGetQueryResultStream<>(kafka.getKafkaHostname(), kafka.getKafkaPort(), VisibilityStatementDeserializer.class);
    final List<VisibilityStatement> read = pollForResults(500, 3, 3, interactor.fromStart(ryaInstance, queryId));
    // Show the fetched binding sets match the original, as well as their order.
    assertEquals(original, read);
}
Also used : ArrayList(java.util.ArrayList) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) ValueFactory(org.openrdf.model.ValueFactory) UUID(java.util.UUID) VisibilityStatement(org.apache.rya.api.model.VisibilityStatement) 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