geneticWedge.gp.io
Class TextReader

java.lang.Object
  extended by geneticWedge.gp.io.TextReader

public class TextReader
extends java.lang.Object

This class contains static methods for reading files and returning StringData or NumericData objects. It also contains utility methods to randomly order data and to remove duplicates from datasets.


Constructor Summary
TextReader()
           
 
Method Summary
static void randomiseLines(java.lang.String filename, java.lang.String newFileName, boolean namesInFirstRow)
          Randomises the data in the file filename and writes it to the file newFileName.
static NumericData readFile(java.lang.String filename, java.lang.String separator, boolean labelsInFirstColumn)
          This method reads data from a file.
static StringData readStringFile(java.lang.String filename, java.lang.String separator, boolean namesInFirstRow, boolean labelsInFirstColumn)
          Returns a StringData object by reading a file named filename.
static void removeDuplicates(java.lang.String filename, java.lang.String newFileName, boolean labelsInFirstColumn, java.lang.String separator)
          Removes duplicated data from the dataset in filename and writes the 'clean' dataset to newFileName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextReader

public TextReader()
Method Detail

readFile

public static NumericData readFile(java.lang.String filename,
                                   java.lang.String separator,
                                   boolean labelsInFirstColumn)
                            throws java.io.FileNotFoundException,
                                   java.io.IOException,
                                   java.lang.NumberFormatException
This method reads data from a file. Separate data are identified via a separator character(s). If the first row of the csv file contains variable names,this will be automatically detected by the reader and the variable names may be retrieved from the NumericData object by calling getNames().

Parameters:
labelsInFirstColumn - If true, the first column will be treated as data labels rather than data. The labels may be retrieved from the NumericData object by calling getLabels().
Throws:
java.io.FileNotFoundException
java.io.IOException
java.lang.NumberFormatException

readStringFile

public static StringData readStringFile(java.lang.String filename,
                                        java.lang.String separator,
                                        boolean namesInFirstRow,
                                        boolean labelsInFirstColumn)
                                 throws java.io.FileNotFoundException,
                                        java.io.IOException
Returns a StringData object by reading a file named filename.

Parameters:
filename - A path to the csv file
separator - The character(s) used as a data separator
namesInFirstRow - If true, the first column will be treated as variable names rather than data. The names will be saved and can be retrieved from the NumericData object by calling getNames()
labelsInFirstColumn - If true, the first column will be treated as String labels rather than data. The labels will be saved and can be retrieved from the NumericData object by calling getLabels()
Throws:
java.io.FileNotFoundException
java.io.IOException

randomiseLines

public static void randomiseLines(java.lang.String filename,
                                  java.lang.String newFileName,
                                  boolean namesInFirstRow)
Randomises the data in the file filename and writes it to the file newFileName.

Parameters:
namesInFirstRow - True if filename contains column headings, false otherwise.

removeDuplicates

public static void removeDuplicates(java.lang.String filename,
                                    java.lang.String newFileName,
                                    boolean labelsInFirstColumn,
                                    java.lang.String separator)
                             throws java.io.IOException
Removes duplicated data from the dataset in filename and writes the 'clean' dataset to newFileName.

Parameters:
labelsInFirstColumn - True if the first column contains data labels, false otherwise
separator - The separator used in filename.
Throws:
java.io.IOException