Search in sources :

Example 21 with StatementImpl

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

the class SameAsTest method testGraphConfiguration.

@Test
public // This isn't a good test.  It's simply a cut-and-paste from a test that was failing in a different package in the SameAsVisitor.
void testGraphConfiguration() throws Exception {
    URI a = vf.createURI(namespace, "a");
    Statement statement = new StatementImpl(a, vf.createURI(namespace, "p"), vf.createLiteral("l"));
    Statement statement2 = new StatementImpl(a, vf.createURI(namespace, "p2"), vf.createLiteral("l"));
    ryaDAO.add(RdfToRyaConversions.convertStatement(statement));
    ryaDAO.add(RdfToRyaConversions.convertStatement(statement2));
    ryaDAO.add(RdfToRyaConversions.convertStatement(new StatementImpl(vf.createURI(namespace, "b"), vf.createURI(namespace, "p"), vf.createLiteral("l"))));
    ryaDAO.add(RdfToRyaConversions.convertStatement(new StatementImpl(vf.createURI(namespace, "c"), vf.createURI(namespace, "n"), vf.createLiteral("l"))));
    // build a connection
    RdfCloudTripleStore store = new RdfCloudTripleStore();
    store.setConf(conf);
    store.setRyaDAO(ryaDAO);
    InferenceEngine inferenceEngine = new InferenceEngine();
    inferenceEngine.setRyaDAO(ryaDAO);
    store.setInferenceEngine(inferenceEngine);
    store.initialize();
    System.out.println(Iterations.asList(store.getConnection().getStatements(a, vf.createURI(namespace, "p"), vf.createLiteral("l"), false, new Resource[0])).size());
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) InferenceEngine(org.apache.rya.rdftriplestore.inference.InferenceEngine) Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 22 with StatementImpl

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

the class RdfCloudTripleStoreConnectionTest method testTransitiveProp.

public void testTransitiveProp() throws Exception {
    if (internalInferenceEngine == null) {
        // infer not supported;
        return;
    }
    RepositoryConnection conn = repository.getConnection();
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "subRegionOf"), RDF.TYPE, OWL.TRANSITIVEPROPERTY));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "Queens"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NYC")));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "NYC"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NY")));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "NY"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "US")));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "US"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "NorthAmerica")));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "NorthAmerica"), vf.createURI(litdupsNS, "subRegionOf"), vf.createURI(litdupsNS, "World")));
    conn.commit();
    conn.close();
    internalInferenceEngine.refreshGraph();
    conn = repository.getConnection();
    String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:subRegionOf lit:NorthAmerica.}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(4, tupleHandler.getCount());
    query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:subRegionOf lit:NY.}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(2, tupleHandler.getCount());
    query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {lit:Queens lit:subRegionOf ?s.}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(5, tupleHandler.getCount());
    query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {lit:NY lit:subRegionOf ?s.}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(3, tupleHandler.getCount());
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) StatementImpl(org.openrdf.model.impl.StatementImpl) TupleQuery(org.openrdf.query.TupleQuery)

Example 23 with StatementImpl

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

the class StreamingTestIT method addRandomQueryStatementPairs.

private void addRandomQueryStatementPairs(final int numPairs) throws Exception {
    final Set<Statement> statementPairs = new HashSet<>();
    for (int i = 0; i < numPairs; i++) {
        final String uri = "http://uuid_" + UUID.randomUUID().toString();
        final Statement statement1 = new StatementImpl(new URIImpl(uri), new URIImpl("http://pred1"), new LiteralImpl("number_" + (i + 1)));
        final Statement statement2 = new StatementImpl(new URIImpl(uri), new URIImpl("http://pred2"), new LiteralImpl("literal"));
        statementPairs.add(statement1);
        statementPairs.add(statement2);
    }
    super.getRyaSailRepository().getConnection().add(statementPairs, new Resource[0]);
    super.getMiniFluo().waitForObservers();
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) URIImpl(org.openrdf.model.impl.URIImpl) HashSet(java.util.HashSet)

Example 24 with StatementImpl

use of org.openrdf.model.impl.StatementImpl in project blueprints by tinkerpop.

the class SailHelper method addStatement.

protected static void addStatement(final Resource subject, final URI predicate, final Value object, final Resource context, final SailConnection sailConnection) {
    Statement statement;
    if (null != context) {
        statement = new ContextStatementImpl(subject, predicate, object, context);
    } else {
        statement = new StatementImpl(subject, predicate, object);
    }
    SailHelper.addStatement(statement, sailConnection);
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl)

Example 25 with StatementImpl

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

the class RdfCloudTripleStoreConnection method getStatementsInternal.

@Override
protected CloseableIteration<? extends Statement, SailException> getStatementsInternal(final Resource subject, final URI predicate, final Value object, final boolean flag, final Resource... contexts) throws SailException {
    // try {
    // have to do this to get the inferred values
    // TODO: Will this method reduce performance?
    final Var subjVar = decorateValue(subject, "s");
    final Var predVar = decorateValue(predicate, "p");
    final Var objVar = decorateValue(object, "o");
    StatementPattern sp = null;
    final boolean hasContext = contexts != null && contexts.length > 0;
    final Resource context = (hasContext) ? contexts[0] : null;
    final Var cntxtVar = decorateValue(context, "c");
    // TODO: Only using one context here
    sp = new StatementPattern(subjVar, predVar, objVar, cntxtVar);
    // return new StoreTripleSource(store.getConf()).getStatements(resource, uri, value, contexts);
    final CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate = evaluate(sp, null, null, false);
    return new // TODO: Use a util class to do this
    CloseableIteration<Statement, SailException>() {

        private boolean isClosed = false;

        @Override
        public void close() throws SailException {
            isClosed = true;
            try {
                evaluate.close();
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }

        @Override
        public boolean hasNext() throws SailException {
            try {
                return evaluate.hasNext();
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }

        @Override
        public Statement next() throws SailException {
            if (!hasNext() || isClosed) {
                throw new NoSuchElementException();
            }
            try {
                final BindingSet next = evaluate.next();
                final Resource bs_subj = (Resource) ((subjVar.hasValue()) ? subjVar.getValue() : next.getBinding(subjVar.getName()).getValue());
                final URI bs_pred = (URI) ((predVar.hasValue()) ? predVar.getValue() : next.getBinding(predVar.getName()).getValue());
                final Value bs_obj = (objVar.hasValue()) ? objVar.getValue() : (Value) next.getBinding(objVar.getName()).getValue();
                final Binding b_cntxt = next.getBinding(cntxtVar.getName());
                // convert BindingSet to Statement
                if (b_cntxt != null) {
                    return new ContextStatementImpl(bs_subj, bs_pred, bs_obj, (Resource) b_cntxt.getValue());
                } else {
                    return new StatementImpl(bs_subj, bs_pred, bs_obj);
                }
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }

        @Override
        public void remove() throws SailException {
            try {
                evaluate.remove();
            } catch (final QueryEvaluationException e) {
                throw new SailException(e);
            }
        }
    };
// } catch (QueryEvaluationException e) {
// throw new SailException(e);
// }
}
Also used : Binding(org.openrdf.query.Binding) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) EmptyBindingSet(org.openrdf.query.impl.EmptyBindingSet) BindingSet(org.openrdf.query.BindingSet) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Var(org.openrdf.query.algebra.Var) Resource(org.openrdf.model.Resource) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) CloseableIteration(info.aduna.iteration.CloseableIteration) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) Value(org.openrdf.model.Value) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

StatementImpl (org.openrdf.model.impl.StatementImpl)66 Statement (org.openrdf.model.Statement)40 Test (org.junit.Test)34 URI (org.openrdf.model.URI)32 ValueFactory (org.openrdf.model.ValueFactory)27 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)26 Resource (org.openrdf.model.Resource)19 Value (org.openrdf.model.Value)19 URIImpl (org.openrdf.model.impl.URIImpl)19 HashSet (java.util.HashSet)16 LiteralImpl (org.openrdf.model.impl.LiteralImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)14 BindingSet (org.openrdf.query.BindingSet)14 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)14 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)10 PcjTableNameFactory (org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory)10 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)10 TupleQuery (org.openrdf.query.TupleQuery)7 RepositoryConnection (org.openrdf.repository.RepositoryConnection)7