final Map<TextSpan, Collection<RareWordTerm>> lookupHitMap ) {
final Collection<TextSpan> discardSpans = new HashSet<TextSpan>();
final List<TextSpan> textSpans = new ArrayList<TextSpan>( lookupHitMap.keySet() );
final int count = textSpans.size();
for ( int i=0; i<count; i++ ) {
final TextSpan spanKeyI = textSpans.get( i );
for ( int j=i+1; j<count; j++ ) {
final TextSpan spanKeyJ = textSpans.get( j );
if ( (spanKeyJ.getStart() <= spanKeyI.getStart() && spanKeyJ.getEnd() > spanKeyI.getEnd())
|| (spanKeyJ.getStart() < spanKeyI.getStart() && spanKeyJ.getEnd() >= spanKeyI.getEnd()) ) {
// J contains I, discard less precise concepts for span I and move on to next span I
if ( spanKeyJ instanceof MultiTextSpan ) {
boolean spanIok = false;
for ( TextSpan missingSpanKey : ((MultiTextSpan)spanKeyJ).getMissingSpans() ) {
if ( (missingSpanKey.getStart() >= spanKeyI.getStart() && missingSpanKey.getStart() < spanKeyI.getEnd())
|| (missingSpanKey.getEnd() > spanKeyI.getStart() && missingSpanKey.getEnd() <= spanKeyI.getEnd()) ) {
// I overlaps a missing span, so it is actually ok
spanIok = true;
break;
}
}
if ( !spanIok ) {
discardSpans.add( spanKeyI );
break;
}
} else {
discardSpans.add( spanKeyI );
break;
}
}
if ( ( (spanKeyI.getStart() <= spanKeyJ.getStart() && spanKeyI.getEnd() > spanKeyJ.getEnd() )
|| (spanKeyI.getStart() < spanKeyJ.getStart() && spanKeyI.getEnd() >= spanKeyJ.getEnd()) ) ) {
// I contains J, discard less precise concepts for span J and move on to next span J
if ( spanKeyI instanceof MultiTextSpan ) {
boolean spanJok = false;
for ( TextSpan missingSpanKey : ((MultiTextSpan)spanKeyI).getMissingSpans() ) {
if ( (missingSpanKey.getStart() >= spanKeyJ.getStart() && missingSpanKey.getStart() < spanKeyJ.getEnd())
|| (missingSpanKey.getEnd() > spanKeyJ.getStart() && missingSpanKey.getEnd() <= spanKeyJ.getEnd()) ) {
// J overlaps a missing span, so it is actually ok
spanJok = true;
break;
}
}