Пример #1
0
        /// <summary>
        /// Similar to the expandFromPatterns, but performs an exhaustive
        /// search, performing simplifications on the graphs until exhausted.
        /// </summary>
        /// <remarks>
        /// Similar to the expandFromPatterns, but performs an exhaustive
        /// search, performing simplifications on the graphs until exhausted.
        /// TODO: ensure cycles do not occur
        /// NOTE: put in an arbitrary depth limit of 3, to prevent churning way too much (heuristic)
        /// </remarks>
        /// <exception cref="System.Exception"/>
        public virtual ICollection <SemanticGraph> ExhaustFromPatterns(IList <SsurgeonPattern> patternList, SemanticGraph sg)
        {
            ICollection <SemanticGraph> generated = ExhaustFromPatterns(patternList, sg, 1);

            if (generated.Count > 1)
            {
                if (log != null)
                {
                    log.Info("Before remove dupe, size=" + generated.Count);
                }
                generated = SemanticGraphUtils.RemoveDuplicates(generated, sg);
                if (log != null)
                {
                    log.Info("AFTER remove dupe, size=" + generated.Count);
                }
            }
            return(generated);
        }
Пример #2
0
        /// <summary>
        /// Given a list of SsurgeonPattern edit scripts, and a SemanticGraph
        /// to operate over, returns a list of expansions of that graph, with
        /// the result of each edit applied against a copy of the graph.
        /// </summary>
        /// <exception cref="System.Exception"/>
        public virtual IList <SemanticGraph> ExpandFromPatterns(IList <SsurgeonPattern> patternList, SemanticGraph sg)
        {
            IList <SemanticGraph> retList = new List <SemanticGraph>();

            foreach (SsurgeonPattern pattern in patternList)
            {
                ICollection <SemanticGraph> generated = pattern.Execute(sg);
                foreach (SemanticGraph orderedGraph in generated)
                {
                    //orderedGraph.vertexList(true);
                    //orderedGraph.edgeList(true);
                    retList.Add(orderedGraph);
                    System.Console.Out.WriteLine("\ncompact = " + orderedGraph.ToCompactString());
                    System.Console.Out.WriteLine("regular=" + orderedGraph);
                }
                if (generated.Count > 0)
                {
                    if (log != null)
                    {
                        log.Info("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
                        log.Info("Pre remove duplicates, num=" + generated.Count);
                    }
                    SemanticGraphUtils.RemoveDuplicates(generated, sg);
                    if (log != null)
                    {
                        log.Info("Expand from patterns");
                        if (logPrefix != null)
                        {
                            log.Info(logPrefix);
                        }
                        log.Info("Pattern = '" + pattern.GetUID() + "' generated " + generated.Count + " matches");
                        log.Info("= = = = = = = = = =\nSrc graph:\n" + sg + "\n= = = = = = = = = =\n");
                        int index = 1;
                        foreach (SemanticGraph genSg in generated)
                        {
                            log.Info("REWRITE " + (index++));
                            log.Info(genSg.ToString());
                            log.Info(". . . . .\n");
                        }
                    }
                }
            }
            return(retList);
        }