src/main/java/de/dfki/lt/loot/fsa/FiniteAutomaton.java
public SubAutomaton optional(SubAutomaton sub) {

    // create new initial and final states
    int newInitialState = this.newVertex();
    int newFinalState = this.newVertex();

    // connect new initial and final state with an epsilon transition
    newEdge(EPSILON, newInitialState, newFinalState);
    // connect the old final state to the new final state with epsilon
    // transitions
    newEdge(EPSILON, sub.getFinalState(), newFinalState);
    // connect the new initial state to the former initial state
    newEdge(EPSILON, newInitialState, sub.getInitialState());

    // update initial state and final state
    sub.setInitialState(newInitialState);
    sub.setFinalState(newFinalState);

    return sub;
  }
/**
   * Modifies the given subautomaton in a way that it optionally matches the
   * char sequences it matches now.
   *
   * @param sub
   *          a subautomaton to wrap with a question mark
   * @return the modified subautomaton with the question mark
   */
Modifies the given subautomaton in a way that it optionally matches the
char sequences it matches now.

@param sub
a subautomaton to wrap with a question mark
@return the modified subautomaton with the question mark
Modifies the given subautomaton in a way that it optionally matches the char sequences it matches now . @param sub a subautomaton to wrap with a question mark @return the modified subautomaton with the question mark
public SubAutomaton optional(SubAutomaton sub) {
    int newInitialState = this.newVertex();
    int newFinalState = this.newVertex();
    newEdge(EPSILON, newInitialState, newFinalState);
    newEdge(EPSILON, sub.getFinalState(), newFinalState);
    newEdge(EPSILON, newInitialState, sub.getInitialState());
    sub.setInitialState(newInitialState);
    sub.setFinalState(newFinalState);
    return sub;
  }
public SubAutomaton optional ( SubAutomaton sub ) { int newInitialState = this . newVertex ( ) ; int newFinalState = this . newVertex ( ) ; newEdge ( EPSILON , newInitialState , newFinalState ) ; newEdge ( EPSILON , sub . getFinalState ( ) , newFinalState ) ; newEdge ( EPSILON , newInitialState , sub . getInitialState ( ) ) ; sub . setInitialState ( newInitialState ) ; sub . setFinalState ( newFinalState ) ; return sub ; }
Modifies the given subautomaton in a way that it optionally matches the
 char sequences it matches now.
Modifies the given subautomaton in a way that it optionally matches the char sequences it matches now .
// create new initial and final states // connect new initial and final state with an epsilon transition // connect the old final state to the new final state with epsilon // transitions // connect the new initial state to the former initial state // update initial state and final state