Example #1
0
        private static void exportFst(Fst fst, string text)
        {
            FileWriter  fileWriter  = new FileWriter(text);
            PrintWriter printWriter = new PrintWriter(fileWriter);
            State       start       = fst.getStart();

            printWriter.println(new StringBuilder().append(start.getId()).append("\t").append(start.getFinalWeight()).toString());
            int numStates = fst.getNumStates();

            for (int i = 0; i < numStates; i++)
            {
                State state = fst.getState(i);
                if (state.getId() != fst.getStart().getId())
                {
                    printWriter.println(new StringBuilder().append(state.getId()).append("\t").append(state.getFinalWeight()).toString());
                }
            }
            string[] isyms = fst.getIsyms();
            string[] osyms = fst.getOsyms();
            numStates = fst.getNumStates();
            for (int j = 0; j < numStates; j++)
            {
                State state2  = fst.getState(j);
                int   numArcs = state2.getNumArcs();
                for (int k = 0; k < numArcs; k++)
                {
                    Arc    arc   = state2.getArc(k);
                    string text2 = (isyms == null) ? Integer.toString(arc.getIlabel()) : isyms[arc.getIlabel()];
                    string text3 = (osyms == null) ? Integer.toString(arc.getOlabel()) : osyms[arc.getOlabel()];
                    printWriter.println(new StringBuilder().append(state2.getId()).append("\t").append(arc.getNextState().getId()).append("\t").append(text2).append("\t").append(text3).append("\t").append(arc.getWeight()).toString());
                }
            }
            printWriter.close();
        }
Example #2
0
        private static Fst readFst(ObjectInputStream objectInputStream)
        {
            string[] array    = Fst.readStringMap(objectInputStream);
            string[] array2   = Fst.readStringMap(objectInputStream);
            int      num      = objectInputStream.readInt();
            Semiring semiring = (Semiring)objectInputStream.readObject();
            int      num2     = objectInputStream.readInt();
            Fst      fst      = new Fst(num2);

            fst.isyms    = array;
            fst.osyms    = array2;
            fst.semiring = semiring;
            for (int i = 0; i < num2; i++)
            {
                int   num3  = objectInputStream.readInt();
                State state = new State(num3 + 1);
                float num4  = objectInputStream.readFloat();
                if (num4 == fst.semiring.zero())
                {
                    num4 = fst.semiring.zero();
                }
                else if (num4 == fst.semiring.one())
                {
                    num4 = fst.semiring.one();
                }
                state.setFinalWeight(num4);
                state.id = objectInputStream.readInt();
                fst.states.add(state);
            }
            fst.setStart((State)fst.states.get(num));
            num2 = fst.getNumStates();
            for (int i = 0; i < num2; i++)
            {
                State state2 = fst.getState(i);
                for (int j = 0; j < state2.initialNumArcs - 1; j++)
                {
                    Arc arc = new Arc();
                    arc.setIlabel(objectInputStream.readInt());
                    arc.setOlabel(objectInputStream.readInt());
                    arc.setWeight(objectInputStream.readFloat());
                    arc.setNextState((State)fst.states.get(objectInputStream.readInt()));
                    state2.addArc(arc);
                }
            }
            return(fst);
        }