edu.umd.cs.findbugs.ml
Class ConvertToARFF

java.lang.Object
  extended by edu.umd.cs.findbugs.ml.ConvertToARFF

public class ConvertToARFF
extends java.lang.Object

Convert a BugCollection into ARFF format. See Witten and Frank, Data Mining, ISBN 1-55860-552-5.

Author:
David Hovemeyer
See Also:
BugCollection, BugInstance

Nested Class Summary
static class ConvertToARFF.AppNameAttribute
           
static interface ConvertToARFF.Attribute
           
static interface ConvertToARFF.AttributeCallback
           
private static class ConvertToARFF.C2ACommandLine
           
static class ConvertToARFF.ClassificationAttribute
           
private static class ConvertToARFF.DataFile
           
static class ConvertToARFF.IdAttribute
          An attribute that just gives each instance a unique id.
private static class ConvertToARFF.MissingNodeException
           
static class ConvertToARFF.NominalAttribute
           
static class ConvertToARFF.NumericAttribute
           
static class ConvertToARFF.PriorityAttribute
           
private static class ConvertToARFF.XPathAttribute
           
 
Field Summary
private  java.util.List<ConvertToARFF.Attribute> attributeList
           
private static int BUG
           
private  boolean dropUnclassifiedWarnings
           
private static int HARMLESS
           
private static int HARMLESS_BUG
           
private static int NOT_BUG
           
private static int UNCLASSIFIED
           
 
Constructor Summary
ConvertToARFF()
           
 
Method Summary
 void addAppNameAttribute()
           
 void addAttribute(ConvertToARFF.Attribute attribute)
           
 void addClassificationAttribute()
           
 void addDefaultAttributes()
           
 void addIdAttribute()
           
 void addNominalAttribute(java.lang.String name, java.lang.String xpath)
           
 void addNumericAttribute(java.lang.String name, java.lang.String xpath)
           
 void addPriorityAttribute()
           
static java.lang.String collectionToRange(java.util.Collection<java.lang.String> collection)
           
 void convert(java.lang.String relationName, org.dom4j.Document document, java.lang.String appName, java.io.Writer out)
          Convert a single Document to ARFF format.
 void dropUnclassifiedWarnings()
           
 void generateHeader(java.lang.String relationName, java.io.Writer out)
          Generate ARFF header.
 void generateInstances(org.dom4j.Document document, java.lang.String appName, java.io.Writer out)
          Generate instances from given Document.
private static int getBugClassification(java.lang.String annotationText)
           
private  java.util.List getBugInstanceList(org.dom4j.Document document)
           
static void main(java.lang.String[] argv)
           
 void scan(org.dom4j.Document document, java.lang.String appName)
          Scan a Document to find out the ranges of attributes.
 void scanAttributeList(ConvertToARFF.AttributeCallback callback)
          Apply a callback to all Attributes.
static java.lang.String toAppName(java.lang.String fileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNCLASSIFIED

private static final int UNCLASSIFIED
See Also:
Constant Field Values

BUG

private static final int BUG
See Also:
Constant Field Values

NOT_BUG

private static final int NOT_BUG
See Also:
Constant Field Values

HARMLESS

private static final int HARMLESS
See Also:
Constant Field Values

HARMLESS_BUG

private static final int HARMLESS_BUG
See Also:
Constant Field Values

attributeList

private java.util.List<ConvertToARFF.Attribute> attributeList

dropUnclassifiedWarnings

private boolean dropUnclassifiedWarnings
Constructor Detail

ConvertToARFF

public ConvertToARFF()
Method Detail

collectionToRange

public static java.lang.String collectionToRange(java.util.Collection<java.lang.String> collection)

dropUnclassifiedWarnings

public void dropUnclassifiedWarnings()

addAttribute

public void addAttribute(ConvertToARFF.Attribute attribute)

addNominalAttribute

public void addNominalAttribute(java.lang.String name,
                                java.lang.String xpath)

addClassificationAttribute

public void addClassificationAttribute()

addNumericAttribute

public void addNumericAttribute(java.lang.String name,
                                java.lang.String xpath)

addPriorityAttribute

public void addPriorityAttribute()

addIdAttribute

public void addIdAttribute()

addAppNameAttribute

public void addAppNameAttribute()

convert

public void convert(java.lang.String relationName,
                    org.dom4j.Document document,
                    java.lang.String appName,
                    java.io.Writer out)
             throws java.io.IOException,
                    ConvertToARFF.MissingNodeException
Convert a single Document to ARFF format.

Parameters:
relationName - the relation name
document - the Document
appName - the application name
out - Writer to write the ARFF output to
Throws:
java.io.IOException
ConvertToARFF.MissingNodeException

scan

public void scan(org.dom4j.Document document,
                 java.lang.String appName)
          throws ConvertToARFF.MissingNodeException,
                 java.io.IOException
Scan a Document to find out the ranges of attributes. All Documents must be scanned before generating the ARFF header and instances.

Parameters:
document - the Document
appName - the application name
Throws:
ConvertToARFF.MissingNodeException
java.io.IOException

generateHeader

public void generateHeader(java.lang.String relationName,
                           java.io.Writer out)
                    throws ConvertToARFF.MissingNodeException,
                           java.io.IOException
Generate ARFF header. Documents must have already been scanned.

Parameters:
relationName - the relation name
out - Writer to write the ARFF output to
Throws:
ConvertToARFF.MissingNodeException
java.io.IOException

generateInstances

public void generateInstances(org.dom4j.Document document,
                              java.lang.String appName,
                              java.io.Writer out)
                       throws ConvertToARFF.MissingNodeException,
                              java.io.IOException
Generate instances from given Document. Document should already have been scanned, and the ARFF header generated.

Parameters:
document - the Document
appName - the application name
out - Writer to write the ARFF output to
Throws:
ConvertToARFF.MissingNodeException
java.io.IOException

scanAttributeList

public void scanAttributeList(ConvertToARFF.AttributeCallback callback)
                       throws ConvertToARFF.MissingNodeException,
                              java.io.IOException
Apply a callback to all Attributes.

Parameters:
callback - the callback
Throws:
ConvertToARFF.MissingNodeException
java.io.IOException

addDefaultAttributes

public void addDefaultAttributes()

getBugClassification

private static int getBugClassification(java.lang.String annotationText)

getBugInstanceList

private java.util.List getBugInstanceList(org.dom4j.Document document)

toAppName

public static java.lang.String toAppName(java.lang.String fileName)

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Throws:
java.lang.Exception