util.io
Class IOUtils

java.lang.Object
  extended by util.io.IOUtils

public class IOUtils
extends java.lang.Object

This class takes care of various I/O related tasks.

Author:
Michiel Van Bel

Constructor Summary
IOUtils(org.apache.log4j.Logger logger, ClassificationAction ca)
          Constructor.
 
Method Summary
 int getLinesInFile(java.io.File file)
          Returns the number of lines (terminated by a carriage return) in the file
 java.io.File makeCopyAndDestroyOriginal(java.io.File original)
          Makes a copy of the file (with a new name), and then destroys the original.
static void mergeFiles(java.io.File output, java.io.File[] files)
          Merges a number of files, by which it is assumed that the lines are space-formatted, and contain space seperated fields.
 void writeCrossValidation(CrossValidationResult result, java.io.File featureFile, int trainPos, int testPos, int trainNeg, int testNeg)
          This methods writes the results of a crossvalidation to a file.
 void writeRocGnuPlotCommand(java.util.List<RocCurveData> fileNames, java.lang.String path)
          This method generates the Gnuplot-commands to display the roc-curves (only possible with cross-validation).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtils

public IOUtils(org.apache.log4j.Logger logger,
               ClassificationAction ca)
Constructor.

Parameters:
logger - Logging facility, really needed because a lot of methods might cause problems and throw exceptions.
ca - The classificationAction to which this instantiaton of IOUtils belongs to.
Method Detail

getLinesInFile

public int getLinesInFile(java.io.File file)
Returns the number of lines (terminated by a carriage return) in the file

Parameters:
file - The file of which we want the number of lines
Returns:
The number of lines

makeCopyAndDestroyOriginal

public java.io.File makeCopyAndDestroyOriginal(java.io.File original)
                                        throws java.io.IOException
Makes a copy of the file (with a new name), and then destroys the original. This method can be used to apply featureselection to feature files.

Parameters:
original - The original File
Returns:
The copied file, with as name the original with "_copy" added
Throws:
java.io.IOException - When diskoperations/filesystemoperations fail

mergeFiles

public static void mergeFiles(java.io.File output,
                              java.io.File[] files)
                       throws java.io.IOException,
                              java.lang.NullPointerException
Merges a number of files, by which it is assumed that the lines are space-formatted, and contain space seperated fields. The output is then sorted according to these numbers. Technically, the array of inputFiles should not contain the outputFile, but normally an exception is thrown when trying to write and read at the same time, so it should not cause problems.

Parameters:
output - The outputFile
files - The inputFiles
Throws:
java.io.IOException - Thrown when a diskoperation cannot be completed
java.lang.NullPointerException - Thrown when a file is null

writeCrossValidation

public void writeCrossValidation(CrossValidationResult result,
                                 java.io.File featureFile,
                                 int trainPos,
                                 int testPos,
                                 int trainNeg,
                                 int testNeg)
This methods writes the results of a crossvalidation to a file. This includes pretty basic stuff such as the amount of true positives and false positives, but also deducted information such as the F_1 measure and the specificity. While it may seem incoherent to need both the featurefile and trainPos/trainNeg data, it is clear this is needed because we may use a special case of crossvalidation in which the data is not split evenly, thus we need more information about the total amount of trainingdata It is assumed that the crossvalidationresult has allready computed all the deducted information.

Parameters:
result - The crossvalidation result
featureFile - File containing the features
trainPos - The number positive training examples used
testPos - The number of positive test examples used
trainNeg - The number of negative training examples used
testNeg - The number of negative test examples used

writeRocGnuPlotCommand

public void writeRocGnuPlotCommand(java.util.List<RocCurveData> fileNames,
                                   java.lang.String path)
This method generates the Gnuplot-commands to display the roc-curves (only possible with cross-validation). Two different gnuplot-command files are generated : a) The first one displays all the roc-curves on a single display. While this works for a limited amount of roc-curves that are also rather divergent, it has limited applicability when the amount of roc-curves increases. b) A command which displays (and stores as png-files) all couples of roc-curves. This is thus easily usable for comparing all the roc-curves.

Parameters:
fileNames - A list with all the filenames and data which contain roc-curve data
path - The path in which to place the resulting gnuplot-command file