Facemorph.DataBase
Class Batch

java.lang.Object
  extended by Facemorph.DataBase.Batch

public class Batch
extends java.lang.Object

Batch stores a list of image files and template files, together with any variables including ID defined


Nested Class Summary
 class Batch.BatchFileException
           
static class Batch.Type
          Describes the type of a Object to allow the system to determine compatability
 
Field Summary
protected  java.lang.String baseDirectory
          Base directory of the files in the Batch
static java.awt.Color colour_exists
           
static java.awt.Color colour_invalid
           
static java.awt.Color colour_unknown
           
protected  java.util.Map<java.lang.String,java.lang.Integer> columnHeaderMap
          Mapping from the header name to the column number (to aid lookup)
protected  java.util.Vector<java.lang.String> columnNames
          Column names
protected  java.util.Vector<Batch.Type> columnType
          The type of *all* the variables in a column
protected  java.util.Vector<java.lang.String> imageFiles
          list of file names of images in batch
protected  java.util.Vector<java.lang.Integer> imageFileStatus
          status (if known) of the imageFile
static java.lang.String imagesHeaderName
          the name of the header containing the image file names
static int invalid_status
          The index has not status because it in not a valid index
static int status_exists
          The file exists and may be valid
static int status_invalid
          The file exists and is invalid
static int status_unknown
          The status of the file is unavailable
protected  java.util.Vector<java.lang.String> templateFiles
          list of file names of templates for the faces in the imageFile list.
protected  java.util.Vector<java.lang.Integer> templateFileStatus
          status (if known) of the templateFiles
static java.lang.String templateHeaderName
          the name of the header containing the image file names
protected  java.util.Vector<java.util.Vector<java.lang.Object>> variables
          The variable data itself.
 
Constructor Summary
Batch()
          Construct an empty Batch of images
Batch(Batch other, java.util.Vector<java.lang.Boolean> filter)
          Copy a subset of the Batch defined by the filter
Batch(java.io.File f)
           
 
Method Summary
 int addColumn(java.lang.String columnName, Batch.Type columnType)
          Add a new data column to the batch file
 void addMatrix(BigMat matrix, int[] selectedColumns, int[] selectedRows)
           
 void addMatrix(BigMat matrix, java.util.Vector<java.lang.String> headers, int[] selectedRows, boolean createColumns)
           
 void addRecord(java.lang.String imageFile, int imageStatus, java.lang.String templateFile, int templateStatus)
          Add a record to the end of the Batch
 void addRecord(java.lang.String imageFile, java.lang.String templateFile)
          Add a record to the end of the Batch
 void addRecord(java.util.Vector<java.lang.Object> variables)
          Add a row of variables as a record to th variable lable (assumed ordered)
protected  void calculateColumnTypes()
          Traverse the data in the variables table to determine the type of the data
 java.lang.Object clone()
           
 BigMat constructMatrix(boolean[] selectedColumns, boolean[] selectedRows)
          Construct a BigMat matrix from numerical data in the Batch file
 BigMat constructMatrix(boolean addImage, boolean addTemplate, int[] selectedColumns, int[] selectedRows)
          Construct a BigMat matrix from numerical data in the Batch file
 BigMat constructMatrix(int[] selectedColumns, int[] selectedRows)
          Construct a BigMat matrix from numerical data in the Batch file
 BigMat constructMatrix(java.util.Vector<java.lang.String> headers)
          Construct a BigMat matrix from numerical data in the Batch file
 BigMat constructMatrix(java.util.Vector<java.lang.String> headers, boolean[] selectedRows)
          Construct a BigMat matrix from numerical data in the Batch file
 BigMat constructMatrix(java.util.Vector<java.lang.String> headers, int[] selectedRows)
          Construct a BigMat matrix from numerical data in the Batch file
protected  Batch.Type determineType(java.lang.String datum)
          Attempt to determine the type of the data in the string
protected  java.util.Map<java.lang.String,java.lang.Integer> extractHeader(java.lang.String line)
          Attempt to extract the column labels of a csv file returns null if any of the line entries is not a string (j.e) is a number
protected  java.lang.String extractInQuotes(java.lang.String text, int offset)
           
protected  int extractInteger(java.lang.String datum)
          Attempt to extract an integer value from the string
protected  double extractNumber(java.lang.String datum)
          Attempt to extract a floating point value from the string
protected  java.lang.String extractString(java.lang.String datum)
          Will remove quotation marks from around a string or else simply return the string
 java.lang.Object get(int row, int col)
          Access the object at a particular row or column.
 java.lang.Object get(int row, java.lang.String name)
          Access the object at a particular row or column.
 java.lang.String getBaseDirectory()
           
 java.lang.String getColumnHeader(int col)
          Returns the name (if any) of the column
 java.lang.String[] getColumnHeaders()
           
 java.util.Vector<java.lang.String> getColumnHeaders(Batch.Type type)
           
 int getColumnIndex(java.lang.String name)
          Returns the column index of the first column with a particular name
 java.lang.Object getColumnObject(int colNo)
          Returns a 'null' or 'zero' filled object of the type required by this column
 int[] getColumnOfIntegers(int colNo)
          Returns a vector of integers from a particular column.
 double[] getColumnOfNumbers(int colNo)
          Returns a vector of doubles from a particular column.
 Batch.Type getColumnType(int colNo)
          Return the type of data in a particular column
 java.io.File getImageFile(int index)
          Returns an appropriate File object for the image names If the name begins with [drive letter]:\ then the path is not added otherwise it is.
 java.io.File getImageFile(java.lang.String name)
          Returns an appropriate File object for the image names If the name begins with [drive letter]:\ then the path is not added otherwise it is.
 java.util.Iterator<java.lang.String> getImageFileIterator()
           
 java.lang.String getImageFileName(int index)
          Get the image file name at position index
 int getImageFileStatus(int index)
          The status of the image file
 ImageIterator getImageIterator()
           
 int getInteger(int row, int col)
          Get the data in a particular row and column as an integer value
 int getInteger(int row, java.lang.String name)
          Get the data in a particular row and column as an integer value
 int getNoColumns()
           
 double getNumber(int row, int col)
          Get the data in a particular row and column as a double value
 double getNumber(int row, java.lang.String name)
          Get the data in a particular row and column as a double value
 java.lang.String getString(int row, int col)
          Get the data as a string, this is guaranteed to succeed, if any data exists at the specified location
 java.lang.String getString(int row, java.lang.String name)
          Get the data as a string, this is guaranteed to succeed, if any data exists at the specified location
 java.io.File getTemplateFile(int index)
          Returns an appropriate File object for the image names If the name begins with [drive letter]:\ then the path is not added otherwise it is.
 java.util.Iterator<java.lang.String> getTemplateFileIterator()
           
 java.lang.String getTemplateFileName(int index)
          Get the template file name at position index
 int getTemplateFileStatus(int index)
          The status of the template file
 TemplateIterator getTemplateIterator()
           
 boolean hasColumn(java.lang.String name)
          Returns true if the column is in the Batch file
protected  boolean isQuoted(java.lang.String testString)
           
 void read(java.io.File f)
          Read in a Batch file
 void readCSV(java.io.File f)
          Read in data from a CSV file
 void readTXT(java.io.File f)
          Read in a txt file batch file (old psychomorph-format)
 void removeColumn(int column)
          remove a column from the batch file referenced by its index
 void removeRecord(int recordNumber)
          remove a record including image and template components;
 void set(int row, int col, double value)
          Put a particular value in the variable table
 void set(int row, int col, int value)
          Put a particular value in the variable table
 void set(int row, int col, java.lang.Object value)
          Put a particular value in the variable table
 void set(int row, int col, java.lang.String value)
          Put a particular value in the variable table
 void setBaseDirectory(java.lang.String bd)
          Set base directory
 void setColumn(int columnIndex, double[] data)
          Sets the values of the given column (index) with the values in the vector of doubles.
 void setImageFileName(int index, java.lang.String name)
          Change the image file name
 void setImageFileStatus(int index, int status)
          Set the status of the j^th image
 void setTemplateFileName(int index, java.lang.String name)
          Change the template file name
 void setTemplateFileStatus(int index, int status)
          Set the status of the j^th template
 int size()
           
 void syncRecordLengths()
          Make the lengths of the various vectors the same.
 void updateStatus()
           
 void write(java.io.File f)
          Write the batch to a file
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseDirectory

protected java.lang.String baseDirectory
Base directory of the files in the Batch


imageFiles

protected java.util.Vector<java.lang.String> imageFiles
list of file names of images in batch


templateFiles

protected java.util.Vector<java.lang.String> templateFiles
list of file names of templates for the faces in the imageFile list. The j^th template file matches the j^th image file.


imageFileStatus

protected java.util.Vector<java.lang.Integer> imageFileStatus
status (if known) of the imageFile


templateFileStatus

protected java.util.Vector<java.lang.Integer> templateFileStatus
status (if known) of the templateFiles


imagesHeaderName

public static final java.lang.String imagesHeaderName
the name of the header containing the image file names

See Also:
Constant Field Values

templateHeaderName

public static final java.lang.String templateHeaderName
the name of the header containing the image file names

See Also:
Constant Field Values

invalid_status

public static final int invalid_status
The index has not status because it in not a valid index

See Also:
Constant Field Values

status_unknown

public static final int status_unknown
The status of the file is unavailable

See Also:
Constant Field Values

status_exists

public static final int status_exists
The file exists and may be valid

See Also:
Constant Field Values

status_invalid

public static final int status_invalid
The file exists and is invalid

See Also:
Constant Field Values

colour_unknown

public static java.awt.Color colour_unknown

colour_exists

public static java.awt.Color colour_exists

colour_invalid

public static java.awt.Color colour_invalid

columnNames

protected java.util.Vector<java.lang.String> columnNames
Column names


columnHeaderMap

protected java.util.Map<java.lang.String,java.lang.Integer> columnHeaderMap
Mapping from the header name to the column number (to aid lookup)


variables

protected java.util.Vector<java.util.Vector<java.lang.Object>> variables
The variable data itself. A grid of Object.


columnType

protected java.util.Vector<Batch.Type> columnType
The type of *all* the variables in a column

Constructor Detail

Batch

public Batch()
Construct an empty Batch of images


Batch

public Batch(java.io.File f)
      throws java.io.IOException
Throws:
java.io.IOException

Batch

public Batch(Batch other,
             java.util.Vector<java.lang.Boolean> filter)
Copy a subset of the Batch defined by the filter

Parameters:
other - A Batch file to take a subset of
filter - Filter to apply to the other Batch file, on entries marked true are copied.
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

size

public int size()
Returns:
The number of records in the set

getImageFileName

public java.lang.String getImageFileName(int index)
Get the image file name at position index

Parameters:
index - record number
Returns:
image file name

getImageFile

public java.io.File getImageFile(int index)
Returns an appropriate File object for the image names If the name begins with [drive letter]:\ then the path is not added otherwise it is.

Parameters:
index - record number
Returns:
full file name

getImageFile

public java.io.File getImageFile(java.lang.String name)
Returns an appropriate File object for the image names If the name begins with [drive letter]:\ then the path is not added otherwise it is.

Parameters:
name - name of the file to process
Returns:
full file name

setImageFileName

public void setImageFileName(int index,
                             java.lang.String name)
Change the image file name

Parameters:
index - record
name - new name

getTemplateFileName

public java.lang.String getTemplateFileName(int index)
Get the template file name at position index

Parameters:
index - record number
Returns:
template file name

getTemplateFile

public java.io.File getTemplateFile(int index)
Returns an appropriate File object for the image names If the name begins with [drive letter]:\ then the path is not added otherwise it is.

Parameters:
index - record number
Returns:
full file names

setTemplateFileName

public void setTemplateFileName(int index,
                                java.lang.String name)
Change the template file name

Parameters:
index - record
name - new name

getImageFileStatus

public int getImageFileStatus(int index)
The status of the image file

Parameters:
index - record number
Returns:
the status of the image

setImageFileStatus

public void setImageFileStatus(int index,
                               int status)
Set the status of the j^th image

Parameters:
index - record number
status - record status

getTemplateFileStatus

public int getTemplateFileStatus(int index)
The status of the template file

Parameters:
index - record number
Returns:
the status of the template

setTemplateFileStatus

public void setTemplateFileStatus(int index,
                                  int status)
Set the status of the j^th template

Parameters:
index - record number
status - record status

setBaseDirectory

public void setBaseDirectory(java.lang.String bd)
Set base directory

Parameters:
bd -

getBaseDirectory

public java.lang.String getBaseDirectory()
Returns:
the base directory of this list of files

addRecord

public void addRecord(java.lang.String imageFile,
                      java.lang.String templateFile)
Add a record to the end of the Batch

Parameters:
imageFile - filename of the image to add
templateFile - filename of the template to add

addRecord

public void addRecord(java.util.Vector<java.lang.Object> variables)
Add a row of variables as a record to th variable lable (assumed ordered)

Parameters:
variables - an (ordered) list of variables to add to the table

addColumn

public int addColumn(java.lang.String columnName,
                     Batch.Type columnType)
Add a new data column to the batch file

Parameters:
columnName - The name to give the added column
columnType - the type of the data in the column
Returns:
the offset of the column for use in future get/set operations

removeColumn

public void removeColumn(int column)
remove a column from the batch file referenced by its index

Parameters:
column - index of column to remove
Throws:
Batch.BatchFileException

removeRecord

public void removeRecord(int recordNumber)
remove a record including image and template components;

Parameters:
recordNumber -

addRecord

public void addRecord(java.lang.String imageFile,
                      int imageStatus,
                      java.lang.String templateFile,
                      int templateStatus)
Add a record to the end of the Batch

Parameters:
imageFile - filename of the image to add
imageStatus - status of the file
templateFile - filename of the template to add
templateStatus - status of the template

getColumnHeaders

public java.lang.String[] getColumnHeaders()
Returns:
a string containing the name of the column headers in the batch

getColumnHeaders

public java.util.Vector<java.lang.String> getColumnHeaders(Batch.Type type)
Returns:
an unordered string containing the name of the column headers in the batch filtered by type

getColumnHeader

public java.lang.String getColumnHeader(int col)
Returns the name (if any) of the column

Parameters:
col - the column number
Returns:
the name of the column

getColumnIndex

public int getColumnIndex(java.lang.String name)
Returns the column index of the first column with a particular name

Parameters:
name - the name of header (as specified in the first row of the CSV file)
Returns:
the index of the column containing the values.

getColumnType

public Batch.Type getColumnType(int colNo)
Return the type of data in a particular column

Parameters:
colNo - the column return type information about
Returns:
type information

getColumnObject

public java.lang.Object getColumnObject(int colNo)
Returns a 'null' or 'zero' filled object of the type required by this column

Parameters:
colNo - The column to query
Returns:
an object of the type relevent to the column

getNoColumns

public int getNoColumns()
Returns:
the number of columns in the variable list

getColumnOfNumbers

public double[] getColumnOfNumbers(int colNo)
Returns a vector of doubles from a particular column.

Parameters:
colNo - the column to vectorise
Returns:
a vector of double values

getColumnOfIntegers

public int[] getColumnOfIntegers(int colNo)
Returns a vector of integers from a particular column.

Parameters:
colNo - the column to vectorise
Returns:
a vector of interger values

setColumn

public void setColumn(int columnIndex,
                      double[] data)
Sets the values of the given column (index) with the values in the vector of doubles.

Parameters:
columnIndex - index of the column to set
data - vector of numbers to fill the column with

hasColumn

public boolean hasColumn(java.lang.String name)
Returns true if the column is in the Batch file

Parameters:
name - name of the column to search for
Returns:
true iff the string name is the name of a variable column

syncRecordLengths

public void syncRecordLengths()
Make the lengths of the various vectors the same. (only to be used if adding to the rows, not removing)


get

public java.lang.Object get(int row,
                            int col)
Access the object at a particular row or column. Not the recommended method, it is preferred that type information is queried and the appropriate getInteger, getNumber, getString is used instead.

Parameters:
row - the record number of the datum to access
col - the column containing the datum
Returns:
the datum itself

getInteger

public int getInteger(int row,
                      int col)
Get the data in a particular row and column as an integer value

Parameters:
row - the record number to access
col - the colum containing the data
Returns:
the data as an integer value

getNumber

public double getNumber(int row,
                        int col)
Get the data in a particular row and column as a double value

Parameters:
row - the record number to access
col - the colum containing the data
Returns:
the data as an double value

getString

public java.lang.String getString(int row,
                                  int col)
Get the data as a string, this is guaranteed to succeed, if any data exists at the specified location

Parameters:
row - the record number
col - the column containing the data
Returns:
a String representing the output.

get

public java.lang.Object get(int row,
                            java.lang.String name)
Access the object at a particular row or column. Not the recommended method, it is preferred that type information is queried and the appropriate getInteger, getNumber, getString is used instead.

Parameters:
row - the record number of the datum to access
col - the column containing the datum
Returns:
the datum itself

getInteger

public int getInteger(int row,
                      java.lang.String name)
Get the data in a particular row and column as an integer value

Parameters:
row - the record number to access
col - the colum containing the data
Returns:
the data as an integer value

getNumber

public double getNumber(int row,
                        java.lang.String name)
Get the data in a particular row and column as a double value

Parameters:
row - the record number to access
col - the colum containing the data
Returns:
the data as an double value

getString

public java.lang.String getString(int row,
                                  java.lang.String name)
Get the data as a string, this is guaranteed to succeed, if any data exists at the specified location

Parameters:
row - the record number
col - the column containing the data
Returns:
a String representing the output.

set

public void set(int row,
                int col,
                java.lang.Object value)
Put a particular value in the variable table

Parameters:
row - the record number to alter
col - the column containing the data
value - the data to set

set

public void set(int row,
                int col,
                int value)
Put a particular value in the variable table

Parameters:
row - the record number to alter
col - the column containing the data
value - the data to set

set

public void set(int row,
                int col,
                double value)
Put a particular value in the variable table

Parameters:
row - the record number to alter
col - the column containing the data
value - the data to set

set

public void set(int row,
                int col,
                java.lang.String value)
Put a particular value in the variable table

Parameters:
row - the record number to alter
col - the column containing the data
value - the data to set

getImageFileIterator

public java.util.Iterator<java.lang.String> getImageFileIterator()
Returns:
an iterator over the image file names

getImageIterator

public ImageIterator getImageIterator()

getTemplateFileIterator

public java.util.Iterator<java.lang.String> getTemplateFileIterator()
Returns:
an iterator over the template files

getTemplateIterator

public TemplateIterator getTemplateIterator()

read

public void read(java.io.File f)
          throws java.io.IOException
Read in a Batch file

Throws:
java.io.IOException

readCSV

public void readCSV(java.io.File f)
             throws java.io.IOException
Read in data from a CSV file

Parameters:
f - file to read
Throws:
java.io.IOException

extractHeader

protected java.util.Map<java.lang.String,java.lang.Integer> extractHeader(java.lang.String line)
Attempt to extract the column labels of a csv file returns null if any of the line entries is not a string (j.e) is a number

Parameters:
line - Line to read in
Returns:
a mapping from (file) column number to (internal) column header

determineType

protected Batch.Type determineType(java.lang.String datum)
Attempt to determine the type of the data in the string

Parameters:
datum - The data in string form
Returns:
The type of the data in the string.

extractString

protected java.lang.String extractString(java.lang.String datum)
Will remove quotation marks from around a string or else simply return the string

Parameters:
datum - A string to extract the string from
Returns:
the non-quoted string

extractInteger

protected int extractInteger(java.lang.String datum)
Attempt to extract an integer value from the string

Parameters:
datum - string containing the number
Returns:
the integer extracted

extractNumber

protected double extractNumber(java.lang.String datum)
Attempt to extract a floating point value from the string


calculateColumnTypes

protected void calculateColumnTypes()
Traverse the data in the variables table to determine the type of the data


isQuoted

protected boolean isQuoted(java.lang.String testString)
Returns:
true if the string in quotation mark delimited

extractInQuotes

protected java.lang.String extractInQuotes(java.lang.String text,
                                           int offset)

readTXT

public void readTXT(java.io.File f)
             throws java.io.IOException
Read in a txt file batch file (old psychomorph-format)

Throws:
java.io.IOException

write

public void write(java.io.File f)
           throws java.io.IOException
Write the batch to a file

Parameters:
f - file to write to
Throws:
java.io.IOException

updateStatus

public void updateStatus()

constructMatrix

public BigMat constructMatrix(java.util.Vector<java.lang.String> headers)
Construct a BigMat matrix from numerical data in the Batch file

Parameters:
headers - a selected of (named) headers to take columns from. (ordered)
Returns:
BigMat matrix containing the ordered numerical data.

constructMatrix

public BigMat constructMatrix(java.util.Vector<java.lang.String> headers,
                              boolean[] selectedRows)
Construct a BigMat matrix from numerical data in the Batch file

Parameters:
headers - a selected of (named) headers to take columns from. (ordered)
selectedRows - (optional) a filter over the records (rows) to choose a subset from which to build the BigMat
Returns:
BigMat matrix containing the ordered numerical data.

constructMatrix

public BigMat constructMatrix(java.util.Vector<java.lang.String> headers,
                              int[] selectedRows)
Construct a BigMat matrix from numerical data in the Batch file

Parameters:
headers - a selected of (named) headers to take columns from. (ordered)
selectedRows - (optional) an index over the records (rows) to choose a subset from which to build the BigMat
Returns:
BigMat matrix containing the ordered numerical data.

constructMatrix

public BigMat constructMatrix(boolean[] selectedColumns,
                              boolean[] selectedRows)
Construct a BigMat matrix from numerical data in the Batch file

Parameters:
headers - a filter over the columns
selectedRows - (optional) a filter over the records (rows) to choose a subset from which to build the BigMat
Returns:
BigMat matrix containing the ordered numerical data.

constructMatrix

public BigMat constructMatrix(int[] selectedColumns,
                              int[] selectedRows)
Construct a BigMat matrix from numerical data in the Batch file

Parameters:
headers - (optional) an index over the columns
selectedRows - (optional) an index over the records (rows) to choose a subset from which to build the BigMat
Returns:
BigMat matrix containing the ordered numerical data.

constructMatrix

public BigMat constructMatrix(boolean addImage,
                              boolean addTemplate,
                              int[] selectedColumns,
                              int[] selectedRows)
Construct a BigMat matrix from numerical data in the Batch file

Parameters:
headers - (optional) an index over the columns
selectedRows - (optional) an index over the records (rows) to choose a subset from which to build the BigMat
Returns:
BigMat matrix containing the ordered numerical data.

addMatrix

public void addMatrix(BigMat matrix,
                      java.util.Vector<java.lang.String> headers,
                      int[] selectedRows,
                      boolean createColumns)

addMatrix

public void addMatrix(BigMat matrix,
                      int[] selectedColumns,
                      int[] selectedRows)