Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
257 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...enax-arq-utils/src/main/java/org/aksw/jenax/arq/util/execution/ResultSetCompareUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package org.aksw.jenax.arq.util.execution; | ||
|
||
import org.aksw.commons.collections.diff.ListDiff; | ||
import org.apache.jena.query.ResultSet; | ||
import org.apache.jena.sparql.engine.binding.Binding; | ||
|
||
import com.google.common.collect.HashMultiset; | ||
import com.google.common.collect.Multiset; | ||
import com.google.common.collect.Multisets; | ||
|
||
public class ResultSetCompareUtils { | ||
|
||
public static Multiset<Binding> toMultiset(ResultSet rs) { | ||
Multiset<Binding> result = HashMultiset.create(); | ||
while(rs.hasNext()) { | ||
Binding original = rs.nextBinding(); | ||
|
||
Binding wrapped = original; | ||
//QuerySolution wrapped = new QuerySolutionWithEquals(original); | ||
|
||
result.add(wrapped); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Traverse the resultset in order, and write out the missing items on each side: | ||
* 1 2 | ||
* --- | ||
* a a | ||
* b c | ||
* d d | ||
* | ||
* gives: | ||
* [c] [b] | ||
* | ||
* (1 lacks c, 2 lacks b) | ||
* | ||
* | ||
* @param a | ||
* @param b | ||
* @return | ||
*/ | ||
public static ListDiff<Binding> compareOrdered(ResultSet a, ResultSet b) { | ||
ListDiff<Binding> result = new ListDiff<>(); | ||
|
||
Binding x = null; | ||
Binding y = null; | ||
|
||
while(a.hasNext()) { | ||
if(!b.hasNext()) { | ||
while(a.hasNext()) { | ||
result.getAdded().add(a.nextBinding()); | ||
} | ||
return result; | ||
} | ||
|
||
//if((x == null && y == null) || x.equals(y) | ||
if(x == y || x.equals(y)) { | ||
x = a.nextBinding(); | ||
y = b.nextBinding(); | ||
continue; | ||
} | ||
|
||
String sx = x.toString(); | ||
String sy = y.toString(); | ||
|
||
if(sx.compareTo(sy) < 0) { | ||
result.getRemoved().add(x); | ||
x = a.nextBinding(); | ||
} else { | ||
result.getAdded().add(y); | ||
y = b.nextBinding(); | ||
} | ||
} | ||
|
||
while(b.hasNext()) { | ||
result.getRemoved().add(b.nextBinding()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static ListDiff<Binding> compareUnordered(ResultSet a, ResultSet b) { | ||
ListDiff<Binding> result = new ListDiff<>(); | ||
|
||
Multiset<Binding> x = toMultiset(a); | ||
Multiset<Binding> y = toMultiset(b); | ||
|
||
Multiset<Binding> common = HashMultiset.create(Multisets.intersection(x, y)); | ||
|
||
y.removeAll(common); | ||
x.removeAll(common); | ||
|
||
result.getAdded().addAll(y); | ||
result.getRemoved().addAll(x); | ||
|
||
return result; | ||
} | ||
|
||
|
||
} |
118 changes: 118 additions & 0 deletions
118
jenax-arq-parent/jenax-arq-utils/src/main/java/org/aksw/jenax/arq/util/triple/ModelDiff.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.aksw.jenax.arq.util.triple; | ||
|
||
import org.aksw.commons.collections.diff.Diff; | ||
|
||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Statement; | ||
|
||
/** | ||
* @author Claus Stadler | ||
* | ||
* Date: 7/12/11 | ||
* Time: 10:54 PM | ||
*/ | ||
public class ModelDiff | ||
extends Diff<Model> | ||
{ | ||
public ModelDiff() { | ||
super( | ||
ModelFactory.createDefaultModel(), | ||
ModelFactory.createDefaultModel(), | ||
ModelFactory.createDefaultModel()); | ||
} | ||
|
||
public ModelDiff(Model added, Model removed, Model retained) { | ||
super(added, removed,retained); | ||
} | ||
|
||
/** | ||
* Basically adds a statement to the set of added items. | ||
* However, if the statement is marked as removed, it is | ||
* removed from the removal-set, but not added to added-set. | ||
* | ||
* @param stmt | ||
*/ | ||
public void add(Statement stmt) { | ||
if(getRemoved().contains(stmt)) { | ||
getRemoved().remove(stmt); | ||
} else { | ||
getRemoved().remove(stmt); | ||
getAdded().add(stmt); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Adds an item to the set of removed items, unless an equal statement is | ||
* contained in the added-set. In this case the statement is removed from the | ||
* added set. | ||
* | ||
* @param stmt | ||
*/ | ||
public void remove(Statement stmt) { | ||
getAdded().remove(stmt); | ||
getRemoved().add(stmt); | ||
} | ||
|
||
public void add(Model model) { | ||
for(Statement stmt : model.listStatements().toList()) { | ||
add(stmt); | ||
} | ||
} | ||
|
||
public void remove(Model model) { | ||
for(Statement stmt : model.listStatements().toList()) { | ||
remove(stmt); | ||
} | ||
} | ||
|
||
public void clear() { | ||
getAdded().removeAll(); | ||
getRemoved().removeAll(); | ||
} | ||
|
||
|
||
public boolean isEmpty() { | ||
boolean result = getAdded().isEmpty() && getRemoved().isEmpty(); | ||
return result; | ||
} | ||
|
||
/* | ||
public void add(Statement stmt) { | ||
getRemoved().remove(stmt); | ||
getAdded().add(stmt); | ||
} | ||
public void remove(Statement stmt) { | ||
getAdded().remove(stmt); | ||
getRemoved().add(stmt); | ||
} | ||
public void add(Model model) { | ||
getRemoved().remove(model); | ||
getAdded().add(model); | ||
} | ||
public void remove(Model model) { | ||
getAdded().remove(model); | ||
getRemoved().add(model); | ||
} | ||
public void clear() { | ||
getAdded().removeAll(); | ||
getRemoved().removeAll(); | ||
}*/ | ||
|
||
public static ModelDiff create(Model a, Model b) { | ||
ModelDiff result = new ModelDiff(); | ||
|
||
result.getAdded().add(b); | ||
result.getAdded().remove(a); | ||
|
||
result.getRemoved().add(a); | ||
result.getRemoved().remove(b); | ||
|
||
return result; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...x-rx-dataaccess/src/main/java/org/aksw/jena_sparql_api/changeset/SinkChangeSetWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters