use of org.sbpax.util.MultiHashMap in project vcell by virtualcell.
the class ModelComparer method extractSubModels.
private void extractSubModels(Graph diff, Set<Graph> subModels) {
MultiMap<Resource, Resource> bNodesMap = new MultiHashMap<Resource, Resource>();
MultiMap<Resource, Statement> triples = new MultiHashMap<Resource, Statement>();
for (Statement statement : diff) {
Set<Resource> bNodesInTriple = new HashSet<Resource>();
recordIfBlankNode(statement.getSubject(), statement, bNodesInTriple, triples);
recordIfBlankNode(statement.getPredicate(), statement, bNodesInTriple, triples);
recordIfBlankNode(statement.getObject(), statement, bNodesInTriple, triples);
Set<Resource> bNodesUnion = new HashSet<Resource>();
bNodesUnion.addAll(bNodesInTriple);
for (Resource bNode : bNodesInTriple) {
Set<Resource> bNodes = bNodesMap.get(bNode);
if (bNodes != null) {
bNodesUnion.addAll(bNodes);
}
}
for (Resource bNode : bNodesUnion) {
bNodesMap.put(bNode, bNodesUnion);
}
}
for (Set<Resource> bNodes : bNodesMap.values()) {
Graph model = new HashGraph();
for (Resource bNode : bNodes) {
for (Statement statement : triples.get(bNode)) {
model.add(statement);
}
}
subModels.add(model);
}
}