Exemple #1
0
  /**
   * The main method takes an argument of a string array. The first element of the array selects a
   * data structure to help analyze the correlation between two documents. The second and third
   * element are the names of the files to be compared. The correlation number is printed.
   */
  public static void main(String[] args) {
    DataCounter<String> counter1 = new BinarySearchTree<String>(new StringComparator());

    DataCounter<String> counter2 = new BinarySearchTree<String>(new StringComparator());
    if (args.length != 3) {
      System.out.println("Usage: [ -b | -a | -m | -h ] <filename1> <filename2>");
    }

    if (args[0].equals("-b")) {
      counter1 = new BinarySearchTree<String>(new StringComparator());
      counter2 = new BinarySearchTree<String>(new StringComparator());
    } else if (args[0].equals("-a")) {
      counter1 = new AVLTree<String>(new StringComparator());
      counter2 = new AVLTree<String>(new StringComparator());
    } else if (args[0].equals("-m")) {
      counter1 = new MoveToFrontList<String>(new StringComparator());
      counter2 = new MoveToFrontList<String>(new StringComparator());
    } else if (args[0].equals("-h")) {
      counter1 = new Hashtable<String>(new StringComparator(), new StringHasher());
      counter2 = new Hashtable<String>(new StringComparator(), new StringHasher());
    } else {
      System.out.println("Incorrect argument. Usage: [ -b | -a | -m | -h ] ");
      System.exit(1);
    }
    int sum1 = parseAndCount(args[1], counter1);
    int sum2 = parseAndCount(args[2], counter2);
    if (counter1.getSize() > counter2.getSize()) {
      System.out.println(compare(counter2.getIterator(), counter1, sum2, sum1));
    } else {
      System.out.println(compare(counter1.getIterator(), counter2, sum1, sum2));
    }
  }