Package weka.core.converters
Class AbstractFileSaver
java.lang.Object
weka.core.converters.AbstractSaver
weka.core.converters.AbstractFileSaver
- All Implemented Interfaces:
Serializable
,CapabilitiesHandler
,CapabilitiesIgnorer
,FileSourcedConverter
,Saver
,EnvironmentHandler
,OptionHandler
,RevisionHandler
- Direct Known Subclasses:
ArffSaver
,C45Saver
,CSVSaver
,DictionarySaver
,JSONSaver
,LibSVMSaver
,MatlabSaver
,SerializedInstancesSaver
,SVMLightSaver
,XRFFSaver
public abstract class AbstractFileSaver
extends AbstractSaver
implements OptionHandler, FileSourcedConverter, EnvironmentHandler
Abstract class for Savers that save to a file
Valid options are:
-i input arff file
The input filw in arff format.
The input filw in arff format.
-o the output file
The output file. The prefix of the output file is sufficient. If no output
file is given, Saver tries to use standard out.
- Version:
- $Revision: 12074 $
- Author:
- Richard Kirkby (rkirkby@cs.waikato.ac.nz), Stefan Mutter (mutter@cs.waikato.ac.nz)
- See Also:
-
Field Summary
Fields inherited from interface weka.core.converters.Saver
BATCH, INCREMENTAL, NONE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancels the incremental saving process.Gets the file name prefixabstract String
to be pverriddenGets ihe file extension.String[]
Gets all the file extensions used for this type of fileString[]
Gets the current settings of the Saver object.boolean
Gets whether relative paths are to be usedGets the writerReturns an enumeration describing the available options.void
resets the optionsvoid
Sets the writer to null.Gets the directoryGets the destination file.static void
runFileSaver
(AbstractFileSaver saver, String[] options) runs the given saver with the specified optionsvoid
setDestination
(File file) Sets the destination file (and directories if necessary).void
setDestination
(OutputStream output) Sets the destination output stream.void
Sets the directory where the instances should be storedvoid
setDirAndPrefix
(String relationName, String add) Sets the directory and the file prefix.void
Set the environment variables to use.void
Sets the destination file.void
setFilePrefix
(String prefix) Sets the file name prefixvoid
setOptions
(String[] options) Parses a given list of options.void
setUseRelativePath
(boolean rp) Set whether to use relative rather than absolute pathsTip text suitable for displaying int the GUIMethods inherited from class weka.core.converters.AbstractSaver
doNotCheckCapabilitiesTipText, getCapabilities, getDoNotCheckCapabilities, getInstances, getWriteMode, resetStructure, setDoNotCheckCapabilities, setInstances, setRetrieval, setStructure, writeBatch, writeIncremental
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface weka.core.RevisionHandler
getRevision
-
Constructor Details
-
AbstractFileSaver
public AbstractFileSaver()
-
-
Method Details
-
resetOptions
public void resetOptions()resets the options- Overrides:
resetOptions
in classAbstractSaver
-
getWriter
Gets the writer- Returns:
- the BufferedWriter
-
resetWriter
public void resetWriter()Sets the writer to null. -
getFileExtension
Gets ihe file extension.- Specified by:
getFileExtension
in interfaceFileSourcedConverter
- Specified by:
getFileExtension
in interfaceSaver
- Overrides:
getFileExtension
in classAbstractSaver
- Returns:
- the file extension as a string.
-
getFileExtensions
Gets all the file extensions used for this type of file- Specified by:
getFileExtensions
in interfaceFileSourcedConverter
- Returns:
- the file extensions
-
retrieveFile
Gets the destination file.- Specified by:
retrieveFile
in interfaceFileSourcedConverter
- Returns:
- the destination file.
-
setFile
Sets the destination file.- Specified by:
setFile
in interfaceFileSourcedConverter
- Specified by:
setFile
in interfaceSaver
- Overrides:
setFile
in classAbstractSaver
- Parameters:
outputFile
- the destination file.- Throws:
IOException
- throws an IOException if file cannot be set
-
setFilePrefix
Sets the file name prefix- Specified by:
setFilePrefix
in interfaceSaver
- Overrides:
setFilePrefix
in classAbstractSaver
- Parameters:
prefix
- the file name prefix
-
filePrefix
Gets the file name prefix- Specified by:
filePrefix
in interfaceSaver
- Overrides:
filePrefix
in classAbstractSaver
- Returns:
- the prefix of the filename
-
setDir
Sets the directory where the instances should be stored- Specified by:
setDir
in interfaceSaver
- Overrides:
setDir
in classAbstractSaver
- Parameters:
dir
- a string containing the directory path and name
-
retrieveDir
Gets the directory- Specified by:
retrieveDir
in interfaceSaver
- Overrides:
retrieveDir
in classAbstractSaver
- Returns:
- a string with the file name
-
setEnvironment
Set the environment variables to use.- Specified by:
setEnvironment
in interfaceEnvironmentHandler
- Parameters:
env
- the environment variables to use
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options. Valid option is:-i input arff file
The input filw in arff format.-o the output file
The output file. The prefix of the output file is sufficient. If no output file is given, Saver tries to use standard out.- Specified by:
setOptions
in interfaceOptionHandler
- Parameters:
options
- the list of options as an array of strings- Throws:
Exception
- if an option is not supported
-
getOptions
Gets the current settings of the Saver object.- Specified by:
getOptions
in interfaceOptionHandler
- Returns:
- an array of strings suitable for passing to setOptions
-
cancel
public void cancel()Cancels the incremental saving process.- Overrides:
cancel
in classAbstractSaver
-
setDestination
Sets the destination file (and directories if necessary).- Specified by:
setDestination
in interfaceSaver
- Overrides:
setDestination
in classAbstractSaver
- Parameters:
file
- the File- Throws:
IOException
- always
-
setDestination
Sets the destination output stream.- Specified by:
setDestination
in interfaceSaver
- Overrides:
setDestination
in classAbstractSaver
- Parameters:
output
- the output stream.- Throws:
IOException
- throws an IOException if destination cannot be set
-
setDirAndPrefix
Sets the directory and the file prefix. This method is used in the KnowledgeFlow GUI- Specified by:
setDirAndPrefix
in interfaceSaver
- Overrides:
setDirAndPrefix
in classAbstractSaver
- Parameters:
relationName
- the name of the relation to saveadd
- additional string which should be part of the filename
-
getFileDescription
to be pverridden- Specified by:
getFileDescription
in interfaceFileSourcedConverter
- Returns:
- the file type description.
-
useRelativePathTipText
Tip text suitable for displaying int the GUI- Returns:
- a description of this property as a String
-
setUseRelativePath
public void setUseRelativePath(boolean rp) Set whether to use relative rather than absolute paths- Specified by:
setUseRelativePath
in interfaceFileSourcedConverter
- Parameters:
rp
- true if relative paths are to be used
-
getUseRelativePath
public boolean getUseRelativePath()Gets whether relative paths are to be used- Specified by:
getUseRelativePath
in interfaceFileSourcedConverter
- Returns:
- true if relative paths are to be used
-
runFileSaver
runs the given saver with the specified options- Parameters:
saver
- the saver to runoptions
- the commandline options
-