Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            /*
             * TransducerGraph fa = new TransducerGraph();
             * fa.addArc(fa.getStartNode(),"1","a","");
             * fa.addArc(fa.getStartNode(),"2","b","");
             * fa.addArc(fa.getStartNode(),"3","c","");
             * fa.addArc("1","4","a","");
             * fa.addArc("2","4","a","");
             * fa.addArc("3","5","c","");
             * fa.addArc("4",fa.getEndNode(),"c","");
             * fa.addArc("5",fa.getEndNode(),"c","");
             * System.out.println(fa);
             * ExactAutomatonMinimizer minimizer = new ExactAutomatonMinimizer();
             * System.out.println(minimizer.minimizeFA(fa));
             */
            System.Console.Out.WriteLine("Starting minimizer test...");
            IList           pathList = new ArrayList();
            TransducerGraph randomFA = TransducerGraph.CreateRandomGraph(5000, 5, 1.0, 5, pathList);
            IList           outputs  = randomFA.GetPathOutputs(pathList);

            TransducerGraph.IGraphProcessor quasiDeterminizer = new QuasiDeterminizer();
            IAutomatonMinimizer             minimizer         = new FastExactAutomatonMinimizer();

            TransducerGraph.INodeProcessor ntsp = new TransducerGraph.SetToStringNodeProcessor(new PennTreebankLanguagePack());
            TransducerGraph.IArcProcessor  isp  = new TransducerGraph.InputSplittingProcessor();
            TransducerGraph.IArcProcessor  ocp  = new TransducerGraph.OutputCombiningProcessor();
            TransducerGraph detGraph            = quasiDeterminizer.ProcessGraph(randomFA);
            TransducerGraph combGraph           = new TransducerGraph(detGraph, ocp);
            // combine outputs into inputs
            TransducerGraph result = minimizer.MinimizeFA(combGraph);

            // minimize the thing
            System.Console.Out.WriteLine("Minimized from " + randomFA.GetNodes().Count + " to " + result.GetNodes().Count);
            result = new TransducerGraph(result, ntsp);
            // pull out strings from sets returned by minimizer
            result = new TransducerGraph(result, isp);
            // split outputs from inputs
            IList minOutputs = result.GetPathOutputs(pathList);

            System.Console.Out.WriteLine("Equal? " + outputs.Equals(minOutputs));
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            TransducerGraph.IGraphProcessor qd = new QuasiDeterminizer();
            IList           pathList           = new ArrayList();
            TransducerGraph graph = TransducerGraph.CreateRandomGraph(1000, 10, 1.0, 10, pathList);
            StringBuilder   b     = new StringBuilder();

            graph.DepthFirstSearch(true, b);
            System.Console.Out.WriteLine(b.ToString());
            System.Console.Out.WriteLine("Done creating random graph");
            //    TransducerGraph.printPathOutputs(pathList, graph, false);
            //System.out.println("Depth first search from start node");
            //TransducerGraph.depthFirstSearch(graph, TransducerGraph.END_NODE, new HashSet(), 0, false);
            TransducerGraph newGraph = qd.ProcessGraph(graph);

            System.Console.Out.WriteLine("Done quasi-determinizing");
            //TransducerGraph.printPathOutputs(pathList, newGraph, false);
            //System.out.println("Depth first search from start node");
            //TransducerGraph.depthFirstSearch(newGraph, TransducerGraph.END_NODE, new HashSet(), 0, false);
            TransducerGraph.TestGraphPaths(graph, newGraph, 1000);
        }