Example #1
0
  private void createRule(Item item, ArrayList<FuzzyAttribute> fuzzy_attributes, PrintWriter w) {
    int attr;
    boolean stop;
    FuzzyAttribute fuzzy_attr;
    FuzzyRegion[] fuzzy_regions;

    attr = item.getIDAttribute();

    if (this.trans.isNominal(attr)) {
      w.print("<attribute name = \"" + this.trans.getAttributeName(attr) + "\" value=\"");
      w.print("" + this.trans.getNominalValue(attr, item.getIDLabel()));
    } else {
      stop = false;
      fuzzy_attr = fuzzy_attributes.get(0);
      for (int i = 0; i < fuzzy_attributes.size() && !stop; i++) {
        fuzzy_attr = fuzzy_attributes.get(i);
        if (fuzzy_attr.getIdAttr() == item.getIDAttribute()) stop = true;
      }
      fuzzy_regions = fuzzy_attr.getFuzzyRegions();

      w.print(
          "<attribute name = \""
              + trans.getAttributeName(fuzzy_attr.getIdAttr())
              + "\" value = \"");
      w.print(fuzzy_regions[item.getIDLabel()].getLabel());
    }
    w.println("\" />");
  }
Example #2
0
  private void saveFuzzyAttributes(
      String fuzzy_attrs_fname, ArrayList<FuzzyAttribute> fuzzy_attributes)
      throws FileNotFoundException {
    int attr, region, id_attr;
    boolean stop;
    FuzzyRegion[] fuzzy_regions;
    FuzzyAttribute fuzzy_attr;
    PrintWriter fuzzy_attrs_writer = new PrintWriter(fuzzy_attrs_fname);

    fuzzy_attrs_writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    fuzzy_attrs_writer.println("<data_base>");

    for (attr = 0; attr < this.trans.getnVars(); attr++) {
      if (this.trans.isNominal(attr)) {
        fuzzy_attrs_writer.println(
            "<attribute name = \""
                + this.trans.getAttributeName(attr)
                + "\" nValues = \""
                + this.trans.nValueNominal(attr)
                + "\" Type = \""
                + this.trans.getAttributeTypeString(attr)
                + "\" >");

        for (region = 0; region < this.trans.nValueNominal(attr); region++) {
          fuzzy_attrs_writer.println(
              "<value \"" + this.trans.getNominalValue(attr, region) + "\" />");
        }
      } else {
        fuzzy_attrs_writer.println(
            "<attribute name = \""
                + this.trans.getAttributeName(attr)
                + "\" nValues = \""
                + this.nFuzzyRegionsForNumericAttributes
                + "\" Type = \""
                + this.trans.getAttributeTypeString(attr)
                + "\" >");
        stop = false;
        fuzzy_attr = fuzzy_attributes.get(0);
        for (int i = 0; i < fuzzy_attributes.size() && !stop; i++) {
          fuzzy_attr = fuzzy_attributes.get(i);
          if (fuzzy_attr.getIdAttr() == attr) stop = true;
        }
        fuzzy_regions = fuzzy_attr.getFuzzyRegions();
        for (region = 0; region < fuzzy_regions.length; region++) {
          fuzzy_attrs_writer.print("<value \"" + fuzzy_regions[region].getLabel() + "\" ");
          fuzzy_attrs_writer.print("\"" + fuzzy_regions[region].getX0() + "\" ");
          fuzzy_attrs_writer.print("\"" + fuzzy_regions[region].getX1() + "\" ");
          fuzzy_attrs_writer.println("\"" + fuzzy_regions[region].getX3() + "\" />");
        }
      }

      fuzzy_attrs_writer.println("</attribute>");
    }

    fuzzy_attrs_writer.println("</data_base>");
    fuzzy_attrs_writer.close();
  }