private void checkDictionary(
      final FusionDictionary dict,
      final List<String> words,
      final SparseArray<List<Integer>> bigrams,
      final HashMap<String, List<String>> shortcutMap) {
    assertNotNull(dict);

    // check unigram
    for (final String word : words) {
      final PtNode ptNode = FusionDictionary.findWordInTree(dict.mRootNodeArray, word);
      assertNotNull(ptNode);
    }

    // check bigram
    for (int i = 0; i < bigrams.size(); ++i) {
      final int w1 = bigrams.keyAt(i);
      for (final int w2 : bigrams.valueAt(i)) {
        final PtNode ptNode = FusionDictionary.findWordInTree(dict.mRootNodeArray, words.get(w1));
        assertNotNull(words.get(w1) + "," + words.get(w2), ptNode.getBigram(words.get(w2)));
      }
    }

    // check shortcut
    if (shortcutMap != null) {
      for (final Entry<String, List<String>> entry : shortcutMap.entrySet()) {
        assertTrue(words.contains(entry.getKey()));
        final PtNode ptNode = FusionDictionary.findWordInTree(dict.mRootNodeArray, entry.getKey());
        for (final String word : entry.getValue()) {
          assertNotNull(
              "shortcut not found: " + entry.getKey() + ", " + word, ptNode.getShortcut(word));
        }
      }
    }
  }
 private void addBigrams(
     final FusionDictionary dict,
     final List<String> words,
     final SparseArray<List<Integer>> bigrams) {
   for (int i = 0; i < bigrams.size(); ++i) {
     final int w1 = bigrams.keyAt(i);
     for (int w2 : bigrams.valueAt(i)) {
       dict.setBigram(words.get(w1), words.get(w2), new ProbabilityInfo(BIGRAM_FREQ));
     }
   }
 }
 /** Adds unigrams to the dictionary. */
 private void addUnigrams(
     final int number,
     final FusionDictionary dict,
     final List<String> words,
     final HashMap<String, List<String>> shortcutMap) {
   for (int i = 0; i < number; ++i) {
     final String word = words.get(i);
     final ArrayList<WeightedString> shortcuts = new ArrayList<>();
     if (shortcutMap != null && shortcutMap.containsKey(word)) {
       for (final String shortcut : shortcutMap.get(word)) {
         shortcuts.add(new WeightedString(shortcut, UNIGRAM_FREQ));
       }
     }
     dict.add(
         word,
         new ProbabilityInfo(UNIGRAM_FREQ),
         (shortcutMap == null) ? null : shortcuts,
         false /* isNotAWord */);
   }
 }