Search in sources :

Example 6 with URI

use of org.openrdf.model.URI 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 7 with URI

use of org.openrdf.model.URI 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 8 with URI

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

the class AccumuloConstantPcjIT method testEvaluateThreeIndexVarInstantiate.

@Test
public void testEvaluateThreeIndexVarInstantiate() throws PcjException, RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, MalformedQueryException, SailException, QueryEvaluationException, TupleQueryResultHandlerException {
    final URI superclass = new URIImpl("uri:superclass");
    final URI superclass2 = new URIImpl("uri:superclass2");
    final URI sub = new URIImpl("uri:entity");
    subclass = new URIImpl("uri:class");
    obj = new URIImpl("uri:obj");
    talksTo = new URIImpl("uri:talksTo");
    final URI howlsAt = new URIImpl("uri:howlsAt");
    final URI subType = new URIImpl("uri:subType");
    conn.add(subclass, RDF.TYPE, superclass);
    conn.add(subclass2, RDF.TYPE, superclass2);
    conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
    conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
    conn.add(sub, howlsAt, superclass);
    conn.add(superclass, subType, obj);
    conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
    conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
    final String indexSparqlString = // 
    "" + // 
    "SELECT ?dog ?pig ?duck  " + // 
    "{" + // 
    "  ?pig a ?dog . " + // 
    "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
    "}";
    final String indexSparqlString2 = // 
    "" + // 
    "SELECT ?o ?f ?e ?c ?l  " + // 
    "{" + // 
    "  ?e <uri:talksTo> ?o . " + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
    "  ?c a ?f . " + // 
    "}";
    final String indexSparqlString3 = // 
    "" + // 
    "SELECT ?wolf ?sheep ?chicken  " + // 
    "{" + // 
    "  ?wolf <uri:howlsAt> ?sheep . " + // 
    "  ?sheep <uri:subType> ?chicken. " + // 
    "}";
    final String queryString = // 
    "" + // 
    "SELECT ?c ?l ?f ?o " + // 
    "{" + // 
    "  <uri:entity> a ?c . " + // 
    "  <uri:entity> <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
    "  <uri:entity> <uri:talksTo> ?o . " + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
    "  ?c a ?f . " + // 
    "  <uri:entity> <uri:howlsAt> ?f. " + // 
    "  ?f <uri:subType> <uri:obj>. " + // 
    "}";
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1, indexSparqlString, new String[] { "dog", "pig", "duck" }, Optional.<PcjVarOrderFactory>absent());
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 2, indexSparqlString2, new String[] { "o", "f", "e", "c", "l" }, Optional.<PcjVarOrderFactory>absent());
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 3, indexSparqlString3, new String[] { "wolf", "sheep", "chicken" }, Optional.<PcjVarOrderFactory>absent());
    final CountingResultHandler crh1 = new CountingResultHandler();
    final CountingResultHandler crh2 = new CountingResultHandler();
    conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh1);
    PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, prefix);
    pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh2);
    Assert.assertEquals(crh1.getCount(), crh2.getCount());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 9 with URI

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

the class PrecompJoinOptimizerIT method testEvaluateSingeFilterWithLeftJoin.

@Test
public void testEvaluateSingeFilterWithLeftJoin() throws TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException, RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException, PcjException, InferenceEngineException, NumberFormatException, UnknownHostException {
    final String indexSparqlString1 = // 
    "" + // 
    "SELECT ?e ?l ?c " + // 
    "{" + // 
    "  Filter(?l = \"label3\") " + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    final URI sub3 = new URIImpl("uri:entity3");
    final URI subclass3 = new URIImpl("uri:class3");
    conn.add(sub3, RDF.TYPE, subclass3);
    conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
    PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablePrefix + "INDEX_1", indexSparqlString1, new String[] { "e", "l", "c" }, Optional.<PcjVarOrderFactory>absent());
    final String queryString = // 
    "" + // 
    "SELECT ?e ?c ?o ?m ?l" + // 
    "{" + // 
    "  Filter(?l = \"label3\") " + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
    "  OPTIONAL { ?e <uri:talksTo> ?o . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?m }" + // 
    "}";
    final CountingResultHandler crh = new CountingResultHandler();
    PcjIntegrationTestingUtil.deleteCoreRyaTables(accCon, tablePrefix);
    PcjIntegrationTestingUtil.closeAndShutdown(conn, repo);
    repo = PcjIntegrationTestingUtil.getAccumuloPcjRepo(tablePrefix, "instance");
    conn = repo.getConnection();
    conn.add(sub, talksTo, obj);
    conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
    pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
    Assert.assertEquals(1, crh.getCount());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 10 with URI

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

the class CbSailTest method testInsertData.

public void testInsertData() throws Exception {
    URI cpu = vf.createURI(litdupsNS, "cpu");
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    URI uri2 = vf.createURI(litdupsNS, "uri2");
    List<Statement> insert = new ArrayList<Statement>();
    insert.add(new StatementImpl(cpu, loadPerc, uri1));
    insert.add(new StatementImpl(cpu, loadPerc, uri2));
    resultEndpoint.expectedBodiesReceived(true);
    template.sendBody(insert);
    assertMockEndpointsSatisfied();
    resultEndpoint.expectedMessageCount(2);
    String query = "select * where {" + "<" + cpu.toString() + "> ?p ?o1." + "}";
    template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query);
    assertMockEndpointsSatisfied();
}
Also used : Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) ArrayList(java.util.ArrayList) URI(org.openrdf.model.URI)

Aggregations

URI (org.openrdf.model.URI)368 Test (org.junit.Test)138 Value (org.openrdf.model.Value)122 Resource (org.openrdf.model.Resource)110 Statement (org.openrdf.model.Statement)96 ValueFactory (org.openrdf.model.ValueFactory)83 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)67 URIImpl (org.openrdf.model.impl.URIImpl)58 HashSet (java.util.HashSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)34 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)34 Literal (org.openrdf.model.Literal)34 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)34 StatementImpl (org.openrdf.model.impl.StatementImpl)32 LiteralImpl (org.openrdf.model.impl.LiteralImpl)29 Var (org.openrdf.query.algebra.Var)28 ArrayList (java.util.ArrayList)25 SailConnection (org.openrdf.sail.SailConnection)25 LinearRing (com.vividsolutions.jts.geom.LinearRing)24 Polygon (com.vividsolutions.jts.geom.Polygon)24