Exemple #1
0
        private static void PrintTrieDFSAHelper <T, S>(DFSAState <T, S> state, int level)
        {
            if (state.IsAccepting())
            {
                return;
            }
            ICollection <T> inputs = state.ContinuingInputs();

            foreach (T input in inputs)
            {
                DFSATransition <T, S> transition = state.Transition(input);
                System.Console.Out.Write(level);
                System.Console.Out.Write(input);
                for (int i = 0; i < level; i++)
                {
                    System.Console.Out.Write("   ");
                }
                System.Console.Out.Write(transition.Score());
                System.Console.Out.Write(" ");
                System.Console.Out.WriteLine(input);
                PrintTrieDFSAHelper(transition.Target(), level + 1);
            }
        }
Exemple #2
0
        /// <exception cref="System.IO.IOException"/>
        public void PrintAttFsmFormat(TextWriter w)
        {
            IQueue <DFSAState <T, S> >      q       = new LinkedList <DFSAState <T, S> >();
            ICollection <DFSAState <T, S> > visited = Generics.NewHashSet();

            q.Offer(initialState);
            while (q.Peek() != null)
            {
                DFSAState <T, S> state = q.Poll();
                if (state == null || visited.Contains(state))
                {
                    continue;
                }
                visited.Add(state);
                if (state.IsAccepting())
                {
                    w.Write(state.ToString() + "\t" + state.Score() + "\n");
                    continue;
                }
                TreeSet <T> inputs = new TreeSet <T>(state.ContinuingInputs());
                foreach (T input in inputs)
                {
                    DFSATransition <T, S> transition = state.Transition(input);
                    DFSAState <T, S>      target     = transition.Target();
                    if (!visited.Contains(target))
                    {
                        q.Add(target);
                    }
                    w.Write(state.ToString() + "\t" + target.ToString() + "\t" + transition.GetInput() + "\t" + transition.Score() + "\n");
                }
            }
        }