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); }
public static Fst importFst(string basename, Semiring semiring) { Fst fst = new Fst(semiring); HashMap hashMap = Convert.importSymbols(new StringBuilder().append(basename).append(".input.syms").toString()); if (hashMap == null) { hashMap = new HashMap(); hashMap.put("<eps>", Integer.valueOf(0)); } HashMap hashMap2 = Convert.importSymbols(new StringBuilder().append(basename).append(".output.syms").toString()); if (hashMap2 == null) { hashMap2 = new HashMap(); hashMap2.put("<eps>", Integer.valueOf(0)); } HashMap hashMap3 = Convert.importSymbols(new StringBuilder().append(basename).append(".states.syms").toString()); FileInputStream fileInputStream = new FileInputStream(new StringBuilder().append(basename).append(".fst.txt").toString()); DataInputStream dataInputStream = new DataInputStream(fileInputStream); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataInputStream, "UTF-8")); int num = 1; HashMap hashMap4 = new HashMap(); string text; while ((text = bufferedReader.readLine()) != null) { string[] array = String.instancehelper_split(text, "\\t"); Integer integer; if (hashMap3 == null) { integer = Integer.valueOf(Integer.parseInt(array[0])); } else { integer = (Integer)hashMap3.get(array[0]); } State state = (State)hashMap4.get(integer); if (state == null) { state = new State(semiring.zero()); fst.addState(state); hashMap4.put(integer, state); } if (num != 0) { num = 0; fst.setStart(state); } if (array.Length > 2) { Integer integer2; if (hashMap3 == null) { integer2 = Integer.valueOf(Integer.parseInt(array[1])); } else { integer2 = (Integer)hashMap3.get(array[1]); } State state2 = (State)hashMap4.get(integer2); if (state2 == null) { state2 = new State(semiring.zero()); fst.addState(state2); hashMap4.put(integer2, state2); } if (hashMap.get(array[2]) == null) { hashMap.put(array[2], Integer.valueOf(hashMap.size())); } int iLabel = ((Integer)hashMap.get(array[2])).intValue(); if (hashMap2.get(array[3]) == null) { hashMap2.put(array[3], Integer.valueOf(hashMap2.size())); } int oLabel = ((Integer)hashMap2.get(array[3])).intValue(); float weight; if (array.Length > 4) { weight = Float.parseFloat(array[4]); } else { weight = 0f; } Arc arc = new Arc(iLabel, oLabel, weight, state2); state.addArc(arc); } else if (array.Length > 1) { float finalWeight = Float.parseFloat(array[1]); state.setFinalWeight(finalWeight); } else { state.setFinalWeight(0f); } } dataInputStream.close(); fst.setIsyms(Utils.toStringArray(hashMap)); fst.setOsyms(Utils.toStringArray(hashMap2)); return(fst); }