public static ITree ReadTree(string brtFile, bool isRemoveLeafNodes = true, bool isContraintTree = false) { TreeDataParser parser = new TreeDataParser(brtFile, isRemoveLeafNodes, true, isContraintTree); var tree = parser.GetTree(); return(tree); }
public static void VisualizeTree(IEnumerable <string> brtFiles, string luceneIndex = null, string[] keywords = null, bool isRemoveLeafNodes = true) { List <ITree> trees = new List <ITree>(); foreach (var brtFile in brtFiles) { //Read tree from file TreeDataParser parser = new TreeDataParser(brtFile, isRemoveLeafNodes); var tree = parser.GetTree(); Trace.WriteLine(tree.GetDepth(tree.Root)); if (luceneIndex != null) { var scheme = TreeNodeScheme.Get(tree.Graph.NodeTable); scheme.SetIndexReader(LuceneOperations.GetIndexReader(luceneIndex)); scheme.SetBRTFileName(brtFile); } trees.Add(tree); } //Print analyze info DoubleStatistics depthStat = new DoubleStatistics(); DoubleStatistics internalNodeStat = new DoubleStatistics(); foreach (var tree in trees) { depthStat.AddNumber(tree.BFS(tree.Root).Max(node => { int depth = 0; INode ancestor = node; while ((ancestor = tree.GetParent(ancestor)) != null) { depth++; } return(depth); }) + 1); internalNodeStat.AddNumber(tree.BFS(tree.Root).Count()); } Console.WriteLine(depthStat.ToString()); Console.WriteLine(internalNodeStat.ToString()); //Visualize tree Thread NetServer = new Thread(new ThreadStart(() => { TreeVisualization treeVis = new TreeVisualization(trees, keywords); })); NetServer.SetApartmentState(ApartmentState.STA); NetServer.IsBackground = true; NetServer.Start(); System.Windows.Threading.Dispatcher.Run(); }