use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryUtil method equals.
/**
* Compares the models in the default contexts of the two supplied repositories and returns true if they
* are equal. Models are equal if they contain the same set of statements. bNodes IDs are not relevant for
* model equality, they are mapped from one model to the other by using the attached properties. Note that
* the method pulls the entire default context of both repositories into main memory. Use with caution.
*/
public static boolean equals(Repository rep1, Repository rep2) throws RepositoryException {
// Fetch statements from rep1 and rep2
Set<Statement> model1, model2;
RepositoryConnection con1 = rep1.getConnection();
try {
model1 = Iterations.asSet(con1.getStatements(null, null, null, true));
} finally {
con1.close();
}
RepositoryConnection con2 = rep2.getConnection();
try {
model2 = Iterations.asSet(con2.getStatements(null, null, null, true));
} finally {
con2.close();
}
return Models.isomorphic(model1, model2);
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class Connections method consumeRDFCollection.
/**
* Retrieve all {@link Statement}s that together form the RDF Collection starting with the supplied start
* resource and send them to the supplied {@link Consumer}.
*
* @param conn
* the {@link RepositoryConnection} to use for statement retrieval.
* @param head
* the start resource of the RDF Collection. May not be {@code null}.
* @param collectionConsumer
* a {@link Consumer} function to which all retrieved statements will be reported. May not be
* {@code null}.
* @param contexts
* the context(s) from which to read the RDF Collection. This argument is an optional vararg and
* can be left out.
* @throws RepositoryException
* if an error occurred while reading the collection statements, for example if a cycle is
* detected in the RDF collection, or some other anomaly which makes it non-wellformed.
* @see RDFCollections
* @see <a href="http://www.w3.org/TR/rdf-schema/#ch_collectionvocab">RDF Schema 1.1 section on Collection
* vocabulary</a>.
*/
public static void consumeRDFCollection(RepositoryConnection conn, Resource head, Consumer<Statement> collectionConsumer, Resource... contexts) throws RepositoryException {
GetStatementOptional statementSupplier = (s, p, o, c) -> getStatement(conn, s, p, o, c);
Function<String, Supplier<RepositoryException>> exceptionSupplier = Repositories::repositoryException;
RDFCollections.extract(statementSupplier, head, collectionConsumer, exceptionSupplier, contexts);
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class AbstractRepositoryConnection method add.
@Override
public void add(Iterable<? extends Statement> statements, Resource... contexts) throws RepositoryException {
OpenRDFUtil.verifyContextNotNull(contexts);
boolean localTransaction = startLocalTransaction();
try {
for (Statement st : statements) {
addWithoutCommit(st, contexts);
}
conditionalCommit(localTransaction);
} catch (RepositoryException e) {
conditionalRollback(localTransaction);
throw e;
} catch (RuntimeException e) {
conditionalRollback(localTransaction);
throw e;
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class ContextStatementTest method test.
@Test
public void test() {
Statement st1 = vf.createStatement(s1, p1, o1);
Statement st2 = vf.createStatement(s1, p1, o1, g1);
Statement st3 = vf.createStatement(s1, p1, o2);
Statement st4 = vf.createStatement(s1, p1, o1, g1);
Statement st5 = vf.createStatement(s1, p1, o1, g2);
assertNotEquals(st1, st2);
assertNotEquals(st1, st3);
assertEquals(st2, st4);
assertNotEquals(st2, st5);
Set<Statement> set = new HashSet<Statement>();
set.add(st1);
set.add(st2);
set.add(st3);
set.add(st4);
set.add(st5);
assertEquals(4, set.size());
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class DAWGTestResultSetUtil method toTupleQueryResult.
public static TupleQueryResult toTupleQueryResult(Iterable<? extends Statement> dawgGraph) throws DAWGTestResultSetParseException {
TupleQueryResultBuilder tqrBuilder = new TupleQueryResultBuilder();
DAWGTestResultSetParser parser = new DAWGTestResultSetParser(tqrBuilder);
try {
parser.startRDF();
for (Statement st : dawgGraph) {
parser.handleStatement(st);
}
parser.endRDF();
return tqrBuilder.getQueryResult();
} catch (RDFHandlerException e) {
throw new DAWGTestResultSetParseException(e.getMessage(), e);
}
}
Aggregations