net.sf.myra.datamining.io
Class ArffHelper

java.lang.Object
  extended by net.sf.myra.datamining.io.Helper
      extended by net.sf.myra.datamining.io.ArffHelper
Direct Known Subclasses:
ExtendedArffHelper

public class ArffHelper
extends Helper

Helper class to manipulate files in ARFF (Weka) format.

Version:
$Revision$ $Date:: $
Author:
Fernando Esteban Barril Otero

Nested Class Summary
protected static class ArffHelper.UnsupportedAttribute
          This class represents an unsupported attribute (e.g.
 
Constructor Summary
ArffHelper()
          No instances allowed (private constructor).
 
Method Summary
protected  java.lang.String getExtension()
          Returns the default file extension.
protected  boolean isBlank(java.lang.String line)
          Checks if the line is blank.
protected  boolean isComment(java.lang.String line)
          Checks if the line begin with the comment character ('%').
static void main(java.lang.String[] args)
          Utility method to convert the specified dataset file to ARFF format.
 Dataset read(java.io.File file)
          Returns a Dataset instance that represents the data of the specified ARFF file.
 Dataset read(java.io.Reader reader)
          Returns a Dataset instance that represents the data of the specified ARFF file.
protected  java.lang.String trim(java.lang.String s)
          Returns a copy of the specified string, with single and double quotes, as well as leading and trailing spaces omitted.
 void write(java.io.File directory, Dataset dataset)
          Writes an ARFF file representing the specified dataset.
 void write(java.io.Writer writer, Dataset dataset)
          Writes an ARFF file representing the specified dataset.
protected  void writeAttribute(Attribute attribute, java.io.PrintWriter writer)
          Writes the ARFF attribute information.
protected  void writeData(Dataset dataset, java.io.PrintWriter writer)
          Writes the ARFF data section.
protected  void writeHeader(Metadata metadata, java.io.PrintWriter writer)
          Writes the ARFF header section.
protected  void writeTarget(Metadata metadata, java.io.PrintWriter writer)
           
 
Methods inherited from class net.sf.myra.datamining.io.Helper
getHelper, getHelper, isCompressed, open, open, read, setCompressed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArffHelper

public ArffHelper()
No instances allowed (private constructor).

Method Detail

read

public Dataset read(java.io.File file)
             throws java.io.IOException
Returns a Dataset instance that represents the data of the specified ARFF file.

Specified by:
read in class Helper
Parameters:
file - the file to read the data from.
Returns:
a Dataset instance.
Throws:
java.io.IOException - if any file operation fails.

read

public Dataset read(java.io.Reader reader)
             throws java.io.IOException
Returns a Dataset instance that represents the data of the specified ARFF file.

Parameters:
reader - the input reader.
Returns:
a Dataset instance.
Throws:
java.io.IOException - if any file operation fails.

write

public void write(java.io.File directory,
                  Dataset dataset)
           throws java.io.IOException
Writes an ARFF file representing the specified dataset.

Specified by:
write in class Helper
Parameters:
directory - the output directory.
dataset - the dataset to be written.
Throws:
java.io.IOException

write

public void write(java.io.Writer writer,
                  Dataset dataset)
           throws java.io.IOException
Writes an ARFF file representing the specified dataset.

Specified by:
write in class Helper
Parameters:
writer - the output writer.
dataset - the dataset to be written.
Throws:
java.io.IOException

writeHeader

protected void writeHeader(Metadata metadata,
                           java.io.PrintWriter writer)
Writes the ARFF header section.

Parameters:
metadata - the metadata information.
writer - the writer instance.

writeTarget

protected void writeTarget(Metadata metadata,
                           java.io.PrintWriter writer)

writeData

protected void writeData(Dataset dataset,
                         java.io.PrintWriter writer)
Writes the ARFF data section.

Parameters:
dataset - the dataset instance.
writer - the writer instance.

writeAttribute

protected void writeAttribute(Attribute attribute,
                              java.io.PrintWriter writer)
Writes the ARFF attribute information.

Parameters:
attribute - the attribute to write.
writer - the writer instance.

isComment

protected boolean isComment(java.lang.String line)
Checks if the line begin with the comment character ('%').

Parameters:
line - the line to check.
Returns:
true if the line begins with the comment character ('%'); false otherwise.

isBlank

protected boolean isBlank(java.lang.String line)
Checks if the line is blank.

Parameters:
line - the line to check.
Returns:
true if the line is blank; false otherwise.

trim

protected java.lang.String trim(java.lang.String s)
Returns a copy of the specified string, with single and double quotes, as well as leading and trailing spaces omitted.

Parameters:
s - the string to remove single and double quotes, as well as leading and trailing spaces.
Returns:
A copy of the specified string, with single and double quotes, as well as leading and trailing spaces removed.

getExtension

protected java.lang.String getExtension()
Returns the default file extension.

Returns:
the default file extension.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Utility method to convert the specified dataset file to ARFF format.

Parameters:
args - command-line arguments.
Throws:
java.lang.Exception


Copyright © 2013. All Rights Reserved.