Ejemplo n.º 1
0
        public void Execute(CGGraph graph)
        {
            List <CGNode> deletes = new List <CGNode>();

            foreach (var node in graph.Nodes)
            {
                if (node.text == "null_tag")
                {
                    deletes.Add(node);
                    foreach (var inR in graph.Relations.Where(c => c.Head == node.id).ToList())
                    {
                        graph.RemoveRelation(inR);
                    }
                    foreach (var outR in graph.Relations.Where(c => c.Tail == node.id).ToList())
                    {
                        graph.RemoveRelation(outR);
                    }
                }
            }
            foreach (var item in deletes)
            {
                graph.RemoveNode(item);
            }
        }
Ejemplo n.º 2
0
        private void GraphFusion(CGGraph graph, IEnumerable <IGrouping <string, CGNode> > groups)
        {
            foreach (var g in groups)
            {
                //survivor
                List <CGNode>     deletes           = new List <CGNode>();
                List <CGRelation> relations_deletes = new List <CGRelation>();
                List <CGRelation> relations_news    = new List <CGRelation>();

                var max = g.OrderByDescending(c => c.rstweight).First();
                foreach (var node in g)
                {
                    if (node.id == max.id)
                    {
                        continue;
                    }
                    max.AddFusionNode(node);
                    deletes.Add(node);
                }
                foreach (var node in g)
                {
                    if (node.id == max.id)
                    {
                        continue;
                    }

                    var inrelations = from c in graph.Relations where c.Tail == node.id select c;
                    foreach (var item in inrelations)
                    {
                        var n = item.Clone();
                        n.Tail = max.id;
                        relations_deletes.Add(item);

                        if (deletes.Where(c => c.id == n.Head).Count() == 0)
                        {
                            relations_news.Add(n);
                        }
                    }
                    var outrelations = from c in graph.Relations where c.Head == node.id select c;
                    foreach (var item in outrelations)
                    {
                        var n = item.Clone();
                        n.Head = max.id;
                        relations_deletes.Add(item);
                        if (deletes.Where(c => c.id == n.Tail).Count() == 0)
                        {
                            relations_news.Add(n);
                        }
                    }
                }
                foreach (var item in relations_deletes)
                {
                    graph.RemoveRelation(item);
                }
                foreach (var item in relations_news)
                {
                    graph.AddRelation(item);
                }

                foreach (var item in deletes)
                {
                    graph.RemoveNode(item);
                }
            }
        }