public static List<Integer> exactTokenFinderIgnoreCase(final String pattern,
      final String[] tokens) {
    final String[] patternTokens = pattern.split(" ");
    int i, j;
    final int patternLength = patternTokens.length;
    final int sentenceLength = tokens.length;
    final List<Integer> neTokens = new ArrayList<Integer>();
    for (j = 0; j <= sentenceLength - patternLength; ++j) {
      for (i = 0; i < patternLength
          && patternTokens[i].equalsIgnoreCase(tokens[i + j]); ++i) {
        ;
      }
      if (i >= patternLength) {
        neTokens.add(j);
        neTokens.add(i + j);
      }
    }
    return neTokens;
  }
public static List < Integer > exactTokenFinderIgnoreCase ( final String pattern , final String [ ] tokens ) { final String [ ] patternTokens = pattern . split ( " " ) ; int i , j ; final int patternLength = patternTokens . length ; final int sentenceLength = tokens . length ; final List < Integer > neTokens = new ArrayList < Integer > ( ) ; for ( j = 0 ; j <= sentenceLength - patternLength ; ++ j ) { for ( i = 0 ; i < patternLength && patternTokens [ i ] . equalsIgnoreCase ( tokens [ i + j ] ) ; ++ i ) { ; } if ( i >= patternLength ) { neTokens . add ( j ) ; neTokens . add ( i + j ) ; } } return neTokens ; }
Finds a pattern (typically a named entity string) in a tokenized sentence.
It outputs the {@link Span} indexes of the named entity found, if any.

@param pattern
a string to find
@param tokens
an array of tokens
@return token spans of the pattern (e.g. a named entity)