public static MutableFst remove ( Fst fst ) { Preconditions . checkNotNull ( fst ) ; Preconditions . checkNotNull ( fst . getSemiring ( ) ) ; Semiring semiring = fst . getSemiring ( ) ; MutableFst result = MutableFst . emptyWithCopyOfSymbols ( fst ) ; int iEps = fst . getInputSymbols ( ) . get ( Fst . EPS ) ; int oEps = fst . getOutputSymbols ( ) . get ( Fst . EPS ) ; @ SuppressWarnings ( "unchecked" ) HashMap < Integer , Double > [ ] closure = new HashMap [ fst . getStateCount ( ) ] ; MutableState [ ] oldToNewStateMap = new MutableState [ fst . getStateCount ( ) ] ; State [ ] newToOldStateMap = new State [ fst . getStateCount ( ) ] ; initResultStates ( fst , result , oldToNewStateMap , newToOldStateMap ) ; addNonEpsilonArcs ( fst , result , iEps , oEps , closure , oldToNewStateMap ) ; // augment fst with arcs generated from epsilon moves. for ( int i = 0 ; i < result . getStateCount ( ) ; i ++ ) { MutableState state = result . getState ( i ) ; State oldState = newToOldStateMap [ state . getId ( ) ] ; if ( closure [ oldState . getId ( ) ] == null ) { continue ; } for ( Integer pathFinalStateIndex : closure [ oldState . getId ( ) ] . keySet ( ) ) { State closureState = fst . getState ( pathFinalStateIndex ) ; if ( semiring . isNotZero ( closureState . getFinalWeight ( ) ) ) { Double prevWeight = getPathWeight ( oldState , closureState , closure ) ; Preconditions . checkNotNull ( prevWeight , "problem with prev weight on closure from %s" , oldState ) ; state . setFinalWeight ( semiring . plus ( state . getFinalWeight ( ) , semiring . times ( prevWeight , closureState . getFinalWeight ( ) ) ) ) ; } for ( int j = 0 ; j < closureState . getArcCount ( ) ; j ++ ) { Arc arc = closureState . getArc ( j ) ; if ( ( arc . getIlabel ( ) != iEps ) || ( arc . getOlabel ( ) != oEps ) ) { Double pathWeight = getPathWeight ( oldState , closureState , closure ) ; Preconditions . checkNotNull ( pathWeight , "problem with prev weight on closure from %s" , oldState ) ; double newWeight = semiring . times ( arc . getWeight ( ) , pathWeight ) ; MutableState nextState = oldToNewStateMap [ arc . getNextState ( ) . getId ( ) ] ; result . addArc ( state , arc . getIlabel ( ) , arc . getOlabel ( ) , nextState , newWeight ) ; } } } } Connect . apply ( result ) ; ArcSort . sortByInput ( result ) ; return result ; }
Removes epsilon transitions from an fst . Returns a new epsilon - free fst and does not modify the original fst