/**
   * Returns an enumeration describing the available options.
   *
   * @return an enumeration of all the available options.
   */
  public Enumeration listOptions() {
    Vector result;
    Enumeration en;

    result = new Vector();

    // ancestor
    en = super.listOptions();
    while (en.hasMoreElements()) result.addElement(en.nextElement());

    result.addElement(
        new Option(
            "\tUses a sorted list (ordered according to distance) instead of the\n"
                + "\tKDTree for finding the neighbors.\n"
                + "\t(default is KDTree)",
            "naive",
            0,
            "-naive"));

    // IBk
    en = m_Classifier.listOptions();
    while (en.hasMoreElements()) {
      Option o = (Option) en.nextElement();
      // remove -X, -W and -E
      if (!o.name().equals("X") && !o.name().equals("W") && !o.name().equals("E"))
        result.addElement(o);
    }

    return result.elements();
  }
Ejemplo n.º 2
0
  @Override
  protected void getParameters() {
    // fills the global Options vector

    System.out.println(getLocalName() + ": The options are: ");

    String optPath = System.getProperty("user.dir") + getOptFileName();

    agent_options = new pikater.ontology.messages.Agent();
    agent_options.setName(getLocalName());
    agent_options.setType(getAgentType());
    // read options from file
    try {
      /* Sets up a file reader to read the options file */
      FileReader input = new FileReader(optPath);
      /*
       * Filter FileReader through a Buffered read to read a line at a
       * time
       */
      BufferedReader bufRead = new BufferedReader(input);

      String line; // String that holds current file line
      int count = 0; // Line number of count
      // Read first line
      line = bufRead.readLine();
      count++;

      // list of ontology.messages.Option
      List _options = new ArrayList();

      // Read through file one line at time. Print line # and line
      while (line != null) {
        System.out.println("    " + count + ": " + line);

        // parse the line
        String delims = "[ ]+";
        String[] params = line.split(delims, 7);

        if (params[0].equals("$")) {

          MyWekaOption.dataType dt = MyWekaOption.dataType.BOOLEAN;

          if (params[2].equals("boolean")) {
            dt = MyWekaOption.dataType.BOOLEAN;
          }
          if (params[2].equals("float")) {
            dt = MyWekaOption.dataType.FLOAT;
          }
          if (params[2].equals("int")) {
            dt = MyWekaOption.dataType.INT;
          }
          if (params[2].equals("mixed")) {
            dt = MyWekaOption.dataType.MIXED;
          }

          String[] default_options = ((Classifier) getModelObject()).getOptions();

          Enumeration en = ((Classifier) getModelObject()).listOptions();
          while (en.hasMoreElements()) {

            Option next = (weka.core.Option) en.nextElement();
            String default_value = "False";
            for (int i = 0; i < default_options.length; i++) {
              if (default_options[i].equals("-" + next.name())) {
                if (default_options[i].startsWith("-")) {
                  // if the next array element is again an
                  // option name,
                  // (or it is the last element)
                  // => it's a boolean parameter
                  if (i == default_options.length - 1) {
                    default_value = "True";
                  } else {
                    // if
                    // (default_options[i+1].startsWith("-")){
                    if (default_options[i + 1].matches("\\-[A-Z]")) {
                      default_value = "True";
                    } else {
                      default_value = default_options[i + 1];
                    }
                  }
                }
              }
            }

            if ((next.name()).equals(params[1])) {
              MyWekaOption o;
              if (params.length > 4) {

                o =
                    new MyWekaOption(
                        next.description(),
                        next.name(),
                        next.numArguments(),
                        next.synopsis(),
                        dt,
                        new Integer(params[3]).intValue(),
                        new Integer(params[4]).intValue(),
                        params[5],
                        default_value,
                        params[6]);

              } else {
                o =
                    new MyWekaOption(
                        next.description(),
                        next.name(),
                        next.numArguments(),
                        next.synopsis(),
                        dt,
                        0,
                        0,
                        "",
                        default_value,
                        "");
              }

              // convert&save o to options vector
              _options.add(convertOption(o));
            }
          }
        }

        line = bufRead.readLine();

        count++;
      }
      agent_options.setOptions(_options);
      bufRead.close();

    } catch (ArrayIndexOutOfBoundsException e) {
      /*
       * If no file was passed on the command line, this exception is
       * generated. A message indicating how to the class should be called
       * is displayed
       */
      System.out.println("Usage: java ReadFile filename\n");
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(getLocalName() + ": Reading options from .opt file failed.");
    }
    // Save the agent's options

    /*
     * Enumeration en = cls.listOptions();
     *
     * while(en.hasMoreElements()){ Option next =
     * (weka.core.Option)en.nextElement();
     * System.out.println("  "+next.description()+ ", " +next.name()+ ", "
     * +next.numArguments()+ ", " +next.synopsis() ); System.out.println();
     * }
     */

    /*
     * System.out.println("MyWekaOptions: "); for (Enumeration e =
     * Options.elements() ; e.hasMoreElements() ;) { MyWekaOption next =
     * (MyWekaOption)e.nextElement(); System.out.print(next.name+" ");
     * System.out.print(next.lower+" "); System.out.print(next.upper+" ");
     * System.out.print(next.type+" ");
     * System.out.print(next.numArgsMin+" ");
     * System.out.print(next.numArgsMax+" "); System.out.println(next.set);
     * System.out.println("------------"); }
     */
  } // end getParameters