001    /*
002     * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003     *
004     * This file is part of the Java Data Mining Package (JDMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * JDMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * JDMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with JDMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.jdmp.weka.wrappers;
025    
026    import org.jdmp.core.dataset.ClassificationDataSet;
027    import org.jdmp.core.dataset.RegressionDataSet;
028    import org.ujmp.core.Matrix;
029    import org.ujmp.core.calculation.Calculation.Ret;
030    
031    import weka.core.FastVector;
032    
033    public class DataSetToAttributeInfoWrapper extends FastVector {
034            private static final long serialVersionUID = -5668139225494255695L;
035    
036            public DataSetToAttributeInfoWrapper(RegressionDataSet dataSet, boolean discrete) {
037                    super();
038    
039                    // for (Attribute f : dataSet.getAttributes()) {
040                    // weka.core.Attribute a = null;
041                    // if (f.isDiscrete()) {
042                    // FastVector values = new FastVector();
043                    // for (int i = 0; i < f.getValueCount(); i++) {
044                    // values.addElement("Attribute " + i);
045                    // }
046                    // a = new weka.core.Attribute(f.getLabel(), values);
047                    // } else {
048                    // a = new weka.core.Attribute(f.getLabel());
049                    // }
050                    // addElement(a);
051                    // }
052                    Matrix valueCounts = dataSet.getInputMatrix().max(Ret.NEW, Matrix.ROW).plus(1);
053                    for (int j = 0; j < dataSet.getInputMatrix().getColumnCount(); j++) {
054                            weka.core.Attribute a = null;
055                            if (discrete) {
056                                    FastVector values = new FastVector();
057                                    for (int i = 0; i < valueCounts.getAsDouble(0, j); i++) {
058                                            values.addElement("Attribute " + i);
059                                    }
060                                    a = new weka.core.Attribute(j + "", values);
061                            } else {
062                                    a = new weka.core.Attribute(j + "");
063                            }
064                            addElement(a);
065                    }
066    
067                    FastVector classes = new FastVector();
068                    for (int i = 0; i < ((ClassificationDataSet) dataSet).getClassCount(); i++) {
069                            classes.addElement("Class " + i);
070                    }
071                    weka.core.Attribute a = new weka.core.Attribute("class", classes);
072                    addElement(a);
073            }
074    }