예제 #1
0
 public Transformer(FiniteStateTable dfa) {
   this.dfa = dfa;
   flatFST = new FlatFST();
   used = new BitSet(dfa.getTransitionTable().size());
   used.clear();
   statePosition = new int[dfa.getDFA().size()];
 }
예제 #2
0
파일: ReadFST.java 프로젝트: q474818917/FST
  public static void main(String[] args) {

    if (args.length < 1) {
      System.out.printf("ReadFST file.fst\n");
      System.exit(0);
    }

    FiniteStateTable fst = new FiniteStateTable();
    try {

      fst.readFSTFile(args[0]);

      fst.traverseDFA(0, 0, new StringBuilder(), 0, 0);

    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
      ex.printStackTrace();
    }
  }
예제 #3
0
  //
  // transform data structure from DFA+TransitionTable to FlatFST
  //
  void transform() {

    int current = 0;
    int beginning = 0;
    int i;

    // iteration through all states
    for (int state = 0; state < dfa.getDFA().size(); state++) {

      // check all transition space
      current = beginning - 1;
      do {
        do { // find unused space
          for (++current; used.get(current); current++) ;
          // make sure for unused space
        } while ((dfa.ofFinished(state) == true) && flatFST.isUsed(current));

        // check all transition space
        for (i = 0; i < dfa.ofSize(state); i++) {
          if (flatFST.isUsed(current + dfa.ofChar(state, i))) {
            break;
          }
        }
      } while (i < dfa.ofSize(state));

      // copy all transitions into flatfst position
      for (i = 0; i < dfa.ofSize(state); i++) {
        flatFST.put(
            current + dfa.ofChar(state, i),
            new FSTType(dfa.ofChar(state, i), dfa.ofValue(state, i), dfa.ofNext(state, i)));
      }

      if (dfa.ofFinished(state)) {
        flatFST.setFinished(current);
      }

      // set state position
      statePosition[state] = current;
      used.set(current);

      // move beginning position
      for (; used.get(beginning); beginning++) ;
    }
    // free memory
    used = null;

    // most import concept of flatFST
    // combine state(position of FST) and transition
    for (i = 0; i < flatFST.size(); i++) {
      if (flatFST.isUsed(i) && !flatFST.isFinished(i)) {
        flatFST.get(i).next = statePosition[flatFST.get(i).next];
      }
    }
  }