Example usage for weka.core.converters ArffLoader FILE_EXTENSION

List of usage examples for weka.core.converters ArffLoader FILE_EXTENSION

Introduction

In this page you can find the example usage for weka.core.converters ArffLoader FILE_EXTENSION.

Prototype

String FILE_EXTENSION

To view the source code for weka.core.converters ArffLoader FILE_EXTENSION.

Click Source Link

Document

the file extension

Usage

From source file:adams.flow.transformer.WekaInstanceDumper.java

License:Open Source License

/**
 * Generates the filename for the output.
 *
 * @param header   the current relation/*from w w  w .  ja  va 2 s  .c  o m*/
 * @return      the generated filename
 */
protected File createFilename(Instances header) {
    String result;
    File file;

    if (m_UseRelationNameAsFilename) {
        file = new File(m_OutputPrefix.getAbsolutePath());
        result = file.getParent() + File.separator + FileUtils.createFilename(header.relationName(), "_");
    } else {
        result = m_OutputPrefix.getAbsolutePath();
    }

    if (m_Counter > 0)
        result += "-" + m_Counter;

    switch (m_OutputFormat) {
    case ARFF:
        result += ArffLoader.FILE_EXTENSION;
        break;
    case CSV:
        result += CSVLoader.FILE_EXTENSION;
        break;
    case TAB:
        result += CSVLoader.FILE_EXTENSION;
        break;
    default:
        throw new IllegalStateException("Unhandled output format: " + m_OutputFormat);
    }

    return new File(result);
}

From source file:lfsom.data.LFSData.java

License:Apache License

/**
 * Gets the data from a csv file./*from  w ww. j  a v  a 2s. co  m*/
 * 
 * @param fileName
 */

public LFSData(String fileName) {
    Class claseCargador = CSVLoader.class;

    if (fileName.endsWith(ArffLoader.FILE_EXTENSION)) {
        claseCargador = ArffLoader.class;
    } else {
        if (fileName.endsWith(JSONLoader.FILE_EXTENSION)) {
            claseCargador = JSONLoader.class;
        } else {
            if (fileName.endsWith(MatlabLoader.FILE_EXTENSION)) {
                claseCargador = MatlabLoader.class;
            } else {
                if (fileName.endsWith(XRFFLoader.FILE_EXTENSION)) {
                    claseCargador = XRFFLoader.class;
                } else {
                    if (fileName.endsWith(C45Loader.FILE_EXTENSION)) {
                        claseCargador = C45Loader.class;
                    }
                }
            }
        }
    }

    try {
        AbstractFileLoader cargador = (AbstractFileLoader) claseCargador.getConstructor().newInstance();
        boolean cambio_col = false;

        cargador.setSource(new File(fileName));

        Instances data1 = cargador.getDataSet();

        double[][] matrix2 = new double[data1.size()][data1.numAttributes()];

        for (int i = 0; i < data1.size(); i++) {
            matrix2[i] = data1.get(i).toDoubleArray();
        }

        // Ahora se comprueba si todas las columnas son ok

        Integer[] colVale;
        dim = 0;

        if (data1.size() > 0) {
            colVale = new Integer[matrix2[0].length];
            double[] stdevX = StatisticSample.stddeviation(matrix2);

            for (int k = 0; k < matrix2[0].length; k++) {
                if (Math.abs(stdevX[k]) >= 0.000000001) {
                    colVale[k] = dim;
                    dim++;
                } else {
                    colVale[k] = -1;
                    cambio_col = true;
                }
            }

        } else {
            dim = data1.numAttributes();
            colVale = new Integer[dim];
            for (int k = 0; k < dim; k++) {
                colVale[k] = k;
            }
        }

        double[][] matrixAssign = new double[matrix2.length][dim];

        if (cambio_col) {
            for (int k = 0; k < matrix2.length; k++) {
                for (int w = 0; w < matrix2[0].length; w++) {
                    if (colVale[w] != -1) {
                        matrixAssign[k][colVale[w]] = matrix2[k][w];
                    }
                }

            }

        } else {
            matrixAssign = matrix2;
        }

        // Fin de la comprobacion

        setLabels(new String[dim]);
        for (int i = 0; i < data1.numAttributes(); i++) {
            if (colVale[i] != -1) {
                getLabels()[colVale[i]] = data1.attribute(i).name();
            }
        }

        BufferedWriter br = new BufferedWriter(new FileWriter("d:/tmp/fich.csv"));
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < matrixAssign.length; i++) {
            String cad = String.valueOf(matrixAssign[i][0]);
            for (int k = 1; k < matrixAssign[i].length; k++)
                cad += "," + matrixAssign[i][k];
            sb.append(cad + "\n");
        }

        br.write(sb.toString());
        br.close();

        setMatrix(matrixAssign);

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}