예제 #1
0
  public static void main(String argv[]) throws IOException {
    int i, predict_probability = 0;

    // parse options
    for (i = 0; i < argv.length; i++) {
      if (argv[i].charAt(0) != '-') break;
      ++i;
      switch (argv[i - 1].charAt(1)) {
        case 'b':
          predict_probability = atoi(argv[i]);
          break;
        default:
          System.err.print("unknown option\n");
          exit_with_help();
      }
    }
    if (i >= argv.length) exit_with_help();
    try {
      BufferedReader input = new BufferedReader(new FileReader(argv[i]));
      DataOutputStream output = new DataOutputStream(new FileOutputStream(argv[i + 2]));
      svm_model model = svm.svm_load_model(argv[i + 1]);
      if (predict_probability == 1)
        if (svm.svm_check_probability_model(model) == 0) {
          System.err.print("Model does not support probabiliy estimates\n");
          System.exit(1);
        }
      predict(input, output, model, predict_probability);
      input.close();
      output.close();
    } catch (FileNotFoundException e) {
      exit_with_help();
    } catch (ArrayIndexOutOfBoundsException e) {
      exit_with_help();
    }
  }
  public static void main(String argv[]) throws IOException {
    int i, predict_probability = 0;
    svm_print_string = svm_print_stdout;

    // parse options
    for (i = 0; i < argv.length; i++) {
      if (argv[i].charAt(0) != '-') break;
      ++i;
      switch (argv[i - 1].charAt(1)) {
        case 'b':
          predict_probability = atoi(argv[i]);
          break;
        case 'q':
          svm_print_string = svm_print_null;
          i--;
          break;
        default:
          System.err.print("Unknown option: " + argv[i - 1] + "\n");
          exit_with_help();
      }
    }
    if (i >= argv.length - 2) exit_with_help();
    try {
      BufferedReader input = new BufferedReader(new FileReader(argv[i]));
      DataOutputStream output =
          new DataOutputStream(new BufferedOutputStream(new FileOutputStream(argv[i + 2])));
      svm_model model = svm.svm_load_model(argv[i + 1]);
      if (model == null) {
        System.err.print("can't open model file " + argv[i + 1] + "\n");
        System.exit(1);
      }
      if (predict_probability == 1) {
        if (svm.svm_check_probability_model(model) == 0) {
          System.err.print("Model does not support probabiliy estimates\n");
          System.exit(1);
        }
      } else {
        if (svm.svm_check_probability_model(model) != 0) {
          svm_predict.info("Model supports probability estimates, but disabled in prediction.\n");
        }
      }
      predict(input, output, model, predict_probability);
      input.close();
      output.close();
    } catch (FileNotFoundException e) {
      exit_with_help();
    } catch (ArrayIndexOutOfBoundsException e) {
      exit_with_help();
    }
  }