/**
   * Loads words from a given {@link IResource} (UTF-8, one word per line, #-starting lines are
   * considered comments).
   */
  public static HashSet<String> load(IResource resource) throws IOException {
    final HashSet<String> words = Sets.newHashSet();

    final InputStream is = resource.open();
    if (is == null) throw new IOException("Resource returned null stream: " + resource);

    final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

    try {

      String line;
      while ((line = reader.readLine()) != null) {
        line = line.trim();
        if (line.startsWith("#") || line.length() == 0) {
          continue;
        }

        words.add(line);
      }
    } finally {
      reader.close();
    }

    return words;
  }
  public static Set<String> collectClusterLabels(ProcessingResult pr) {
    final Set<String> clusterLabels = Sets.newHashSet();
    new Cloneable() {
      public void dumpClusters(List<Cluster> clusters, int depth) {
        for (Cluster c : clusters) {
          clusterLabels.add(c.getLabel());
          if (c.getSubclusters() != null) {
            dumpClusters(c.getSubclusters(), depth + 1);
          }
        }
      }
    }.dumpClusters(pr.getClusters(), 0);

    return clusterLabels;
  }