weka.core.converters

## Class JSONSaver

- java.lang.Object
- - weka.core.converters.AbstractSaver
  - - weka.core.converters.AbstractFileSaver
    - - weka.core.converters.JSONSaver

- All Implemented Interfaces:
    java.io.Serializable, CapabilitiesHandler, CapabilitiesIgnorer, BatchConverter, FileSourcedConverter, Saver, EnvironmentHandler, OptionHandler, RevisionHandler, WeightedInstancesHandler

      public class JSONSaver
      extends AbstractFileSaver
      implements BatchConverter, WeightedInstancesHandler

  Writes to a destination that is in JSON format.
  The data can be compressed with gzip, in order to save space.
  For more information, see JSON homepage:
  http://www.json.org/

  Valid options are:

       -i <the input file>
        The input file

       -o <the output file>
        The output file

       -C <class index>
        The class index (first and last are valid as well).
        (default: last)

       -compress
        Compresses the data (uses '.json.gz' as extension instead of '.json')
        (default: off)

  Version:
    $Revision: 14860 $
  Author:
    FracPete (fracpete at waikato dot ac dot nz)
  See Also:
    `Saver`, Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface weka.core.converters.Saver

      `BATCH, INCREMENTAL, NONE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JSONSaver()` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `classIndexTipText()` Returns the tip text for this property.
    `java.lang.String` | `compressOutputTipText()` Returns the tip text for this property.
    `Capabilities` | `getCapabilities()` Returns the Capabilities of this saver.
    `java.lang.String` | `getClassIndex()` Get the index of the class attribute.
    `boolean` | `getCompressOutput()` Gets whether the output data is compressed.
    `java.lang.String` | `getFileDescription()` Returns a description of the file type.
    `java.lang.String[]` | `getFileExtensions()` Gets all the file extensions used for this type of file.
    `java.lang.String[]` | `getOptions()` returns the options of the current setup.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `java.lang.String` | `globalInfo()` Returns a string describing this Saver.
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `static void` | `main(java.lang.String[] args)` Main method.
    `void` | `resetOptions()` Resets the Saver.
    `void` | `setClassIndex(java.lang.String value)` Sets index of the class attribute.
    `void` | `setCompressOutput(boolean value)` Sets whether to compress the output.
    `void` | `setDestination(java.io.OutputStream output)` Sets the destination output stream.
    `void` | `setFile(java.io.File outputFile)` Sets the destination file.
    `void` | `setInstances(Instances instances)` Sets instances that should be stored.
    `void` | `setOptions(java.lang.String[] options)` Parses the options for this object.
    `void` | `writeBatch()` Writes a Batch of instances.

    - ### Methods inherited from class weka.core.converters.AbstractFileSaver

      `cancel, filePrefix, getFileExtension, getUseRelativePath, getWriter, resetWriter, retrieveDir, retrieveFile, runFileSaver, setDestination, setDir, setDirAndPrefix, setEnvironment, setFilePrefix, setUseRelativePath, useRelativePathTipText`

    - ### Methods inherited from class weka.core.converters.AbstractSaver

      `doNotCheckCapabilitiesTipText, getDoNotCheckCapabilities, getInstances, getWriteMode, resetStructure, setDoNotCheckCapabilities, setRetrieval, setStructure, writeIncremental`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JSONSaver

          public JSONSaver()

      Constructor.

  - ### Method Detail

    - #### globalInfo

          public java.lang.String globalInfo()

      Returns a string describing this Saver.
      Returns:
        a description of the Saver suitable for displaying in the explorer/experimenter gui

    - #### listOptions

          public java.util.Enumeration<Option> listOptions()

      Returns an enumeration describing the available options.
      Specified by:
        `listOptions` in interface `OptionHandler`
      Overrides:
        `listOptions` in class `AbstractFileSaver`
      Returns:
        an enumeration of all the available options.

    - #### getOptions

          public java.lang.String[] getOptions()

      returns the options of the current setup.
      Specified by:
        `getOptions` in interface `OptionHandler`
      Overrides:
        `getOptions` in class `AbstractFileSaver`
      Returns:
        the current options

    - #### setOptions

          public void setOptions(java.lang.String[] options)
                          throws java.lang.Exception

      Parses the options for this object.

      Valid options are:

           -i <the input file>
            The input file

           -o <the output file>
            The output file

           -C <class index>
            The class index (first and last are valid as well).
            (default: last)

           -compress
            Compresses the data (uses '.json.gz' as extension instead of '.json')
            (default: off)

      Specified by:
        `setOptions` in interface `OptionHandler`
      Overrides:
        `setOptions` in class `AbstractFileSaver`
      Parameters:
        `options` - the options to use
      Throws:
        `java.lang.Exception` - if setting of options fails

    - #### getFileDescription

          public java.lang.String getFileDescription()

      Returns a description of the file type.
      Specified by:
        `getFileDescription` in interface `FileSourcedConverter`
      Specified by:
        `getFileDescription` in class `AbstractFileSaver`
      Returns:
        a short file description

    - #### getFileExtensions

          public java.lang.String[] getFileExtensions()

      Gets all the file extensions used for this type of file.
      Specified by:
        `getFileExtensions` in interface `FileSourcedConverter`
      Overrides:
        `getFileExtensions` in class `AbstractFileSaver`
      Returns:
        the file extensions

    - #### setFile

          public void setFile(java.io.File outputFile)
                       throws java.io.IOException

      Sets the destination file.
      Specified by:
        `setFile` in interface `FileSourcedConverter`
      Specified by:
        `setFile` in interface `Saver`
      Overrides:
        `setFile` in class `AbstractFileSaver`
      Parameters:
        `outputFile` - the destination file.
      Throws:
        `java.io.IOException` - throws an IOException if file cannot be set

    - #### resetOptions

          public void resetOptions()

      Resets the Saver.
      Overrides:
        `resetOptions` in class `AbstractFileSaver`

    - #### classIndexTipText

          public java.lang.String classIndexTipText()

      Returns the tip text for this property.
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getClassIndex

          public java.lang.String getClassIndex()

      Get the index of the class attribute.
      Returns:
        the index of the class attribute

    - #### setClassIndex

          public void setClassIndex(java.lang.String value)

      Sets index of the class attribute.
      Parameters:
        `value` - the index of the class attribute

    - #### compressOutputTipText

          public java.lang.String compressOutputTipText()

      Returns the tip text for this property.
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getCompressOutput

          public boolean getCompressOutput()

      Gets whether the output data is compressed.
      Returns:
        true if the output data is compressed

    - #### setCompressOutput

          public void setCompressOutput(boolean value)

      Sets whether to compress the output.
      Parameters:
        `value` - if truee the output will be compressed

    - #### getCapabilities

          public Capabilities getCapabilities()

      Returns the Capabilities of this saver.
      Specified by:
        `getCapabilities` in interface `CapabilitiesHandler`
      Overrides:
        `getCapabilities` in class `AbstractSaver`
      Returns:
        the capabilities of this object
      See Also:
        `Capabilities`

    - #### setInstances

          public void setInstances(Instances instances)

      Sets instances that should be stored.
      Specified by:
        `setInstances` in interface `Saver`
      Overrides:
        `setInstances` in class `AbstractSaver`
      Parameters:
        `instances` - the instances

    - #### setDestination

          public void setDestination(java.io.OutputStream output)
                              throws java.io.IOException

      Sets the destination output stream.
      Specified by:
        `setDestination` in interface `Saver`
      Overrides:
        `setDestination` in class `AbstractFileSaver`
      Parameters:
        `output` - the output stream.
      Throws:
        `java.io.IOException` - throws an IOException if destination cannot be set

    - #### writeBatch

          public void writeBatch()
                          throws java.io.IOException

      Writes a Batch of instances.
      Specified by:
        `writeBatch` in interface `Saver`
      Specified by:
        `writeBatch` in class `AbstractSaver`
      Throws:
        `java.io.IOException` - throws IOException if saving in batch mode is not possible

    - #### getRevision

          public java.lang.String getRevision()

      Returns the revision string.
      Specified by:
        `getRevision` in interface `RevisionHandler`
      Returns:
        the revision

    - #### main

          public static void main(java.lang.String[] args)

      Main method.
      Parameters:
        `args` - should contain the options of a Saver.