public DirectedGraphWithSourceData Publish(folderNode folder, String name) { TagCounter = new frequencyCounter <string>(); NodeTagCounter = new frequencyCounter <string>(); RebuildIndex(); String listPath = folder.pathFor("nd_" + name + "_list.txt", imbSCI.Data.enums.getWritableFileMode.overwrite, "List of selected nodes"); String statPath = folder.pathFor("nd_" + name + "_stats.txt", imbSCI.Data.enums.getWritableFileMode.overwrite, "Stats of selected nodes"); String graphPath = folder.pathFor("nd_" + name + "_graph.dgml", imbSCI.Data.enums.getWritableFileMode.overwrite, "Structure graph"); String graphStatsPath = folder.pathFor("nd_" + name + "_graph_stats.txt", imbSCI.Data.enums.getWritableFileMode.overwrite, "Stats of the complete graph"); StringBuilder listBuilder = new StringBuilder(); StringBuilder statBuilder = new StringBuilder(); StringBuilder graphStatBuilder = new StringBuilder(); foreach (var item in items) { listBuilder.AppendLine(item.XPath); TagCounter.Count(item.node.Name); } var freqBins = TagCounter.GetFrequencyBins(); foreach (var bin in freqBins) { statBuilder.AppendLine(bin.Key + " " + bin.Value.toCsvInLine()); } var GraphFreqBins = NodeTagCounter.GetFrequencyBins(); foreach (var bin in GraphFreqBins) { graphStatBuilder.AppendLine(bin.Key + " " + bin.Value.toCsvInLine()); } DirectedGraphWithSourceData dgml = BuildDGML(); dgml.Save(graphPath, imbSCI.Data.enums.getWritableFileMode.overwrite); File.WriteAllText(listPath, listBuilder.ToString()); File.WriteAllText(statPath, statBuilder.ToString()); File.WriteAllText(graphStatsPath, graphStatBuilder.ToString()); return(dgml); }
public DirectedGraphWithSourceData BuildDirectedGraph(NodeDictionaryGraphStyleSettings style = null) { if (style == null) { style = new NodeDictionaryGraphStyleSettings(); } DirectedGraphWithSourceData output = new DirectedGraphWithSourceData(); List <NodeGraph> allChildren = this.getAllChildrenInType <NodeGraph>(); output.Populate(allChildren, x => x.GetChildren <NodeGraph>(), x => x.path, x => x.name, false, false); // output.Populate(allChildren, x => x.item., x => x.path, x => x.name, false, false); foreach (var pair in output.Sources) { if (pair.Key is Link graphLink) { style.SetElement(graphLink, pair.Value.LastOrDefault() as NodeGraph); } else if (pair.Key is Node graphNode) { style.SetElement(graphNode, pair.Value.LastOrDefault() as NodeGraph); } } if (style.AddContentNodes) { var nodesWithItem = allChildren.Where(x => x.item != null).ToList(); var contentNodes = output.Populate <NodeGraph, HtmlNode>(nodesWithItem, x => x.item.node.SelectTextLeafNodes(), x => x.path, x => x.name, x => x.XPath, x => x.GetInnerText(), false, false); foreach (KeyValuePair <GraphElement, List <object> > pairs in contentNodes) { style.SetContentElement(pairs.Key); } } return(output); }
public void Publish(folderNode folder, DirectedGraphWithSourceData InitialGraph) { ColorGradientForInstanceEnumeration <String> chunkInstanceGradient = new ColorGradientForInstanceEnumeration <String>("#f7941d", "#6dcff6"); chunkInstanceGradient.Prepare(items.Select(x => x.ExtractorName)); if (InitialGraph == null) { return; } NodeGraph chunkRootGraph = BuildChunkRootsGraph(); var chunkRootGraphNodes = InitialGraph.Nodes.Get(chunkRootGraph.getAllChildren().Select(x => x.path)).ToDictionary(x => x.Id); foreach (var gnp in chunkRootGraphNodes) { if (gnp.Value is Node) { gnp.Value.Background = "#999999"; gnp.Value.StrokeDashArray = "2,5,2,5,2,5"; gnp.Value.StrokeThinkness = 2; } } List <NodeGraph> TargetRootNodes = chunkRootGraph.getAllChildrenInType <NodeGraph>().Where(x => x.HasMetaData()).ToList(); ListDictionary <ContentChunk, DirectedGraph> subgraphs = new ListDictionary <ContentChunk, DirectedGraph>(); NodeDictionaryGraphStyleSettings style = new NodeDictionaryGraphStyleSettings(); foreach (NodeGraph ng in TargetRootNodes) { var TargetRootNodesInContentGraph = InitialGraph.Select <NodeGraph>(new List <NodeGraph>() { ng }, x => x.path, true, true); ContentChunk chunk = ng.GetMetaData <ContentChunk>(); var nodeColor = chunkInstanceGradient.GetColor(chunk.ExtractorName, true); foreach (var pair in TargetRootNodesInContentGraph) { if (pair.Key is Node node) { var allLinked = chunk.PublishAnnotation(InitialGraph, nodeColor, style); var sg = InitialGraph.GetSubgraph(allLinked.SelectMany(x => x)); sg.Title = chunk.name; subgraphs[chunk].Add(sg); } else if (pair.Key is Link link) { // link.Stroke = nodeColor; } } } foreach (var pair in subgraphs) { Int32 grpi = 0; foreach (var grp in pair.Value) { String grpp = "chunk_subgraph" + pair.Key.name + grpi.ToString() + ".dgml"; grp.Save(folder.pathFor(grpp, imbSCI.Data.enums.getWritableFileMode.overwrite), imbSCI.Data.enums.getWritableFileMode.overwrite); grpi++; } } InitialGraph.Save(folder.pathFor("CompleteGraph.dgml"), imbSCI.Data.enums.getWritableFileMode.overwrite); /* * var chunkTargetRootNodes = InitialGraph.Nodes.Get(.Select(x => x.path)).ToDictionary(x => x.Id); * foreach (var gnp in chunkTargetRootNodes) * { * * if (gnp.Value is Node) * { * gnp.Value.Background = chunkInstanceGradient.GetColor(chunk.ExtractorName, true); * gnp.Value.StrokeDashArray = ""; * gnp.Value.StrokeThinkness = 5; * } * } * * * * foreach (ContentChunk chunk in items) * { * var graphNodes = InitialGraph.Nodes.Get(chunk.ContentAnalysis.allContent.items.Select(x => x.XPath)); * * var nodeColor = chunkInstanceGradient.GetColor(chunk.ExtractorName, true); * * var itemsByXPath = chunk.ContentAnalysis.allContent.items.ToDictionary(x => x.XPath); * * var graphNodeByXPath = chunk.ContentAnalysis.allContent.ContentGraph.getAllChildren().ToDictionary(x => x.path); * * foreach (var gn in graphNodes) * { * gn.Background = nodeColor; * * } * * var SelectedGraphNodes = InitialGraph.Nodes.Get(itemsByXPath.Keys).ToDictionary(x => x.Id); * * foreach (var gnp in SelectedGraphNodes) * { * gnp.Value.Background = nodeColor; * * } * * * } * */ foreach (ContentChunk chunk in items) { String chunkStrictName = chunk.name.getCleanPropertyName(); var subfolder = folder.Add(chunkStrictName, chunk.name, "Cluster group diagnostics"); chunk.Publish(subfolder); } }
public DirectedGraphWithSourceData BuildDGML(NodeDictionaryGraphStyleSettings style = null) { if (style == null) { style = new NodeDictionaryGraphStyleSettings(); } DirectedGraphWithSourceData output = new DirectedGraphWithSourceData(); RebuildIndex(); output = ContentGraph.BuildDirectedGraph(style); /* * List<NodeGraph> allChildren = ContentGraph.getAllChildrenInType<NodeGraph>(); * * output.Populate(allChildren, x => x.GetChildren<NodeGraph>(), x => x.path, x => x.name, false, false); * * * // output.Populate(allChildren, x => x.item., x => x.path, x => x.name, false, false); * * foreach (var pair in output.Sources) * { * if (pair.Key is Link graphLink) * { * style.SetElement(graphLink, pair.Value.LastOrDefault() as NodeGraph); * * * } else if (pair.Key is Node graphNode) * { * style.SetElement(graphNode, pair.Value.LastOrDefault() as NodeGraph); * } * } * * var nodesWithItem = allChildren.Where(x => x.item != null).ToList(); * * var contentNodes = output.Populate<NodeGraph, HtmlNode>(nodesWithItem, x => x.item.node.SelectTextLeafNodes(), x => x.path, x => x.name, x => x.XPath, x => x.GetInnerText(), false, false); * * foreach (var pairs in contentNodes) * { * if (pairs.Key is Node) * { * pairs.Key.StrokeThinkness = 0; * pairs.Key.StrokeDashArray = "3,3,3,3,3"; * pairs.Key.Stroke = "#999999"; * } * } * * //foreach (NodeGraph graph in allChildren) * //{ * // if (graph.item != null) * // { * * * * // } * * // if (graph.Count() == 0) * // { * * // } * //} */ return(output); }