edu.ida.dataformat
Class ArffFile

java.lang.Object
  extended by edu.ida.dataformat.ArffFile

public class ArffFile
extends java.lang.Object

A class for reading and writing Arff-Files.

You can either load a file, parse a string or a BufferedReader. Afterwards, you can extract the information with the methods getComment(), getNumberOfAttributes(), getAttributeName(), getAttributeType(), getAttributeData().

Alternative, you can construct an empty ArffFile object, and then use setComment(), defineAttribute(), add() to fill in the data and then save to a file with save(), or to a string with write().

The first comment in an ArffFile is extracted and made available through the *Comment() accessors. Usually, this comment contains some interesting information about the data set.

Currently, the class only supports numerical, string and nominal attributes. It also does not support sparse storage (yet).


Constructor Summary
ArffFile()
          Construct an empty ArffFile.
 
Method Summary
 void add(java.lang.Object[] datum)
          Add a datum.
 void defineAttribute(java.lang.String name, java.lang.String type, java.lang.String[] data)
          Define a new attribute.
 java.lang.String dump()
          Generate a string which describes the data set.
 java.lang.String[] getAttributeData(java.lang.String name)
          Get additional information on the attribute.
 java.lang.String getAttributeName(int idx)
          Get the name of an attribute.
 java.lang.String getAttributeType(java.lang.String name)
          Get the type of an attribute.
 java.lang.String getComment()
          Get the initial comment of the relation.
 int getDataSize()
           
 java.lang.Object[] getDatum(int i)
           
 int getNumberOfAttributes()
          Get the number of attributes.
 java.lang.String getRelation()
          Get the name of the relation.
static ArffFile load(java.lang.String filename)
          Load an ArffFile.
static void main(java.lang.String[] args)
          Main function for debugging.
 void parse(java.io.BufferedReader r)
          Parse an ArffFile from a BufferedReader.
static ArffFile parse(java.lang.String l)
          Parse an ArffFile from a string.
 void save(java.lang.String filename)
          Save the data into a file.
 void setComment(java.lang.String comment)
          Set the initial comment of the relation.
 void setRelation(java.lang.String relation)
          Set the name of the relation.
 java.lang.String write()
          Write the ArffFile to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArffFile

public ArffFile()
Construct an empty ArffFile.

Method Detail

load

public static ArffFile load(java.lang.String filename)
                     throws java.io.FileNotFoundException,
                            java.io.IOException,
                            ArffFileParseError
Load an ArffFile.

Throws:
java.io.FileNotFoundException
java.io.IOException
ArffFileParseError

parse

public static ArffFile parse(java.lang.String l)
                      throws java.io.IOException,
                             ArffFileParseError
Parse an ArffFile from a string.

Throws:
java.io.IOException
ArffFileParseError

parse

public void parse(java.io.BufferedReader r)
           throws java.io.IOException
Parse an ArffFile from a BufferedReader.

Throws:
java.io.IOException

defineAttribute

public void defineAttribute(java.lang.String name,
                            java.lang.String type,
                            java.lang.String[] data)
Define a new attribute. Type must be one of "numeric", "string", and "nominal". For nominal attributes, the allowed values must also be given. This variant of defineAttribute allows to set this data.


dump

public java.lang.String dump()
Generate a string which describes the data set.


write

public java.lang.String write()
Write the ArffFile to a string.


save

public void save(java.lang.String filename)
          throws java.io.IOException
Save the data into a file.

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
Main function for debugging. Loads files from the argument list and dumps their contents to the System.out.


getRelation

public java.lang.String getRelation()
Get the name of the relation.


setRelation

public void setRelation(java.lang.String relation)
Set the name of the relation.


getComment

public java.lang.String getComment()
Get the initial comment of the relation.


setComment

public void setComment(java.lang.String comment)
Set the initial comment of the relation.


getNumberOfAttributes

public int getNumberOfAttributes()
Get the number of attributes.


getAttributeName

public java.lang.String getAttributeName(int idx)
Get the name of an attribute.


getAttributeType

public java.lang.String getAttributeType(java.lang.String name)
Get the type of an attribute. Currently, the attribute types are "numeric", "string", and "nominal". For nominal attributes, use getAttributeData() to retrieve the possible values for the attribute.


getAttributeData

public java.lang.String[] getAttributeData(java.lang.String name)
Get additional information on the attribute. This data is used for nominal attributes to define the possible values.


add

public void add(java.lang.Object[] datum)
Add a datum. No checking of the data types is performed!


getDataSize

public int getDataSize()

getDatum

public java.lang.Object[] getDatum(int i)