private static void augment ( AugmentLabels label , MutableFst fst , Semiring semiring , String eps1 , String eps2 ) { // label: 0->augment on ilabel // 1->augment on olabel int e1inputIndex = fst . getInputSymbols ( ) . getOrAdd ( eps1 ) ; int e2inputIndex = fst . getInputSymbols ( ) . getOrAdd ( eps2 ) ; int e1outputIndex = fst . getOutputSymbols ( ) . getOrAdd ( eps1 ) ; int e2outputIndex = fst . getOutputSymbols ( ) . getOrAdd ( eps2 ) ; int iEps = fst . getInputSymbols ( ) . get ( Fst . EPS ) ; int oEps = fst . getOutputSymbols ( ) . get ( Fst . EPS ) ; int numStates = fst . getStateCount ( ) ; for ( int i = 0 ; i < numStates ; i ++ ) { MutableState s = fst . getState ( i ) ; for ( MutableArc arc : s . getArcs ( ) ) { if ( ( label == AugmentLabels . OUTPUT ) && ( arc . getOlabel ( ) == oEps ) ) { arc . setOlabel ( e2outputIndex ) ; } else if ( ( label == AugmentLabels . INPUT ) && ( arc . getIlabel ( ) == iEps ) ) { arc . setIlabel ( e1inputIndex ) ; } } if ( label == AugmentLabels . INPUT ) { fst . addArc ( s , e2inputIndex , oEps , s , semiring . one ( ) ) ; } else if ( label == AugmentLabels . OUTPUT ) { fst . addArc ( s , iEps , e1outputIndex , s , semiring . one ( ) ) ; } } }
Augments the labels of an Fst in order to use it for composition avoiding multiple epsilon paths in the resulting Fst