Example usage for weka.core.converters JSONSaver JSONSaver

List of usage examples for weka.core.converters JSONSaver JSONSaver

Introduction

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

Prototype

public JSONSaver() 

Source Link

Document

Constructor.

Usage

From source file:adams.data.io.output.JSONSpreadSheetWriter.java

License:Open Source License

/**
 * Returns an instance of the file loader.
 * /*from  www  .  j  a  v a2  s .  com*/
 * @return      the file loader
 */
@Override
protected AbstractFileSaver newSaver() {
    return new JSONSaver();
}

From source file:com.kdcloud.lib.rest.ext.InstancesRepresentation.java

License:Open Source License

protected Saver getSaver() throws IOException {
    if (getMediaType().equals(MediaType.TEXT_PLAIN))
        return new ArffSaver();
    else if (getMediaType().equals(MediaType.TEXT_CSV))
        return new CSVSaver();
    else if (getMediaType().equals(MediaType.APPLICATION_JSON))
        return new JSONSaver();
    else// www. ja  v a  2 s . co  m
        raiseNotSupportedMediaType();
    return null;
}

From source file:gate.plugin.learningframework.data.CorpusRepresentationWeka.java

/**
 * Export the data. If parms is null then default ARFF format is used. In addition, parms can
 * contain the parameter -format fmt and additional parameters specific to the format. If format
 * is/*ww  w  . j  a  v  a2  s. c o  m*/
 * <ul>
 * <li> "csv": -F fieldSeparator (default is tab) -M missingValueString (default is ?) -N
 * (suppress header row, default is no)
 * <li> "
 *
 * @param directory
 * @param format
 */
public void export(File directory, String parms) {
    if (parms == null || parms.isEmpty()) {
        System.err.println("EXPORTING using ArffSaver");
        ArffSaver saver = new ArffSaver();
        saver.setInstances(data);
        File outFile = new File(directory, "data.arff");
        try {
            saver.setFile(outFile);
        } catch (IOException ex) {
            throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
        }
        try {
            saver.writeBatch();
        } catch (IOException ex) {
            throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
        }
    } else {
        // first parse the parms to see if we have a -format value
        Parms ps = new Parms(parms, "f:format:s");
        String format = (String) ps.getValueOrElse("format", "");
        if (format.equals("csv")) {
            ps = new Parms(parms, "F:F:s", "M:M:s", "N:N:b");
            String fieldSep = gate.util.Strings.unescape((String) ps.getValueOrElse("F", "\\t"));
            String mv = gate.util.Strings.unescape((String) ps.getValueOrElse("M", "?"));
            boolean noHeader = (boolean) ps.getValueOrElse("N", true);
            CSVSaver saver = new CSVSaver();
            saver.setInstances(data);
            File outFile = new File(directory, "data.csv");
            try {
                saver.setFile(outFile);
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
            try {
                saver.writeBatch();
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
        } else if (format.equals("json")) {
            File outFile = new File(directory, "data.json");
            JSONSaver saver = new JSONSaver();
            saver.setInstances(data);
            try {
                saver.setFile(outFile);
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
            try {
                saver.writeBatch();
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
        } else if (format.equals("libsvm")) {
            File outFile = new File(directory, "data.libsvm");
            LibSVMSaver saver = new LibSVMSaver();
            saver.setInstances(data);
            try {
                saver.setFile(outFile);
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
            try {
                saver.writeBatch();
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
        } else if (format.equals("svmlight")) {
            File outFile = new File(directory, "data.svmlight");
            SVMLightSaver saver = new SVMLightSaver();
            saver.setInstances(data);
            try {
                saver.setFile(outFile);
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
            try {
                saver.writeBatch();
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
        } else if (format.equals("matlab")) {
            File outFile = new File(directory, "data.m");
            MatlabSaver saver = new MatlabSaver();
            saver.setInstances(data);
            try {
                saver.setFile(outFile);
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
            try {
                saver.writeBatch();
            } catch (IOException ex) {
                throw new GateRuntimeException("Error exporting Weka data to " + outFile, ex);
            }
        } else {
            throw new GateRuntimeException("Unknown format for exporting Weka representation: " + format);
        }
    }
}