@ Override public GallicWeight commonDivisor ( GallicWeight a , GallicWeight b ) { double newWeight = this . weightSemiring . plus ( a . getWeight ( ) , b . getWeight ( ) ) ; if ( isZero ( a ) ) { if ( isZero ( b ) ) { return zero ; } if ( b . getLabels ( ) . isEmpty ( ) ) { return GallicWeight . create ( GallicWeight . EMPTY , newWeight ) ; } // just the first char of b return GallicWeight . createSingleLabel ( b . getLabels ( ) . get ( 0 ) , newWeight ) ; } else if ( isZero ( b ) ) { if ( a . getLabels ( ) . isEmpty ( ) ) { return GallicWeight . create ( GallicWeight . EMPTY , newWeight ) ; } // just the first char of a return GallicWeight . createSingleLabel ( a . getLabels ( ) . get ( 0 ) , newWeight ) ; } else { // neither are zero, emit one char if they share it, otherwise empty if ( a . getLabels ( ) . isEmpty ( ) || b . getLabels ( ) . isEmpty ( ) ) { return GallicWeight . create ( GallicWeight . EMPTY , newWeight ) ; } if ( a . getLabels ( ) . get ( 0 ) == b . getLabels ( ) . get ( 0 ) ) { return GallicWeight . createSingleLabel ( a . getLabels ( ) . get ( 0 ) , newWeight ) ; } return GallicWeight . create ( GallicWeight . EMPTY , newWeight ) ; } }
In this gallic semiring we restrict the common divisor to only be the first character in the stringweight In more general real - time FSTs that support substrings this could be longer but openfst doesn t support this and we don t support this