private void addTokGramIndex(String str) {
        String term = '$' + str + '$';
        String kgram = "";
        for (int i = 0; i < str.length(); i++) {
            kgram = term.substring(i, i+3);
            if (!kGramIndex.containsKey(kgram)) {
                ArrayList<String> terms = new ArrayList<>();
                terms.add(str);
                kGramIndex.put(kgram, terms);
            } else if (!kGramIndex.get(kgram).contains(str)) {
                kGramIndex.get(kgram).add(str);
            }
        }     
     }