static < INN extends CoreMap & HasWord > void mergeTwoDocuments ( List < INN > mainDocument , List < INN > auxDocument , Set < String > auxLabels , String background ) { boolean insideAuxTag = false ; boolean auxTagValid = true ; String prevAnswer = background ; Collection < INN > constituents = new ArrayList < INN > ( ) ; Iterator < INN > auxIterator = auxDocument . listIterator ( ) ; for ( INN wMain : mainDocument ) { String mainAnswer = wMain . get ( AnswerAnnotation . class ) ; INN wAux = auxIterator . next ( ) ; String auxAnswer = wAux . get ( AnswerAnnotation . class ) ; boolean insideMainTag = ! mainAnswer . equals ( background ) ; /* if the auxiliary classifier gave it one of the labels unique to auxClassifier, we might set the mainLabel to that. */ if ( auxLabels . contains ( auxAnswer ) && ! auxAnswer . equals ( background ) ) { //AZ not equal background symbol (it is background symbol not strong class) if ( ! prevAnswer . equals ( auxAnswer ) && ! prevAnswer . equals ( background ) ) { if ( auxTagValid ) { for ( INN wi : constituents ) { wi . set ( AnswerAnnotation . class , prevAnswer ) ; } } constituents = new ArrayList < INN > ( ) ; } insideAuxTag = true ; if ( insideMainTag ) { auxTagValid = false ; } prevAnswer = auxAnswer ; constituents . add ( wMain ) ; } else { if ( insideAuxTag ) { if ( auxTagValid ) { for ( INN wi : constituents ) { wi . set ( AnswerAnnotation . class , prevAnswer ) ; } } constituents = new ArrayList < INN > ( ) ; } insideAuxTag = false ; auxTagValid = true ; prevAnswer = background ; } } // deal with a sequence final auxLabel if ( auxTagValid ) { for ( INN wi : constituents ) { wi . set ( AnswerAnnotation . class , prevAnswer ) ; } } }
This merges in labels from the auxDocument into the mainDocument when tokens have one of the labels in auxLabels and the subsequence labeled with this auxLabel does not conflict with any non - background labelling in the mainDocument .