private static List<String> rewriteBrute(String term){
  List<String> queryList=new ArrayList<>();
  for (int i=1; i < term.length(); i++) {
    String prefixString=term.substring(0,i);
    if (wordBase.contains(prefixString)) {
      prefixString=prefixString.concat(" ");
      String suffixString=term.substring(i,term.length());
      List<String> suffixList=rewriteBrute(suffixString);
      for (int j=0; j < suffixList.size(); j++)       suffixList.set(j,prefixString.concat(suffixList.get(j)));
      queryList.addAll(suffixList);
    }
  }
  if (wordBase.contains(term))   queryList.add(term);
  return queryList;
}

private static List < String > rewriteBrute ( String term ) { List < String > queryList = new ArrayList < > ( ) ; for ( int i = 1 ; i < term . length ( ) ; i ++ ) { String prefixString = term . substring ( 0 , i ) ; if ( wordBase . contains ( prefixString ) ) { prefixString = prefixString . concat ( " " ) ; String suffixString = term . substring ( i , term . length ( ) ) ; List < String > suffixList = rewriteBrute ( suffixString ) ; for ( int j = 0 ; j < suffixList . size ( ) ; j ++ ) suffixList . set ( j , prefixString . concat ( suffixList . get ( j ) ) ) ; queryList . addAll ( suffixList ) ; } } if ( wordBase . contains ( term ) ) queryList . add ( term ) ; return queryList ; }
main recursive algorithm to find possible query strings that original term can be mapped to assumes original term may have a tokenization mistake due to missing multiple space delimiters tries to find all possible valid prefixes of original term as per word knowledge base for each prefix , sends rest of string to a recursive call to get all possible rewritten suffixes attaches prefix term in front of each rewritten suffix in the list returns final term list
