/** The main method. */
  public static void main(String[] ops) {

    KEAKeyphraseExtractor kmb = new KEAKeyphraseExtractor();
    try {
      kmb.setOptions(ops);
      System.err.print("Extracting keyphrases with options: ");
      String[] optionSettings = kmb.getOptions();
      for (int i = 0; i < optionSettings.length; i++) {
        System.err.print(optionSettings[i] + " ");
      }
      System.err.println();
      kmb.loadModel();
      kmb.extractKeyphrases(kmb.collectStems());
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(e.getMessage());
      System.err.println("\nOptions:\n");
      Enumeration enumeration = kmb.listOptions();
      while (enumeration.hasMoreElements()) {
        Option option = (Option) enumeration.nextElement();
        System.err.println(option.synopsis());
        System.err.println(option.description());
      }
    }
  }
  /**
   * 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.º 3
0
  /** Main method for testing this class. */
  public static void main(String[] options) {

    String trainFileString;
    StringBuffer text = new StringBuffer();
    PredictiveApriori apriori = new PredictiveApriori();
    Reader reader;

    try {
      text.append("\n\nPredictiveApriori options:\n\n");
      text.append("-t <training file>\n");
      text.append("\tThe name of the training file.\n");
      Enumeration enu = apriori.listOptions();
      while (enu.hasMoreElements()) {
        Option option = (Option) enu.nextElement();
        text.append(option.synopsis() + '\n');
        text.append(option.description() + '\n');
      }
      trainFileString = Utils.getOption('t', options);
      if (trainFileString.length() == 0) throw new Exception("No training file given!");
      apriori.setOptions(options);
      reader = new BufferedReader(new FileReader(trainFileString));
      apriori.buildAssociations(new Instances(reader));
      System.out.println(apriori);
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("\n" + e.getMessage() + text);
    }
  }
Ejemplo n.º 4
0
  /**
   * Main method.
   *
   * @param args should contain the name of an input file.
   */
  public static void main(String[] args) {
    if (args.length > 0) {
      try {
        TextDirectoryLoader loader = new TextDirectoryLoader();
        loader.setOptions(args);
        // System.out.println(loader.getDataSet());
        Instances structure = loader.getStructure();
        System.out.println(structure);
        Instance temp;
        do {
          temp = loader.getNextInstance(structure);
          if (temp != null) {
            System.out.println(temp);
          }
        } while (temp != null);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      System.err.println("\nUsage:\n" + "\tTextDirectoryLoader [options]\n" + "\n" + "Options:\n");

      Enumeration enm = ((OptionHandler) new TextDirectoryLoader()).listOptions();
      while (enm.hasMoreElements()) {
        Option option = (Option) enm.nextElement();
        System.err.println(option.synopsis());
        System.err.println(option.description());
      }

      System.err.println();
    }
  }
Ejemplo n.º 5
0
  /**
   * Parses a given list of options. Valid options are:
   *
   * <p>-D <br>
   * If set, clusterer is run in debug mode and may output additional info to the console.
   *
   * <p>-do-not-check-capabilities <br>
   * If set, clusterer capabilities are not checked before clusterer is built (use with caution).
   *
   * <p>
   *
   * @param options the list of options as an array of strings
   * @exception Exception if an option is not supported
   */
  @Override
  public void setOptions(String[] options) throws Exception {

    Option.setOptionsForHierarchy(options, this, AbstractClusterer.class);
    setDebug(Utils.getFlag("output-debug-info", options));
    setDoNotCheckCapabilities(Utils.getFlag("do-not-check-capabilities", options));
  }
Ejemplo n.º 6
0
  /** The main method. */
  public static void main(String[] ops) {

    MauiModelBuilder modelBuilder = new MauiModelBuilder();

    try {

      modelBuilder.setOptions(ops);

      // Output what options are used
      if (modelBuilder.getDebug() == true) {
        System.err.print("Building model with options: ");
        String[] optionSettings = modelBuilder.getOptions();
        for (String optionSetting : optionSettings) {
          System.err.print(optionSetting + " ");
        }
        System.err.println();
      }

      HashSet<String> fileNames = modelBuilder.collectStems();
      modelBuilder.buildModel(fileNames);

      if (modelBuilder.getDebug() == true) {
        System.err.print("Model built. Saving the model...");
      }

      modelBuilder.saveModel();

      System.err.print("Done!");

    } catch (Exception e) {

      // Output information on how to use this class
      e.printStackTrace();
      System.err.println(e.getMessage());
      System.err.println("\nOptions:\n");
      Enumeration<Option> en = modelBuilder.listOptions();
      while (en.hasMoreElements()) {
        Option option = (Option) en.nextElement();
        System.err.println(option.synopsis());
        System.err.println(option.description());
      }
    }
  }
Ejemplo n.º 7
0
  /**
   * Test the class from the command line. The instance query should be specified with -Q sql_query
   *
   * @param args contains options for the instance query
   */
  public static void main(String args[]) {

    try {
      InstanceQuery iq = new InstanceQuery();
      String query = Utils.getOption('Q', args);
      if (query.length() == 0) {
        iq.setQuery("select * from Experiment_index");
      } else {
        iq.setQuery(query);
      }
      iq.setOptions(args);
      try {
        Utils.checkForRemainingOptions(args);
      } catch (Exception e) {
        System.err.println("Options for weka.experiment.InstanceQuery:\n");
        Enumeration en = iq.listOptions();
        while (en.hasMoreElements()) {
          Option o = (Option) en.nextElement();
          System.err.println(o.synopsis() + "\n" + o.description());
        }
        System.exit(1);
      }

      Instances aha = iq.retrieveInstances();
      iq.disconnectFromDatabase();
      // query returned no result -> exit
      if (aha == null) return;
      // The dataset may be large, so to make things easier we'll
      // output an instance at a time (rather than having to convert
      // the entire dataset to one large string)
      System.out.println(new Instances(aha, 0));
      for (int i = 0; i < aha.numInstances(); i++) {
        System.out.println(aha.instance(i));
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(e.getMessage());
    }
  }
Ejemplo n.º 8
0
  /**
   * Test method for this class
   *
   * @param args the command line arguments
   */
  public static void main(String[] args) {

    try {
      BVDecompose bvd = new BVDecompose();

      try {
        bvd.setOptions(args);
        Utils.checkForRemainingOptions(args);
      } catch (Exception ex) {
        String result = ex.getMessage() + "\nBVDecompose Options:\n\n";
        Enumeration<Option> enu = bvd.listOptions();
        while (enu.hasMoreElements()) {
          Option option = (Option) enu.nextElement();
          result += option.synopsis() + "\n" + option.description() + "\n";
        }
        throw new Exception(result);
      }

      bvd.decompose();
      System.out.println(bvd.toString());
    } catch (Exception ex) {
      System.err.println(ex.getMessage());
    }
  }
Ejemplo n.º 9
0
  /**
   * Gets the current settings of the clusterer.
   *
   * @return an array of strings suitable for passing to setOptions
   */
  @Override
  public String[] getOptions() {

    Vector<String> options = new Vector<String>();
    for (String s : Option.getOptionsForHierarchy(this, AbstractClusterer.class)) {
      options.add(s);
    }

    if (getDebug()) {
      options.add("-output-debug-info");
    }
    if (getDoNotCheckCapabilities()) {
      options.add("-do-not-check-capabilities");
    }

    return options.toArray(new String[0]);
  }
Ejemplo n.º 10
0
  /**
   * Returns an enumeration describing the available options.
   *
   * @return an enumeration of all the available options.
   */
  @Override
  public Enumeration<Option> listOptions() {

    Vector<Option> newVector =
        Option.listOptionsForClassHierarchy(this.getClass(), AbstractClusterer.class);

    newVector.addElement(
        new Option(
            "\tIf set, clusterer is run in debug mode and\n"
                + "\tmay output additional info to the console",
            "output-debug-info",
            0,
            "-output-debug-info"));
    newVector.addElement(
        new Option(
            "\tIf set, clusterer capabilities are not checked before clusterer is built\n"
                + "\t(use with caution).",
            "-do-not-check-capabilities",
            0,
            "-do-not-check-capabilities"));

    return newVector.elements();
  }
Ejemplo n.º 11
0
  /**
   * Method for testing filters.
   *
   * @param filter the filter to use
   * @param options should contain the following arguments: <br>
   *     -i input_file <br>
   *     -o output_file <br>
   *     -c class_index <br>
   *     -z classname (for filters implementing weka.filters.Sourcable) <br>
   *     or -h for help on options
   * @throws Exception if something goes wrong or the user requests help on command options
   */
  public static void filterFile(Filter filter, String[] options) throws Exception {

    boolean debug = false;
    Instances data = null;
    DataSource input = null;
    PrintWriter output = null;
    boolean helpRequest;
    String sourceCode = "";

    try {
      helpRequest = Utils.getFlag('h', options);

      if (Utils.getFlag('d', options)) {
        debug = true;
      }
      String infileName = Utils.getOption('i', options);
      String outfileName = Utils.getOption('o', options);
      String classIndex = Utils.getOption('c', options);
      if (filter instanceof Sourcable) sourceCode = Utils.getOption('z', options);

      if (filter instanceof OptionHandler) {
        ((OptionHandler) filter).setOptions(options);
      }

      Utils.checkForRemainingOptions(options);
      if (helpRequest) {
        throw new Exception("Help requested.\n");
      }
      if (infileName.length() != 0) {
        input = new DataSource(infileName);
      } else {
        input = new DataSource(System.in);
      }
      if (outfileName.length() != 0) {
        output = new PrintWriter(new FileOutputStream(outfileName));
      } else {
        output = new PrintWriter(System.out);
      }

      data = input.getStructure();
      if (classIndex.length() != 0) {
        if (classIndex.equals("first")) {
          data.setClassIndex(0);
        } else if (classIndex.equals("last")) {
          data.setClassIndex(data.numAttributes() - 1);
        } else {
          data.setClassIndex(Integer.parseInt(classIndex) - 1);
        }
      }
    } catch (Exception ex) {
      String filterOptions = "";
      // Output the error and also the valid options
      if (filter instanceof OptionHandler) {
        filterOptions += "\nFilter options:\n\n";
        Enumeration enu = ((OptionHandler) filter).listOptions();
        while (enu.hasMoreElements()) {
          Option option = (Option) enu.nextElement();
          filterOptions += option.synopsis() + '\n' + option.description() + "\n";
        }
      }

      String genericOptions =
          "\nGeneral options:\n\n"
              + "-h\n"
              + "\tGet help on available options.\n"
              + "\t(use -b -h for help on batch mode.)\n"
              + "-i <file>\n"
              + "\tThe name of the file containing input instances.\n"
              + "\tIf not supplied then instances will be read from stdin.\n"
              + "-o <file>\n"
              + "\tThe name of the file output instances will be written to.\n"
              + "\tIf not supplied then instances will be written to stdout.\n"
              + "-c <class index>\n"
              + "\tThe number of the attribute to use as the class.\n"
              + "\t\"first\" and \"last\" are also valid entries.\n"
              + "\tIf not supplied then no class is assigned.\n";

      if (filter instanceof Sourcable) {
        genericOptions +=
            "-z <class name>\n" + "\tOutputs the source code representing the trained filter.\n";
      }

      throw new Exception('\n' + ex.getMessage() + filterOptions + genericOptions);
    }

    if (debug) {
      System.err.println("Setting input format");
    }
    boolean printedHeader = false;
    if (filter.setInputFormat(data)) {
      if (debug) {
        System.err.println("Getting output format");
      }
      output.println(filter.getOutputFormat().toString());
      printedHeader = true;
    }

    // Pass all the instances to the filter
    Instance inst;
    while (input.hasMoreElements(data)) {
      inst = input.nextElement(data);
      if (debug) {
        System.err.println("Input instance to filter");
      }
      if (filter.input(inst)) {
        if (debug) {
          System.err.println("Filter said collect immediately");
        }
        if (!printedHeader) {
          throw new Error("Filter didn't return true from setInputFormat() " + "earlier!");
        }
        if (debug) {
          System.err.println("Getting output instance");
        }
        output.println(filter.output().toString());
      }
    }

    // Say that input has finished, and print any pending output instances
    if (debug) {
      System.err.println("Setting end of batch");
    }
    if (filter.batchFinished()) {
      if (debug) {
        System.err.println("Filter said collect output");
      }
      if (!printedHeader) {
        if (debug) {
          System.err.println("Getting output format");
        }
        output.println(filter.getOutputFormat().toString());
      }
      if (debug) {
        System.err.println("Getting output instance");
      }
      while (filter.numPendingOutput() > 0) {
        output.println(filter.output().toString());
        if (debug) {
          System.err.println("Getting output instance");
        }
      }
    }
    if (debug) {
      System.err.println("Done");
    }

    if (output != null) {
      output.close();
    }

    if (sourceCode.length() != 0)
      System.out.println(
          wekaStaticWrapper((Sourcable) filter, sourceCode, data, filter.getOutputFormat()));
  }
Ejemplo n.º 12
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
Ejemplo n.º 13
0
  /**
   * Configures/Runs the Experiment from the command line.
   *
   * @param args command line arguments to the Experiment.
   */
  public static void main(String[] args) {

    try {
      weka.core.WekaPackageManager.loadPackages(false, true, false);
      RemoteExperiment exp = null;

      // get options from XML?
      String xmlOption = Utils.getOption("xml", args);
      if (!xmlOption.equals("")) {
        args = new XMLOptions(xmlOption).toArray();
      }

      Experiment base = null;
      String expFile = Utils.getOption('l', args);
      String saveFile = Utils.getOption('s', args);
      boolean runExp = Utils.getFlag('r', args);
      ArrayList<String> remoteHosts = new ArrayList<String>();
      String runHost = " ";
      while (runHost.length() != 0) {
        runHost = Utils.getOption('h', args);
        if (runHost.length() != 0) {
          remoteHosts.add(runHost);
        }
      }
      if (expFile.length() == 0) {
        base = new Experiment();
        try {
          base.setOptions(args);
          Utils.checkForRemainingOptions(args);
        } catch (Exception ex) {
          ex.printStackTrace();
          String result =
              "Usage:\n\n"
                  + "-l <exp file>\n"
                  + "\tLoad experiment from file (default use cli options)\n"
                  + "-s <exp file>\n"
                  + "\tSave experiment to file after setting other options\n"
                  + "\t(default don't save)\n"
                  + "-h <remote host name>\n"
                  + "\tHost to run experiment on (may be specified more than once\n"
                  + "\tfor multiple remote hosts)\n"
                  + "-r \n"
                  + "\tRun experiment on (default don't run)\n"
                  + "-xml <filename | xml-string>\n"
                  + "\tget options from XML-Data instead from parameters\n"
                  + "\n";
          Enumeration<Option> enm = ((OptionHandler) base).listOptions();
          while (enm.hasMoreElements()) {
            Option option = enm.nextElement();
            result += option.synopsis() + "\n";
            result += option.description() + "\n";
          }
          throw new Exception(result + "\n" + ex.getMessage());
        }
      } else {
        Object tmp;

        // KOML?
        if ((KOML.isPresent()) && (expFile.toLowerCase().endsWith(KOML.FILE_EXTENSION))) {
          tmp = KOML.read(expFile);
        } else
        // XML?
        if (expFile.toLowerCase().endsWith(".xml")) {
          XMLExperiment xml = new XMLExperiment();
          tmp = xml.read(expFile);
        }
        // binary
        else {
          FileInputStream fi = new FileInputStream(expFile);
          ObjectInputStream oi = new ObjectInputStream(new BufferedInputStream(fi));
          tmp = oi.readObject();
          oi.close();
        }
        if (tmp instanceof RemoteExperiment) {
          exp = (RemoteExperiment) tmp;
        } else {
          base = (Experiment) tmp;
        }
      }
      if (base != null) {
        exp = new RemoteExperiment(base);
      }
      for (int i = 0; i < remoteHosts.size(); i++) {
        exp.addRemoteHost(remoteHosts.get(i));
      }
      System.err.println("Experiment:\n" + exp.toString());

      if (saveFile.length() != 0) {
        // KOML?
        if ((KOML.isPresent()) && (saveFile.toLowerCase().endsWith(KOML.FILE_EXTENSION))) {
          KOML.write(saveFile, exp);
        } else
        // XML?
        if (saveFile.toLowerCase().endsWith(".xml")) {
          XMLExperiment xml = new XMLExperiment();
          xml.write(saveFile, exp);
        }
        // binary
        else {
          FileOutputStream fo = new FileOutputStream(saveFile);
          ObjectOutputStream oo = new ObjectOutputStream(new BufferedOutputStream(fo));
          oo.writeObject(exp);
          oo.close();
        }
      }

      if (runExp) {
        System.err.println("Initializing...");
        exp.initialize();
        System.err.println("Iterating...");
        exp.runExperiment();
        System.err.println("Postprocessing...");
        exp.postProcess();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println(ex.getMessage());
    }
  }