/// <summary> /// Add a tree after the children of the parent vertex. /// </summary> /// <param name="parent"> Parent identifier. </param> /// <param name="tree"> The tree to add. </param> /// <returns> A dictionary of the equivalence between identifiers of the tree in the parameters and their new value once added to the tree. </returns> public Dictionary <int, int> AddChildTree(int parent, PropertyTree tree) { Dictionary <int, int> renumberedTree = base.AddChildTree(parent, tree); foreach (int key in renumberedTree.Keys) { foreach (string name in tree.Properties().Keys) { if (tree.Property(name).ContainsKey(key)) { int v = tree.Property(name)[key]; if (v != -1) { properties[name].Add(renumberedTree[key], v); } } } } return(renumberedTree); }
/// <summary> /// Saves the PropertyTree into a file (.tlp) /// </summary> /// <param name="tree"> The property tree to save. </param> /// <param name="path"> Contains the path and the name of the file (Do not mention the extension). </param> public void SaveToFile(PropertyTree tree, string path) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(@path + ".tlp")) { // First line file.WriteLine("(tlp \"2.0\""); // List of all nodes file.Write("(nodes"); foreach (int node in tree.parent.Keys) { file.Write(" " + node); } file.WriteLine(")"); // List of all edges int countEdges = 0; foreach (int edge in tree.parent.Keys) { if (edge != 0) { countEdges++; file.WriteLine("(edge " + countEdges + " " + (int)tree.Parent(edge) + " " + edge + ")"); } } // List of all clusters int clusterId = 1; foreach (string name in tree.PropertyNames()) { file.WriteLine("(cluster " + clusterId + " " + name); file.Write("(nodes"); foreach (int node in tree.Property(name).Keys) { file.Write(" " + node); } file.WriteLine("))"); clusterId++; } // List of all properties int propertyId = 1; foreach (string name in tree.PropertyNames()) { file.WriteLine("(property " + propertyId + " string \"" + name + "\""); Dictionary <int, dynamic> property = tree.Property(name); foreach (int id in property.Keys) { file.WriteLine("(node " + id + " " + property[id] + ")"); } file.WriteLine(")"); propertyId++; } } }