public void RemoveNodeType(LabeledNodeType type, LabeledNode node) { if (TypeNodes.ContainsKey(type)) { TypeNodes[type].Remove(node); } }
public virtual void AddNodeType(LabeledNodeType type, LabeledNode node) { if (!UsedTypes.ContainsKey(type.GetQuasiUniqueRepresentation())) { TypeNodes.Add(type, new List <LabeledNode>(10)); UsedTypes.Add(type.GetQuasiUniqueRepresentation(), type); node.Type = type; } else { node.Type = UsedTypes[type.GetQuasiUniqueRepresentation()]; } TypeNodes[node.Type].Add(node); }
/* * public static void Binarize(LabeledNode parent, NodeCreator nodeCreator) * { * if (parent.Children.Count > 2) * { * var firstChild = parent.Children.FirstOrDefault(); * var restOfChildren = parent.Children.ToList(); * restOfChildren.RemoveAt(0); * parent.Children.Clear(); * * var tempNode = nodeCreator.CreateTempNode(); * tempNode.STInfo = "B"; * * parent.AddChild(firstChild); * parent.AddChild(tempNode); * * foreach (var child in restOfChildren) * { * tempNode.AddChild(child); * } * * Binarize(firstChild, nodeCreator); * Binarize(tempNode, nodeCreator); * } * else * { * foreach (var child in parent.Children) * { * BinarizeNew(child, nodeCreator); * } * } * } */ public static void Binarize(LabeledNode parent, NodeCreator nodeCreator) { if (parent.Children.Count > 2) { var groups = FindSuccessiveNonLeavesGroups(parent.Children); groups.Reverse(); foreach (var group in groups) { var indexOfFirst = parent.Children.IndexOf(group.First()); parent.Children.RemoveRange(indexOfFirst, group.Count); var tempNode = nodeCreator.CreateTempNode(); tempNode.Parent = parent; if (parent.STInfo.StartsWith("B_")) { tempNode.STInfo = parent.STInfo; } else { tempNode.STInfo = "B_" + parent.STInfo; } var firstGroupChild = group.FirstOrDefault(); var restOfGroupChildren = group.ToList(); restOfGroupChildren.RemoveAt(0); foreach (var child in restOfGroupChildren) { tempNode.AddChild(child); } parent.Children.Insert(indexOfFirst, firstGroupChild); parent.Children.Insert(indexOfFirst + 1, tempNode); } } foreach (var child in parent.Children) { Binarize(child, nodeCreator); } }