public NodeGraphTemplateDetection(NodeGraph rootNode)
        {
            // if (rootNode.level < 3) return;

            Root = rootNode;
            var allNodes = rootNode.GetChildren(); //.getAllChildren(null, false, false, 1, 500, false); //.getAllChildrenInType<NodeGraph>(null, false, false, 1, 500, true);

            foreach (NodeGraph node in allNodes)
            {
                NodeGraphTemplateCandidate candidate = new NodeGraphTemplateCandidate(node);
                if (candidate.LeafsByRelativePath.Count == 0)
                {
                    continue;
                }

                String templateSignature = candidate.GetSignature();

                String childrenSignature = candidate.GetLeafSignature();



                if (ChildrenByChildSignature.ContainsKey(childrenSignature))
                {
                    var existingTemplate = ChildrenByChildSignature[childrenSignature];
                    existingTemplate.Instances.Add(node);
                }
                else
                {
                    ChildrenByChildSignature.Add(childrenSignature, candidate);
                }
            }


            foreach (var tr in ChildrenByChildSignature.Where(x => x.Value.LeafsByRelativePath.Count <= 1).ToList())
            {
                ChildrenByChildSignature.Remove(tr.Key);
            }

            if (ChildrenByChildSignature.Count > 0)
            {
            }

            /*
             * foreach ( var tr in ChildrenByChildSignature.Where(x => x.Value.Instances.Count <= 1).ToList())
             * {
             *  ChildrenByChildSignature.Remove(tr.Key);
             * }*/
        }
        public Double ParenthoodScoreAgainst(NodeGraphTemplateCandidate other)
        {
            Int32 instanceParenthoods = 0;

            foreach (NodeGraph instance in Instances)
            {
                String path = instance.path;
                if (other.Instances.Any(x => x.path.StartsWith(path)))
                {
                    instanceParenthoods++;
                }
            }
            Double parentHoodScore = Instances.Count().GetRatio(instanceParenthoods);

            return(parentHoodScore);
        }
 public Boolean IsParentOf(NodeGraphTemplateCandidate other)
 {
     return(ParenthoodScoreAgainst(other) > 0.5);
 }