class HomophoneOccurrenceDumper extends LuceneSingleIndexLanguageModel {

  private static final int MIN_COUNT = 1000;

  HomophoneOccurrenceDumper(File topIndexDir) throws IOException {
    super(topIndexDir);
  }

  /**
   * Get the context (left and right words) for the given word(s). This is slow,
   * as it needs to scan the whole index.
   */
  Map<String,Long> getContext(String... tokens) throws IOException {
    Objects.requireNonNull(tokens);
    TermsEnum iterator = getIterator();
    Map<String,Long> result = new HashMap<>();
    BytesRef byteRef;
    int i = 0;
    while ((byteRef = iterator.next()) != null) {
      String term = new String(byteRef.bytes, byteRef.offset, byteRef.length);
      for (String token : tokens) {
        if (term.contains(" " + token + " ")) {
          String[] split = term.split(" ");
          if (split.length == 3) {
            long count = getCount(Arrays.asList(split[0], split[1], split[2]));
            result.put(term, count);
          }
        }
      }
      /*if (i++ > 1_000_000) { // comment in for faster testing with subsets of the data
        break;
      }*/
    }
    return result;
  }

  private void run(String confusionSetPath) throws IOException {
    System.err.println("Loading confusion sets from " + confusionSetPath + ", minimum occurrence: " + MIN_COUNT);
    ConfusionSetLoader confusionSetLoader = new ConfusionSetLoader(new AmericanEnglish());
    InputStream inputStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(confusionSetPath);
    Map<String,List<ConfusionPair>> map = confusionSetLoader.loadConfusionPairs(inputStream);
    Set<String> confusionTerms = map.keySet();
    dumpOccurrences(confusionTerms);
  }

  private void dumpOccurrences(Set<String> tokens) throws IOException {
    Objects.requireNonNull(tokens);
    TermsEnum iterator = getIterator();
    BytesRef byteRef;
    int i = 0;
    while ((byteRef = iterator.next()) != null) {
      String term = new String(byteRef.bytes, byteRef.offset, byteRef.length);
      String[] split = term.split(" ");
      if (split.length == 3) {
        String token = split[1];
        if (tokens.contains(token)) {
          long count = getCount(Arrays.asList(split[0], split[1], split[2]));
          if (count >= MIN_COUNT) {
            System.out.println(token + "\t" + count + "\t" + split[0] + " " + split[1] + " " + split[2]);
          }
        }
      }
      if (i % 10_000 == 0) {
        System.err.println(i + "...");
      }
      i++;
    }
  }

  private TermsEnum getIterator() throws IOException {
    LuceneSearcher luceneSearcher = getLuceneSearcher(3);
    Fields fields = MultiFields.getFields(luceneSearcher.getReader());
    Terms terms = fields.terms("ngram");
    return terms.iterator();
  }

  public static void main(String[] args) throws IOException {<FILL_FUNCTION_BODY>}

  @Override
  public long getTotalTokenCount() {
    throw new RuntimeException("not implemented");
  }
}

    if (args.length != 1) {
      System.out.println("Usage: " + HomophoneOccurrenceDumper.class.getSimpleName() + " <indexDir>");
      System.exit(1);
    }
    try (HomophoneOccurrenceDumper dumper = new HomophoneOccurrenceDumper(new File(args[0]))) {
      dumper.run("/en/confusion_sets.txt");
    }
  
<methods>public void <init>(java.io.File) ,public void <init>(int) ,public static void clearCaches() ,public void close() ,public long getCount(List<java.lang.String>) ,public long getCount(java.lang.String) ,public long getTotalTokenCount() ,public java.lang.String toString() ,public static void validateDirectory(java.io.File) <variables>private static final Map<java.io.File,org.languagetool.languagemodel.LuceneSingleIndexLanguageModel.LuceneSearcher> dirToSearcherMap,private final List<java.io.File> indexes,private final Map<java.lang.Integer,org.languagetool.languagemodel.LuceneSingleIndexLanguageModel.LuceneSearcher> luceneSearcherMap,private final non-sealed long maxNgram,private final non-sealed java.io.File topIndexDir