public static MutableFst reverse ( Fst infst ) { infst . throwIfInvalid ( ) ; MutableFst fst = ExtendFinal . apply ( infst ) ; Semiring semiring = fst . getSemiring ( ) ; MutableFst result = new MutableFst ( fst . getStateCount ( ) , semiring ) ; result . setInputSymbolsAsCopy ( fst . getInputSymbols ( ) ) ; result . setOutputSymbolsAsCopy ( fst . getOutputSymbols ( ) ) ; MutableState [ ] stateMap = initStateMap ( fst , semiring , result ) ; for ( int i = 0 ; i < fst . getStateCount ( ) ; i ++ ) { State oldState = fst . getState ( i ) ; MutableState newState = stateMap [ oldState . getId ( ) ] ; for ( int j = 0 ; j < oldState . getArcCount ( ) ; j ++ ) { Arc oldArc = oldState . getArc ( j ) ; MutableState newNextState = stateMap [ oldArc . getNextState ( ) . getId ( ) ] ; double newWeight = semiring . reverse ( oldArc . getWeight ( ) ) ; result . addArc ( newNextState , oldArc . getIlabel ( ) , oldArc . getOlabel ( ) , newState , newWeight ) ; } } return result ; }
Reverses an fst