Example #1
0
 /**
  * It copies the header of the dataset
  *
  * @return String A string containing all the data-set information
  */
 public String copyHeader() {
   String p = new String("");
   p = "@relation " + Attributes.getRelationName() + "\n";
   p += Attributes.getInputAttributesHeader();
   p += Attributes.getOutputAttributesHeader();
   p += Attributes.getInputHeader() + "\n";
   p += Attributes.getOutputHeader() + "\n";
   p += "@data\n";
   return p;
 }
Example #2
0
  /**
   * Generating the header of the output file @ param p PrintStream
   *
   * @return Nothing
   */
  private void CopyHeaderTest(PrintStream p) {

    // Header of the output file
    p.println("@relation " + Attributes.getRelationName());
    p.print(Attributes.getInputAttributesHeader());
    p.print(Attributes.getOutputAttributesHeader());
    p.println(Attributes.getInputHeader());
    p.println(Attributes.getOutputHeader());
    p.println("@data");
  }
Example #3
0
  /**
   * Init a new set of instances
   *
   * @param nfexamples Name of the dataset file
   * @param train The dataset file is for training or for test
   */
  public ProcDataset(String nfexamples, boolean train) throws IOException {

    try {
      IS = new InstanceSet();
      IS.readSet(nfexamples, train);
      System.out.println("Dataset analyzed: " + Attributes.getRelationName());
    } catch (Exception e) {
      System.out.println("Exception in readSet");
      e.printStackTrace();
    }
  }
Example #4
0
  /** It does return the original header definiton but without @input and @output in there */
  public String getOriginalHeaderWithoutInOut() {
    String line = "";
    Attribute[] attrs = null;

    // Getting the relation name and the attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      line = "@relation " + attributes.getRelationName() + "\n";
      attrs = attributes.getAttributes();
    } else {
      line = "@relation " + Attributes.getRelationName() + "\n";
      attrs = Attributes.getAttributes();
    }

    for (int i = 0; i < attrs.length; i++) {
      line += attrs[i].toString() + "\n";
    }
    return line;
  } // end getOriginalHeaderWithoutInOut
Example #5
0
  /**
   * It does return a new header (not necessary the same header as the input file one). It only
   * includes the valid attributes, those ones defined in @inputs and @outputs (or taken as that
   * role following the keel format specification).
   *
   * @return a String with the new header
   */
  public String getNewHeader() {
    String line = "";
    Attribute[] attrs = null;

    // Getting the relation name and the attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      line = "@relation " + attributes.getRelationName() + "\n";
      attrs = attributes.getInputAttributes();
    } else {
      line = "@relation " + Attributes.getRelationName() + "\n";
      attrs = Attributes.getInputAttributes();
    }

    for (int i = 0; i < attrs.length; i++) {
      line += attrs[i].toString() + "\n";
    }

    // Gettin all the outputs attributes
    if (storeAttributesAsNonStatic && attributes != null) {
      attrs = attributes.getOutputAttributes();
      line += attrs[0].toString() + "\n";

      // Getting @inputs and @outputs
      line += attributes.getInputHeader() + "\n";
      line += attributes.getOutputHeader() + "\n";
    } else {
      attrs = Attributes.getOutputAttributes();
      line += attrs[0].toString() + "\n";

      // Getting @inputs and @outputs
      line += Attributes.getInputHeader() + "\n";
      line += Attributes.getOutputHeader() + "\n";
    }

    return line;
  } // end getNewHeader
Example #6
0
  /** Function to stores header of a data file. */
  private void readHeader() {
    String attributeName;
    Vector attributeValues;
    int i;

    name = Attributes.getRelationName();

    // Create vectors to hold information temporarily.
    attributes = new Vector();

    Attribute at;

    // store attribute inputs and of the header
    for (int j = 0; j < Attributes.getInputNumAttributes(); j++) {
      at = Attributes.getInputAttribute(j);
      attributeName = at.getName();

      // check if it is real
      if (at.getType() == 2) {
        float min = (float) at.getMinAttribute();
        float max = (float) at.getMinAttribute();
        attributes.addElement(new MyAttribute(attributeName, j));
        MyAttribute att = (MyAttribute) attributes.elementAt(j);
        att.setRange(min, max);
        att.activate();
      } else {
        if (at.getType() == 1) // check if it is integer
        {
          int min = (int) at.getMinAttribute();
          int max = (int) at.getMinAttribute();
          attributes.addElement(new MyAttribute(attributeName, j));
          MyAttribute att = (MyAttribute) attributes.elementAt(j);
          att.setRange(min, max);
          att.activate();
        } else // it is nominal
        {
          attributeValues = new Vector();
          for (int k = 0; k < at.getNumNominalValues(); k++) {
            attributeValues.addElement(at.getNominalValue(k));
          }
          attributes.addElement(new MyAttribute(attributeName, attributeValues, j));
          MyAttribute att = (MyAttribute) attributes.elementAt(j);
          att.activate();
        }
      }
    } // for

    // store outputs of the header
    at = Attributes.getOutputAttribute(0);
    attributeName = at.getName();

    int j = Attributes.getNumAttributes() - 1;

    // check if it is real
    if (at.getType() == 2) {
      float min = (float) at.getMinAttribute();
      float max = (float) at.getMinAttribute();
      attributes.addElement(new MyAttribute(attributeName, j));
      MyAttribute att = (MyAttribute) attributes.elementAt(j);
      att.setRange(min, max);
      att.activate();
    } else {
      if (at.getType() == 1) // check if it is integer
      {
        int min = (int) at.getMinAttribute();
        int max = (int) at.getMinAttribute();
        attributes.addElement(new MyAttribute(attributeName, j));
        MyAttribute att = (MyAttribute) attributes.elementAt(j);
        att.setRange(min, max);
        att.activate();
      } else // it is nominal
      {
        attributeValues = new Vector();
        for (int k = 0; k < at.getNumNominalValues(); k++) {
          attributeValues.addElement(at.getNominalValue(k));
        }
        attributes.addElement(new MyAttribute(attributeName, attributeValues, j));
        MyAttribute att = (MyAttribute) attributes.elementAt(j);
        att.activate();
      }
    }

    // set the index of the output class
    classIndex = Attributes.getNumAttributes() - 1;
  }