Esempio n. 1
0
  /* Dendrograms... */
  public int makeDendrograms(File root, Cluster clustering) throws jplag.ExitException {
    HTMLFile f = this.program.report.openHTMLFile(root, "dendro.html");
    f.println("<!DOCTYPE HTML PUBLIC \"-//DTD HTML 3.2//EN\">");
    f.println(
        "<HTML>\n<HEAD>\n<TITLE>"
            + msg.getString("Clusters.Dendrogram")
            + "</TITLE>\n"
            + "<script language=\"JavaScript\" type=\"text/javascript\" "
            + "src=\"fields.js\">\n</script>\n</HEAD>\n<BODY>");
    f.println("<H1>" + msg.getString("Clusters.Dendrogram") + "</H1>");

    f.println("<form name=\"data\" action=\"\">");
    f.println("<table border=\"0\">");
    f.println(
        "<tr><td>"
            + msg.getString("Clusters.Cluster_size")
            + ":</td>"
            + "<td><input type=\"text\" readonly name=\"size\" size=\"5\"></td>");
    f.println(
        "<td rowspan=\"3\">"
            + msg.getString("Clusters.Themewords")
            + ":</td><td rowspan=\"3\"><textarea cols=\"80\" rows=\"3\" readonly "
            + "name=\"theme\"></textarea></td></tr>");
    f.println(
        "<tr><td>"
            + msg.getString("Clusters.Threshold")
            + ":</td><td><input type=\"text\" readonly name=\"thresh\" "
            + "size=\"6\"></td></tr>");
    f.println(
        "<tr><td>"
            + msg.getString("Clusters.Documents")
            + ":</td><td><input type=\"text\" readonly name=\"docs\" "
            + "size=\"30\"></td></tr>");
    f.println("</table>\n</form>");

    f.println(paintDendrogram(new File(root, "dendro.gif"), clustering));
    f.println(
        "<P><IMG SRC=\"dendro.gif\" ALT=\""
            + msg.getString("Clusters.Dendrogram_picture")
            + "\" USEMAP=\"#Dendrogram\"></P>");
    f.println("</BODY>\n</HTML>");
    f.close();
    return f.bytesWritten();
  }
Esempio n. 2
0
  /** This method returns the distribution HTML code as a string */
  private String outputClustering(HTMLFile f, Collection<Cluster> allClusters, int maxSize) {
    int[] distribution = new int[maxSize + 1];
    int max = 0;
    for (int i = 0; i <= maxSize; i++) distribution[i] = 0;

    // Now output the clustering:
    f.println("<TABLE CELLPADDING=2 CELLSPACING=2>");

    f.println(
        "<TR><TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Cluster_number")
            + "<TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Size")
            + "<TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Threshold")
            + "<TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Cluster_members")
            + "<TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Most_frequent_words")
            + "</TR>");
    Iterator<Cluster> clusterI = allClusters.iterator();
    for (int i = 1; clusterI.hasNext(); i++) {
      Cluster cluster = clusterI.next();
      if (max < ++distribution[cluster.size()]) max = distribution[cluster.size()];

      // no singleton clusters
      if (cluster.size() == 1) continue;

      f.print(
          "<TR><TD ALIGN=center BGCOLOR=#8080ff>"
              + i
              + "<TD ALIGN=center BGCOLOR=#c0c0ff>"
              + cluster.size()
              + "<TD ALIGN=center BGCOLOR=#c0c0ff>"
              + cluster.getSimilarity()
              + "<TD ALIGN=left BGCOLOR=#c0c0ff>");

      // sort names
      TreeSet<Submission> sortedSubmissions = new TreeSet<Submission>();
      for (int x = 0; x < cluster.size(); x++) {
        sortedSubmissions.add(submissions.elementAt(cluster.getSubmissionAt(x)));
      }

      for (Iterator<Submission> iter = sortedSubmissions.iterator(); iter.hasNext(); ) {
        Submission sub = iter.next();
        int index = submissions.indexOf(sub);
        f.print("<A HREF=\"submission" + index + ".html\">" + sub.name + "</A>");
        if (iter.hasNext()) f.print(", ");
        neededSubmissions.add(sub); // write files for these.
      }

      if (this.program.get_language() instanceof jplag.text.Language) {
        f.println(
            "<TD ALIGN=left BGCOLOR=#c0c0ff>"
                + ThemeGenerator.generateThemes(
                    sortedSubmissions, this.program.get_themewords(), true, this.program));
      } else {
        f.println("<TD ALIGN=left BGCOLOR=#c0c0ff>-");
      }

      f.println("</TR>");
    }
    f.println("</TABLE>\n<P>\n");

    f.println("<H5>" + msg.getString("Clusters.Distribution_of_cluster_size") + ":</H5>");

    String text;
    text = "<TABLE CELLPADDING=1 CELLSPACING=1>\n";
    text +=
        "<TR><TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Cluster_size")
            + "<TH ALIGN=center BGCOLOR=#8080ff>"
            + msg.getString("Clusters.Number_of_clusters")
            + "<TH ALIGN=center BGCOLOR=#8080ff>.</TR>\n";
    for (int i = 0; i <= maxSize; i++) {
      if (distribution[i] == 0) continue;
      text +=
          "<TR><TD ALIGN=center BGCOLOR=#c0c0ff>"
              + i
              + "<TD ALIGN=right BGCOLOR=#c0c0ff>"
              + distribution[i]
              + "<TD BGCOLOR=#c0c0ff>\n";
      for (int j = (distribution[i] * barLength / max); j > 0; j--) text += ("#");
      if (distribution[i] * barLength / max == 0) {
        if (distribution[i] == 0) text += (".");
        else text += ("#");
      }
      text += ("</TR>\n");
    }
    text += ("</TABLE>\n");

    f.print(text);
    return text;
  }