ExecMain.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This is the main class to execute the computation and get the GOID.
  3. */
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.OutputStreamWriter;
  7. import java.util.Vector;
  8. import weka.core.Instances;
  9. /**
  10. *
  11. * @author DTian
  12. */
  13. public class ExecMain {
  14. public static void main(String[] args) {
  15. // SGD2AttrTable sgd = new SGD2AttrTable();
  16. // Get clusters
  17. try {
  18. // Check the input arguments
  19. checkParameters(args.length);
  20. GetClusters myGetClusters = new GetClusters();
  21. // To get the input file type
  22. Instances oriData = myGetClusters.input(args[0]);
  23. // Get the output files name
  24. String outputWholeCluster = args[0] + "-WholeTree.txt";
  25. String outputFinalTable = args[0] + "-finalTable.csv";
  26. String outputSummary = args[0] + "-summary.csv";
  27. boolean fromFunction = true?false:args[4].trim().compareToIgnoreCase("true") == 0;
  28. // Create the root cluster name
  29. int round = 1; //for tree level
  30. int position = 0; // for node position in same level
  31. String rootName = (round-1)+"-"+position+"-"+0;
  32. // System.out.println("root cluster is:" + rootName);
  33. myGetClusters.printRootName(outputWholeCluster,rootName);
  34. // Create a vector for fianl table
  35. Vector vecFinalTable = new Vector();
  36. Vector vecSummary = new Vector();
  37. //get the variable name
  38. vecFinalTable.addElement(myGetClusters.printTableHead(oriData));
  39. // Create the root node
  40. TreeNode root = new TreeNode(rootName,0.0,oriData,null);
  41. OutputStreamWriter xmlWriter = new OutputStreamWriter(
  42. new FileOutputStream(new File("tree.xml"), true));
  43. xmlWriter.write(" <tree>\n <declarations> \n <attributeDecl name=\"name\" type=\"String\"/>\n </declarations>\n");
  44. xmlWriter.write(" <branch>\n <attribute name=\"name\" value=\""+"root" +"\"/>\n");
  45. xmlWriter.flush();
  46. // Recursive clustering the data
  47. myGetClusters.clustering(
  48. root,
  49. round,
  50. ""+position,
  51. vecFinalTable,
  52. vecSummary,
  53. outputWholeCluster,
  54. xmlWriter,
  55. args[1],
  56. args[2],
  57. args[3],
  58. fromFunction
  59. );
  60. xmlWriter.write(" </branch>\n");
  61. xmlWriter.write("</tree>\n");
  62. xmlWriter.close();
  63. // Output final result
  64. myGetClusters.printVector(vecFinalTable,outputFinalTable);
  65. myGetClusters.printVector(vecSummary,outputSummary);
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. System.exit(1);
  69. }
  70. }
  71. /**
  72. * check the number of the arguments:
  73. * java GetCluster arg1 arg2 ...
  74. *
  75. * @param length the length of the arguments
  76. * in this program, length should be 1
  77. */
  78. private static void checkParameters(int length) {
  79. if(length != 5) {
  80. // there are 5 parameters, 1,file for clustering; 2, lookup table file;
  81. // 3, backgroud file; 4, repeat counts(an integer) 5, GoIDfromFunction (boolean)
  82. System.out.println("Usage: java ExecMain clusterFileName GoMatrixFilename backGroundFilename repeatTime true|false");
  83. System.exit(1);
  84. }
  85. }
  86. }