Ocronet.Dynamic.OcroFST.FstUtil.fst_copy_reverse C# (CSharp) Method

fst_copy_reverse() public static method

Reverse the FST's arcs, adding a new start vertex (former accept).
public static fst_copy_reverse ( IGenericFst dst, IGenericFst src, bool no_accept = false ) : void
dst Ocronet.Dynamic.Interfaces.IGenericFst
src Ocronet.Dynamic.Interfaces.IGenericFst
no_accept bool
return void
        public static void fst_copy_reverse(IGenericFst dst, IGenericFst src, bool no_accept = false)
        {
            dst.Clear();
            int n = src.nStates();
            for (int i = 0; i <= n; i++)
                dst.NewState();
            if (!no_accept)
                dst.SetAccept(src.GetStart());
            dst.SetStart(n);
            for (int i = 0; i < n; i++)
            {
                dst.AddTransition(n, i, 0, src.GetAcceptCost(i), 0);
                Intarray targets = new Intarray(), outputs = new Intarray(), inputs = new Intarray();
                Floatarray costs = new Floatarray();
                src.Arcs(inputs, targets, outputs, costs, i);
                if (inputs.Length() != targets.Length())
                    throw new Exception("ASSERT: inputs.length() == targets.length()");
                if (inputs.Length() != outputs.Length())
                    throw new Exception("ASSERT: inputs.length() == outputs.length()");
                if (inputs.Length() != costs.Length())
                    throw new Exception("ASSERT: inputs.length() == costs.length()");
                for (int j = 0; j < inputs.Length(); j++)
                    dst.AddTransition(targets.At1d(j), i, outputs.At1d(j), costs.At1d(j), inputs.At1d(j));
            }
        }

Usage Example

コード例 #1
0
ファイル: AStarUtil.cs プロジェクト: liaoheping/OCRonet
        public static void a_star_backwards(Floatarray costs_for_all_nodes, IGenericFst fst)
        {
            IGenericFst reverse = FstFactory.MakeOcroFST();

            FstUtil.fst_copy_reverse(reverse, fst, true); // creates an extra vertex
            AStarSearch a = new AStarSearch(reverse);

            a.Loop();
            costs_for_all_nodes.Copy(a.g);
            costs_for_all_nodes.Pop(); // remove the extra vertex
        }