}
private FunctionallyGroundedNode getFgNodeFromPathNode(ZipFile zipFile,
PathNode pathNode, NamedNode describingResource) throws IOException {
Node afgn = null;
FunctionallyGroundedNodeImpl result = functionallyGroundedBuilder.createFGNode();
descriptionPathToFgNode.put(describingResource, result);
for (String moleculeNodeName : pathNode.list()) {
PathNode moleculePathNode = pathNode.getSubPath(moleculeNodeName);
Model model = ModelFactory.createDefaultModel();
model
.read(moleculePathNode.getInputStream(),
ReferencingNaturalizer.rootURL
+ moleculePathNode.getPath());
/*
* StmtIterator specialStmtIter = model.listStatements(null,
* MODELDIFF.functionallyGroundedIn, (Resource)null); Statement
* specialStmt = specialStmtIter.nextStatement();
* specialStmtIter.close(); Resource groundedNodedRes =
* specialStmt.getSubject(); specialStmt.remove();
*/
Graph graph = JenaUtil.getGraphFromModel(model, false);
Graph tripleSet = new SimpleGraph();
Node currentAfgn = null;
Map<Node, FunctionallyGroundedNode> innerReplacements = new HashMap<Node, FunctionallyGroundedNode>();
for (Triple triple : graph) {
if (triple.getPredicate().equals(
new PropertyNodeImpl(MODELDIFF.functionallyGroundedIn
.getURI()))) {
Node subject = triple.getSubject();
if (!describingResource.equals(triple.getObject())) {
// throw new RuntimeException("invalid diff");
// now legal as fg-nodes may reference to others in
// their nt-molecules
//infinite recursion by cache
FunctionallyGroundedNode replacement = getFgNodeFromDescribingNode(zipFile,
(NamedNode) triple.getObject());
innerReplacements.put(subject, replacement);
} else {
currentAfgn = subject;
}
} else {
tripleSet.add(triple);
}
}
if (afgn == null) {
afgn = currentAfgn;
} else {
tripleSet = replaceNode(currentAfgn, afgn, tripleSet);
}
for (Entry<Node, FunctionallyGroundedNode> entry : innerReplacements.entrySet()) {
tripleSet = replaceNode(entry.getKey(), entry.getValue(), tripleSet);
}
NonTerminalMolecule ntMolecule = functionallyGroundedBuilder.createNTMolecule(afgn);
ntMolecule.addAll(tripleSet);
result.addMolecule(ntMolecule);
}
return result;
}