src/test/java/de/dfki/lt/loot/fsa/TestMinimization.java
public int[] readFromText(String text, CharFsa fsa) {
    Map<Integer, Integer> stateMap = new HashMap<Integer, Integer>();

    String[] lines = text.split("%");

    // first line contains the initial state
    int initialState = Integer.parseInt(lines[0]);
    stateMap.put(initialState, getNewState(fsa, initialState, stateMap));
    fsa.setInitialState(getNewState(fsa, initialState, stateMap));

    String line;
    int l = 1;
    int edgeCount = 0;
    while (true) {
      // read edges
      line = lines[l++];
      String[] edgeParts = line.split(" ");
      if (edgeParts.length != 3) {
        // all edges have been read
        break;
      }
      edgeCount++;
      int startState = Integer.parseInt(edgeParts[0]);
      int endState = Integer.parseInt(edgeParts[2]);
      String label = edgeParts[1];
      fsa.newEdge(
        label.charAt(0),
        getNewState(fsa, startState, stateMap),
        getNewState(fsa, endState, stateMap));
    }

    // read final states;
    // line already contains the first final state
    fsa.setFinalState(getNewState(fsa, Integer.parseInt(line), stateMap));
    int finalStatesCount = 1;
    while (l < lines.length) {
      line = lines[l++];
      fsa.setFinalState(getNewState(fsa, Integer.parseInt(line), stateMap));
      finalStatesCount++;
    }
    //fsa.makeTotal();

    int [] result = { stateMap.size(), edgeCount, finalStatesCount };
    return result;
  }
/**
   * Initializes this automaton from text based format at the given path.
   *
   * @param textPath
   *          the path from where to read the text
   * @throws IOException
   */
Initializes this automaton from text based format at the given path.
@param textPath
the path from where to read the text
@throws IOException
Initializes this automaton from text based format at the given path . @param textPath the path from where to read the text @throws IOException
public int[] readFromText(String text, CharFsa fsa) {
    Map<Integer, Integer> stateMap = new HashMap<Integer, Integer>();
    String[] lines = text.split("%");
    int initialState = Integer.parseInt(lines[0]);
    stateMap.put(initialState, getNewState(fsa, initialState, stateMap));
    fsa.setInitialState(getNewState(fsa, initialState, stateMap));
    String line;
    int l = 1;
    int edgeCount = 0;
    while (true) {
      line = lines[l++];
      String[] edgeParts = line.split(" ");
      if (edgeParts.length != 3) {
        break;
      }
      edgeCount++;
      int startState = Integer.parseInt(edgeParts[0]);
      int endState = Integer.parseInt(edgeParts[2]);
      String label = edgeParts[1];
      fsa.newEdge(
        label.charAt(0),
        getNewState(fsa, startState, stateMap),
        getNewState(fsa, endState, stateMap));
    }
    fsa.setFinalState(getNewState(fsa, Integer.parseInt(line), stateMap));
    int finalStatesCount = 1;
    while (l < lines.length) {
      line = lines[l++];
      fsa.setFinalState(getNewState(fsa, Integer.parseInt(line), stateMap));
      finalStatesCount++;
    }
    int [] result = { stateMap.size(), edgeCount, finalStatesCount };
    return result;
  }
public int [ ] readFromText ( String text , CharFsa fsa ) { Map < Integer , Integer > stateMap = new HashMap < Integer , Integer > ( ) ; String [ ] lines = text . split ( "%" ) ; int initialState = Integer . parseInt ( lines [ 0 ] ) ; stateMap . put ( initialState , getNewState ( fsa , initialState , stateMap ) ) ; fsa . setInitialState ( getNewState ( fsa , initialState , stateMap ) ) ; String line ; int l = 1 ; int edgeCount = 0 ; while ( true ) { line = lines [ l ++ ] ; String [ ] edgeParts = line . split ( " " ) ; if ( edgeParts . length != 3 ) { break ; } edgeCount ++ ; int startState = Integer . parseInt ( edgeParts [ 0 ] ) ; int endState = Integer . parseInt ( edgeParts [ 2 ] ) ; String label = edgeParts [ 1 ] ; fsa . newEdge ( label . charAt ( 0 ) , getNewState ( fsa , startState , stateMap ) , getNewState ( fsa , endState , stateMap ) ) ; } fsa . setFinalState ( getNewState ( fsa , Integer . parseInt ( line ) , stateMap ) ) ; int finalStatesCount = 1 ; while ( l < lines . length ) { line = lines [ l ++ ] ; fsa . setFinalState ( getNewState ( fsa , Integer . parseInt ( line ) , stateMap ) ) ; finalStatesCount ++ ; } int [ ] result = { stateMap . size ( ) , edgeCount , finalStatesCount } ; return result ; }
Initializes this automaton from text based format at the given path.
Initializes this automaton from text based format at the given path .
// first line contains the initial state // read edges // all edges have been read // read final states; // line already contains the first final state //fsa.makeTotal();