protected TransformedString stem(String words){
  StringBuilder builder=new StringBuilder();
  Map<Integer,Integer> indexMap=new HashMap<>();
  Integer index=0;
  String content=words.toLowerCase();
  while (!content.isEmpty()) {
    indexMap.put(builder.length(),index);
    if (Character.isAlphabetic(content.charAt(0))) {
      Matcher m=WORD_PATTERN.matcher(content);
      m.find();
      String match=m.group();
      CharSequence stemmedMatch=stemmer.stem(match);
      builder.append(stemmedMatch);
      index+=match.length();
      content=content.substring(match.length());
    }
 else {
      builder.append(content.substring(0,1));
      content=content.substring(1);
      index++;
    }
  }
  indexMap.put(builder.length(),index);
  return new TransformedString(words,builder.toString(),indexMap);
}

protected TransformedString stem ( String words ) { StringBuilder builder = new StringBuilder ( ) ; Map < Integer , Integer > indexMap = new HashMap < > ( ) ; Integer index = 0 ; String content = words . toLowerCase ( ) ; while ( ! content . isEmpty ( ) ) { indexMap . put ( builder . length ( ) , index ) ; if ( Character . isAlphabetic ( content . charAt ( 0 ) ) ) { Matcher m = WORD_PATTERN . matcher ( content ) ; m . find ( ) ; String match = m . group ( ) ; CharSequence stemmedMatch = stemmer . stem ( match ) ; builder . append ( stemmedMatch ) ; index += match . length ( ) ; content = content . substring ( match . length ( ) ) ; } else { builder . append ( content . substring ( 0 , 1 ) ) ; content = content . substring ( 1 ) ; index ++ ; } } indexMap . put ( builder . length ( ) , index ) ; return new TransformedString ( words , builder . toString ( ) , indexMap ) ; }
convert a word , or words , into their stemmed form and return it along with a mapping between the original and transformed strings
