public static Set<String> subparts(String word,int nMin,int nMax){
  Set<String> subparts=new HashSet<String>();
  for (int n=nMin; n <= nMax; n++) {
    for (int i=0; i < word.length(); i++) {
      StringBuilder builder=new StringBuilder();
      String w=word.substring(i,Math.min(i + n,word.length()));
      for (      char c : w.toCharArray()) {
        builder.append(escape(c));
      }
      subparts.add(builder.toString());
    }
  }
  return subparts;
}

public static Set < String > subparts ( String word , int nMin , int nMax ) { Set < String > subparts = new HashSet < String > ( ) ; for ( int n = nMin ; n <= nMax ; n ++ ) { for ( int i = 0 ; i < word . length ( ) ; i ++ ) { StringBuilder builder = new StringBuilder ( ) ; String w = word . substring ( i , Math . min ( i + n , word . length ( ) ) ) ; for ( char c : w . toCharArray ( ) ) { builder . append ( escape ( c ) ) ; } subparts . add ( builder . toString ( ) ) ; } } return subparts ; }
returns a set with all n - grams ; nmin < = n < = nmax
