コード例 #1
0
        public List <List <Node> > PublishAnnotation(DirectedGraph graph, String nodeColor = "#f7941d", NodeDictionaryGraphStyleSettings style = null)
        {
            if (style == null)
            {
                style = new NodeDictionaryGraphStyleSettings();
            }

            Node node = graph.Nodes[XPathRoot];

            node.Background = nodeColor;

            var chunkInfoNode = new Node()
            {
                Id              = name,
                Label           = name,
                Background      = Color.LightGreen.ColorToHex(),
                Foreground      = Color.DarkGray.ColorToHex(),
                Stroke          = nodeColor,
                StrokeThinkness = 0
            };

            graph.Nodes.Add(chunkInfoNode);
            graph.Links.Add(new Link(node, chunkInfoNode)
            {
                StrokeDashArray = "2,2,2,2,2", Stroke = nodeColor
            });

            var allLinked = graph.GetAllLinkedInIterations(node);

            foreach (var iteration in allLinked)
            {
                foreach (var ln in iteration)
                {
                    if (ln != chunkInfoNode)
                    {
                        if (ln.Stroke == style.DynamicStrokeColor)
                        {
                            ln.Background = style.DynamicStrokeColor;
                        }
                        else if (ln.Stroke == style.StaticStrokeColor)
                        {
                            ln.Background = style.StaticStrokeColor;
                        }
                        else if (ln.StrokeDashArray.isNullOrEmpty())
                        {
                            ln.Background = nodeColor;
                        }
                    }
                    else
                    {
                    }
                }
            }
            return(allLinked);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
        }