code: public static Map<String, Integer> createNGrams(String inputQuery, boolean removeStopWords) {
      List<String> wordsInString =
          Lists.newArrayList(Stemmer.replaceIllegalCharacter(inputQuery).split(" "));
      if (removeStopWords) wordsInString.removeAll(STOPWORDSLIST);
      List<String> stemmedWordsInString =
          wordsInString.stream().map(Stemmer::stem).collect(Collectors.toList());
      Map<String, Integer> tokens = new HashMap<>();
      // Padding the string
      for (String singleWord : stemmedWordsInString) {
        if (!StringUtils.isEmpty(singleWord)) {
          // The s$ will be the produced from two words.
          StringBuilder singleString = new StringBuilder(singleWord.length() + 2);
          singleString.append('^').append(singleWord.toLowerCase()).append('$');
          int length = singleString.length();
          for (int i = 0; i < length - 1; i++) {
            String token = null;
            if (i + N_GRAMS < length) {
              token = singleString.substring(i, i + N_GRAMS);
  
            } else {
              token = singleString.substring(length - 2);
            }
  
            if (!tokens.containsKey(token)) {
              tokens.put(token, 1);
            } else {
              tokens.put(token, (tokens.get(token) + 1));
            }
          }
        }
      }
  
      return tokens;
    }
docs: create n-grams tokens of the string.
  
  @return a map of ngram tokens with the corresponding frequency