Example #1
0
        /**
         * /// Trims an Fst, removing states and arcs that are not on successful paths.
         * ///
         * /// @param fst the fst to trim
         */
        public static void Apply(Fst fst)
        {
            Semiring semiring = fst.Semiring;

            if (semiring == null)
            {
                Logger.LogInfo <Connect>("Fst has no semiring.");
                return;
            }

            HashSet <State> accessible   = new HashSet <State>();
            HashSet <State> coaccessible = new HashSet <State>();

            List <Arc>[] exploredArcs = new List <Arc> [fst.GetNumStates()];

            List <List <State> > paths = new List <List <State> >();

            paths.Add(new List <State>());

            DepthFirstSearch(fst, accessible, paths, exploredArcs, coaccessible);

            HashSet <State> toDelete = new HashSet <State>();

            for (int i = 0; i < fst.GetNumStates(); i++)
            {
                State s = fst.GetState(i);
                if (!(accessible.Contains(s) || coaccessible.Contains(s)))
                {
                    toDelete.Add(s);
                }
            }

            fst.DeleteStates(toDelete);
        }