use of org.apache.rya.indexing.StatementConstraints 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")))));
}
}
use of org.apache.rya.indexing.StatementConstraints 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);
}
use of org.apache.rya.indexing.StatementConstraints in project incubator-rya by apache.
the class RyaOutputFormatTest method testFreeTextIndexing.
@Test
public void testFreeTextIndexing() throws Exception {
final AccumuloFreeTextIndexer ft = new AccumuloFreeTextIndexer();
ft.setConf(conf);
final RyaStatement input = RyaStatement.builder().setSubject(new RyaURI(GRAPH + ":s")).setPredicate(new RyaURI(GRAPH + ":p")).setObject(new RyaType(XMLSchema.STRING, "one two three four five")).build();
RyaOutputFormat.setCoreTablesEnabled(job, false);
RyaOutputFormat.setFreeTextEnabled(job, true);
RyaOutputFormat.setTemporalEnabled(job, false);
RyaOutputFormat.setEntityEnabled(job, false);
write(input);
final Set<Statement> empty = new HashSet<>();
final Set<Statement> expected = new HashSet<>();
expected.add(RyaToRdfConversions.convertStatement(input));
Assert.assertEquals(expected, getSet(ft.queryText("one", new StatementConstraints())));
Assert.assertEquals(empty, getSet(ft.queryText("!two", new StatementConstraints())));
Assert.assertEquals(expected, getSet(ft.queryText("*r", new StatementConstraints())));
Assert.assertEquals(empty, getSet(ft.queryText("r*", new StatementConstraints())));
Assert.assertEquals(expected, getSet(ft.queryText("!r*", new StatementConstraints())));
Assert.assertEquals(expected, getSet(ft.queryText("t* & !s*", new StatementConstraints())));
ft.close();
}
use of org.apache.rya.indexing.StatementConstraints in project incubator-rya by apache.
the class MongoFreeTextIndexerIT method testContextSearch.
@Test
public void testContextSearch() 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 = new URIImpl(RDFS.COMMENT.toString());
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(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
assertEquals(Sets.newHashSet(), getSet(f.queryText("hat", new StatementConstraints().setContext(vf.createURI("foo:context2")))));
}
}
use of org.apache.rya.indexing.StatementConstraints in project incubator-rya by apache.
the class GeoIndexerTest method testDcSearchWithContext.
@Test
public void testDcSearchWithContext() throws Exception {
// test a ring around dc
try (final GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) {
f.setConf(conf);
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("foo:subj");
final URI predicate = GeoConstants.GEO_AS_WKT;
final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
final Resource context = vf.createURI("foo:context");
final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
f.storeStatement(convertStatement(statement));
f.flush();
final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
// query with correct context
Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
// query with wrong context
Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
}
}
Aggregations