use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class QueryResultsTest method testDistinctGraphQueryResults.
@Test
public void testDistinctGraphQueryResults() throws QueryEvaluationException {
GraphQueryResult filtered = QueryResults.distinctResults(gqr);
List<Statement> processed = new ArrayList<Statement>();
while (filtered.hasNext()) {
Statement result = filtered.next();
assertFalse(processed.contains(result));
processed.add(result);
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class QueryResultsTest method testStreamGraphResult.
@Test
public void testStreamGraphResult() {
List<Statement> aboutA = QueryResults.stream(gqr).filter(s -> s.getSubject().equals(a)).collect(Collectors.toList());
assertFalse(aboutA.isEmpty());
for (Statement st : aboutA) {
assertTrue(st.getSubject().equals(a));
}
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryUtil method difference.
/**
* Compares two models, defined by two statement collections, and returns the difference between the first
* and the second model (that is, all statements that are present in model1 but not in model2). Blank node
* IDs are not relevant for model equality, they are mapped from one model to the other by using the
* attached properties. *
* <p>
* <b>NOTE: this algorithm is currently broken; it doesn't actually map blank nodes between the two
* models.</b>
*
* @return The collection of statements that is the difference between model1 and model2.
*/
public static Collection<? extends Statement> difference(Collection<? extends Statement> model1, Collection<? extends Statement> model2) {
// Create working copies
LinkedList<Statement> copy1 = new LinkedList<Statement>(model1);
LinkedList<Statement> copy2 = new LinkedList<Statement>(model2);
Collection<Statement> result = new ArrayList<Statement>();
// Compare statements that don't contain bNodes
Iterator<Statement> iter1 = copy1.iterator();
while (iter1.hasNext()) {
Statement st = iter1.next();
if (st.getSubject() instanceof BNode || st.getObject() instanceof BNode) {
// these statements are handled later
continue;
}
// Try to remove the statement from model2
boolean removed = copy2.remove(st);
if (!removed) {
// statement was not present in model2 and is part of the difference
result.add(st);
}
iter1.remove();
}
// FIXME: this algorithm is broken: bNodeMapping is assumed to contain a
// bnode mapping while in reallity it is an empty map
HashMap<BNode, BNode> bNodeMapping = new HashMap<BNode, BNode>();
for (Statement st1 : copy1) {
boolean foundMatch = false;
for (Statement st2 : copy2) {
if (statementsMatch(st1, st2, bNodeMapping)) {
// Found a matching statement
foundMatch = true;
break;
}
}
if (!foundMatch) {
// No statement matching st1 was found in model2, st1 is part of
// the difference.
result.add(st1);
}
}
return result;
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryUtil method difference.
/**
* Compares two models defined by the default context of two repositories and returns the difference
* between the first and the second model (that is, all statements that are present in rep1 but not in
* rep2). Blank node 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.
* <p>
* <b>NOTE: this algorithm is currently broken; it doesn't actually map blank nodes between the two
* models.</b>
*
* @return The collection of statements that is the difference between rep1 and rep2.
*/
public static Collection<? extends Statement> difference(Repository rep1, Repository rep2) throws RepositoryException {
Collection<Statement> model1 = new HashSet<Statement>();
Collection<Statement> model2 = new HashSet<Statement>();
RepositoryConnection con1 = rep1.getConnection();
try {
Iterations.addAll(con1.getStatements(null, null, null, false), model1);
} finally {
con1.close();
}
RepositoryConnection con2 = rep2.getConnection();
try {
Iterations.addAll(con2.getStatements(null, null, null, false), model2);
} finally {
con2.close();
}
return difference(model1, model2);
}
use of org.eclipse.rdf4j.model.Statement in project rdf4j by eclipse.
the class RepositoryUtil method isSubset.
/**
* Compares the models of the default context of two repositories and returns true if rep1 is a subset of
* rep2. Note that the method pulls the entire default context of both repositories into main memory. Use
* with caution.
*/
public static boolean isSubset(Repository rep1, Repository rep2) throws RepositoryException {
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.isSubset(model1, model2);
}
Aggregations