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());
}
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();
}
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();
}
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);
}
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);
// }
}
Aggregations