Пример #1
0
  /**
   * Parses a given list of options.
   *
   * <p>
   * <!-- options-start -->
   * Valid options are:
   *
   * <p>
   *
   * <pre> -T &lt;NUM|NOM|STR|DAT&gt;
   *  The type of attribute to create:
   *  NUM = Numeric attribute
   *  NOM = Nominal attribute
   *  STR = String attribute
   *  DAT = Date attribute
   *  (default: NUM)</pre>
   *
   * <pre> -C &lt;index&gt;
   *  Specify where to insert the column. First and last
   *  are valid indexes.(default: last)</pre>
   *
   * <pre> -N &lt;name&gt;
   *  Name of the new attribute.
   *  (default: 'Unnamed')</pre>
   *
   * <pre> -L &lt;label1,label2,...&gt;
   *  Create nominal attribute with given labels
   *  (default: numeric attribute)</pre>
   *
   * <pre> -F &lt;format&gt;
   *  The format of the date values (see ISO-8601)
   *  (default: yyyy-MM-dd'T'HH:mm:ss)</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 tmpStr;

    tmpStr = Utils.getOption('T', options);
    if (tmpStr.length() != 0) setAttributeType(new SelectedTag(tmpStr, TAGS_TYPE));
    else setAttributeType(new SelectedTag(Attribute.NUMERIC, TAGS_TYPE));

    tmpStr = Utils.getOption('C', options);
    if (tmpStr.length() == 0) tmpStr = "last";
    setAttributeIndex(tmpStr);

    setAttributeName(Utils.unbackQuoteChars(Utils.getOption('N', options)));

    if (m_AttributeType == Attribute.NOMINAL) {
      tmpStr = Utils.getOption('L', options);
      if (tmpStr.length() != 0) setNominalLabels(tmpStr);
    } else if (m_AttributeType == Attribute.DATE) {
      tmpStr = Utils.getOption('F', options);
      if (tmpStr.length() != 0) setDateFormat(tmpStr);
    }

    if (getInputFormat() != null) {
      setInputFormat(getInputFormat());
    }
  }
Пример #2
0
  public static Instances getDatasetDB(String tableName) throws Exception {
    Statement st = null;
    ResultSet rs = null;
    Connection conn = getDBConn();
    String query;
    switch (tableName) {
      case "all":
        query = Config.selectAll;
        break;
      case "chiller1":
        query = Config.selectChiller1;
        break;
      case "chiller2":
        query = Config.selectChiller2;
        break;
      case "consumption":
        query = Config.selectConsumption;
        break;
      default:
        query = Config.selectAll;
        break;
    }

    st = conn.createStatement();
    rs = st.executeQuery(query);

    ResultSetMetaData rsmd = rs.getMetaData();

    ArrayList<Attribute> attributes = new ArrayList<Attribute>();

    int numAtts = rsmd.getColumnCount();
    for (int i = 1; i <= numAtts; i++) {
      String attName = (rsmd.getColumnName(i));
      Attribute att = new Attribute(attName);
      attributes.add(att);
    }

    Instances data = new Instances(tableName, attributes, 0);

    weka.filters.unsupervised.attribute.Add addAtt = new weka.filters.unsupervised.attribute.Add();
    addAtt.setOptions(weka.core.Utils.splitOptions("-T NOM -N class -L T,F -C last"));
    addAtt.setInputFormat(data);

    data = Filter.useFilter(data, addAtt);
    while (rs.next()) {
      double[] values = new double[numAtts + 1];
      for (int i = 1; i <= numAtts; i++) {
        values[i - 1] = rs.getDouble(i);
      }
      data.add(new DenseInstance(1.0, values));
    }
    return data;
  }