Пример #1
0
 private String statusMessagePrefix() {
   return getCustomName()
       + "$"
       + hashCode()
       + "|"
       + ((m_Filter instanceof OptionHandler
               && Utils.joinOptions(((OptionHandler) m_Filter).getOptions()).length() > 0)
           ? Utils.joinOptions(((OptionHandler) m_Filter).getOptions()) + "|"
           : "");
 }
Пример #2
0
  /**
   * Parses a given list of options.
   *
   * <p>
   * <!-- options-start -->
   * Valid options are:
   *
   * <p>
   *
   * <pre> -delimiters &lt;value&gt;
   *  The delimiters to use
   *  (default ' \r\n\t.,;:'"()?!').</pre>
   *
   * <pre> -max &lt;int&gt;
   *  The max size of the Ngram (default = 3).</pre>
   *
   * <pre> -min &lt;int&gt;
   *  The min size of the Ngram (default = 1).</pre>
   *
   * <!-- options-end -->
   *
   * @param options the list of options as an array of strings
   * @throws Exception if an option is not supported
   */
  public void setOptions(String[] options) throws Exception {
    String value;

    super.setOptions(options);

    value = Utils.getOption("max", options);
    if (value.length() != 0) setNGramMaxSize(Integer.parseInt(value));
    else setNGramMaxSize(3);

    value = Utils.getOption("min", options);
    if (value.length() != 0) setNGramMinSize(Integer.parseInt(value));
    else setNGramMinSize(1);
  }
Пример #3
0
  /**
   * Sets the OptionHandler's options using the given list. All options will be set (or reset)
   * during this call (i.e. incremental setting of options is not possible).
   * <!-- options-start -->
   * Valid options are:
   *
   * <p>
   *
   * <pre> -S &lt;sample size&gt;
   *  Set sample size
   *  (default: 4)
   * </pre>
   *
   * <pre> -G &lt;seed&gt;
   *  Set the seed used to generate samples
   *  (default: 0)
   * </pre>
   *
   * <pre> -D
   *  Produce debugging output
   *  (default no debugging output)
   * </pre>
   *
   * <!-- options-end -->
   *
   * @param options the list of options as an array of strings
   * @throws Exception if an option is not supported
   */
  public void setOptions(String[] options) throws Exception {

    String curropt = Utils.getOption('S', options);
    if (curropt.length() != 0) {
      setSampleSize(Integer.parseInt(curropt));
    } else setSampleSize(4);

    curropt = Utils.getOption('G', options);
    if (curropt.length() != 0) {
      setRandomSeed(Long.parseLong(curropt));
    } else {
      setRandomSeed(0);
    }

    setDebug(Utils.getFlag('D', options));
  }
Пример #4
0
  /**
   * Returns a string that describes the filter as source. The filter will be contained in a class
   * with the given name (there may be auxiliary classes), and will contain two methods with these
   * signatures:
   *
   * <pre><code>
   * // converts one row
   * public static Object[] filter(Object[] i);
   * // converts a full dataset (first dimension is row index)
   * public static Object[][] filter(Object[][] i);
   * </code></pre>
   *
   * where the array <code>i</code> contains elements that are either Double, String, with missing
   * values represented as null. The generated code is public domain and comes with no warranty.
   *
   * @param className the name that should be given to the source class.
   * @param data the dataset used for initializing the filter
   * @return the object source described by a string
   * @throws Exception if the source can't be computed
   */
  public String toSource(String className, Instances data) throws Exception {
    StringBuffer result;
    boolean[] process;
    int i;

    result = new StringBuffer();

    // determine what attributes were processed
    process = new boolean[data.numAttributes()];
    for (i = 0; i < data.numAttributes(); i++) {
      process[i] = (data.attribute(i).isNumeric() && (i != data.classIndex()));
    }

    result.append("class " + className + " {\n");
    result.append("\n");
    result.append("  /** lists which attributes will be processed */\n");
    result.append(
        "  protected final static boolean[] PROCESS = new boolean[]{"
            + Utils.arrayToString(process)
            + "};\n");
    result.append("\n");
    result.append("  /** the computed means */\n");
    result.append(
        "  protected final static double[] MEANS = new double[]{"
            + Utils.arrayToString(m_Means)
            + "};\n");
    result.append("\n");
    result.append("  /** the computed standard deviations */\n");
    result.append(
        "  protected final static double[] STDEVS = new double[]{"
            + Utils.arrayToString(m_StdDevs)
            + "};\n");
    result.append("\n");
    result.append("  /**\n");
    result.append("   * filters a single row\n");
    result.append("   * \n");
    result.append("   * @param i the row to process\n");
    result.append("   * @return the processed row\n");
    result.append("   */\n");
    result.append("  public static Object[] filter(Object[] i) {\n");
    result.append("    Object[] result;\n");
    result.append("\n");
    result.append("    result = new Object[i.length];\n");
    result.append("    for (int n = 0; n < i.length; n++) {\n");
    result.append("      if (PROCESS[n] && (i[n] != null)) {\n");
    result.append("        if (STDEVS[n] > 0)\n");
    result.append("          result[n] = (((Double) i[n]) - MEANS[n]) / STDEVS[n];\n");
    result.append("        else\n");
    result.append("          result[n] = ((Double) i[n]) - MEANS[n];\n");
    result.append("      }\n");
    result.append("      else {\n");
    result.append("        result[n] = i[n];\n");
    result.append("      }\n");
    result.append("    }\n");
    result.append("\n");
    result.append("    return result;\n");
    result.append("  }\n");
    result.append("\n");
    result.append("  /**\n");
    result.append("   * filters multiple rows\n");
    result.append("   * \n");
    result.append("   * @param i the rows to process\n");
    result.append("   * @return the processed rows\n");
    result.append("   */\n");
    result.append("  public static Object[][] filter(Object[][] i) {\n");
    result.append("    Object[][] result;\n");
    result.append("\n");
    result.append("    result = new Object[i.length][];\n");
    result.append("    for (int n = 0; n < i.length; n++) {\n");
    result.append("      result[n] = filter(i[n]);\n");
    result.append("    }\n");
    result.append("\n");
    result.append("    return result;\n");
    result.append("  }\n");
    result.append("}\n");

    return result.toString();
  }