* @param addReferencedFgNodes if false an exception is thrown if graph contians an fg-node which is not in fgNodes
*/
public NaturalizedGraph(Graph graph,
Collection<FunctionallyGroundedNode> fgNodes, boolean addReferencedFgNodes) {
Map<Set<NonTerminalMolecule>, Node> replacementMap = new HashMap<Set<NonTerminalMolecule>, Node>();
Graph fgNodesGraph = new SimpleGraph();
for (Iterator<FunctionallyGroundedNode> iter = fgNodes.iterator(); iter
.hasNext();) {
FunctionallyGroundedNode fgNode = iter.next();
// fg2NormalNodeMap.put(fgNode, fgNode.getOriginalNode());
Node replacementNode = addFgNodeMolecules(fgNode, new DefaultNaturalizer(), fgNodesGraph);
//rehashing necessary as long unfinalized nodes come
replacementMap.put(new HashSet<NonTerminalMolecule>(fgNode.getGroundingMolecules()), replacementNode);
}
Naturalizer naturalizer;
if (addReferencedFgNodes) {
naturalizer = new DefaultNaturalizer();
} else {
naturalizer = null;
}
addGraphTriples(graph, addReferencedFgNodes, naturalizer, replacementMap, fgNodesGraph);
while (fgNodesGraph.size() > 0) {
//add the triples of the fg-nodes graph and repeat if new triples result from fg-nodes replacemnets
//withing these triples
Graph addingFgNodesGraph = fgNodesGraph;
fgNodesGraph = new SimpleGraph();
addGraphTriples(addingFgNodesGraph, addReferencedFgNodes, naturalizer, replacementMap, fgNodesGraph);
}
markFinalized();
}