de.dfki.mycbr.io
Class CSVImporter

java.lang.Object
  extended by de.dfki.mycbr.io.CSVImporter

public class CSVImporter
extends java.lang.Object

Imports instances from CSV files. Please call the following methods in the given order: csvImporter.readData(); csvImporter.checkData(); csvImporter.addMissingValues(); csvImporter.addMissingDescriptions(); csvImporter.doImport();

Author:
myCBR Team

Nested Class Summary
static class CSVImporter.CSVImportError
           
 
Field Summary
static java.lang.String CB_CSV_IMPORT
           
 
Constructor Summary
CSVImporter(java.lang.String f, Concept concept)
           
 
Method Summary
 void addMissingDescriptions()
           
 void addMissingValues()
          after calling this, all values in the table fit the description
 void checkData()
          Checks for consistent data.
 void doImport()
           
 java.util.HashSet<java.lang.String> getAttributeDescsName()
           
 java.util.Vector<java.lang.Integer> getColumnsToBeSkipped()
           
 int getCurrentNumberOfCases()
           
 java.util.ArrayList<java.lang.String[]> getData()
           
 CSVImporter.CSVImportError getError()
           
 java.lang.String[] getHeader()
          Returns the header of the CSV file as a string array.
 java.util.HashMap<AttributeDesc,java.lang.Integer> getIndexToDescMap()
           
 java.util.HashSet<Pair<java.lang.String,AttributeDesc>> getInvalidValues()
           
 java.util.Vector<Pair<java.lang.String,java.lang.Integer>> getMissingDescs()
           
 java.lang.String getSeparator()
           
 java.lang.String getSeparatorMultiple()
           
 java.lang.String getSpecialAttForMissingValues()
           
 int getSymbolThreshold()
           
 int getTotalNumberOfCases()
           
 boolean isChangeDescOnMissingValues()
           
 boolean isCreateMissingDescs()
           
 boolean isImporting()
           
 void readData()
           
 void removeMeta(int col)
          Removes the meta tag of the given column.
 void reset()
           
 void setCaseBase(ICaseBase cb)
           
 void setChangeDescOnMissingValues(boolean changeDescOnMissingValues)
           
 void setCreateMissingDesc(boolean createMissingDescs)
           
 void setMeta(java.lang.Integer col, ICaseBase.Meta meta)
          Adds a mapping entry for meta tag of a case to the given column in the underlying data set.
 void setSeparator(java.lang.String separator)
           
 void setSeparatorMultiple(java.lang.String separatorMultiple)
           
 void setSpecialAttForMissingValues(java.lang.String specialAttForMissingValues)
           
 void setSymbolThreshold(int symbolThreshold)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CB_CSV_IMPORT

public static final java.lang.String CB_CSV_IMPORT
See Also:
Constant Field Values
Constructor Detail

CSVImporter

public CSVImporter(java.lang.String f,
                   Concept concept)
Method Detail

reset

public void reset()

readData

public void readData()

setMeta

public void setMeta(java.lang.Integer col,
                    ICaseBase.Meta meta)
Adds a mapping entry for meta tag of a case to the given column in the underlying data set. When importing the current data, the columns that are mapped to, will be used as the associated meta data in the case object Will override data, if more than one column is mapped to the same meta tag. Is assumed to be called after readData() and before checkData()

Parameters:
col - the column which holds the meta information
meta - the meta type

removeMeta

public void removeMeta(int col)
Removes the meta tag of the given column. Is assumed to be called after readData() and before checkData()

Parameters:
col - the column that should not refer to meta information afterwards

addMissingValues

public void addMissingValues()
after calling this, all values in the table fit the description


checkData

public void checkData()
Checks for consistent data. Assumes that all meta data tags have been added first


addMissingDescriptions

public void addMissingDescriptions()

setCaseBase

public void setCaseBase(ICaseBase cb)

doImport

public void doImport()

getError

public CSVImporter.CSVImportError getError()
Returns:
the error

setSeparator

public void setSeparator(java.lang.String separator)
Parameters:
separator - the separator to set

getSeparator

public java.lang.String getSeparator()
Returns:
the separator

getSeparatorMultiple

public java.lang.String getSeparatorMultiple()
Returns:
the separatorMultiple

setSeparatorMultiple

public void setSeparatorMultiple(java.lang.String separatorMultiple)
Parameters:
separatorMultiple - the separatorMultiple to set

setCreateMissingDesc

public void setCreateMissingDesc(boolean createMissingDescs)
Parameters:
createMissingDescs - the createMissingSlots to set

isCreateMissingDescs

public boolean isCreateMissingDescs()
Returns:
the createMissingSlots

setChangeDescOnMissingValues

public void setChangeDescOnMissingValues(boolean changeDescOnMissingValues)
Parameters:
changeDescOnMissingValues - the changeDescOnMissingValues to set

isChangeDescOnMissingValues

public boolean isChangeDescOnMissingValues()
Returns:
the changeDescOnMissingValues

setSpecialAttForMissingValues

public void setSpecialAttForMissingValues(java.lang.String specialAttForMissingValues)
Parameters:
specialAttForMissingValues - the specialAttForMissingValues to set

getSpecialAttForMissingValues

public java.lang.String getSpecialAttForMissingValues()
Returns:
the specialAttForMissingValues

getColumnsToBeSkipped

public java.util.Vector<java.lang.Integer> getColumnsToBeSkipped()

getData

public java.util.ArrayList<java.lang.String[]> getData()
Returns:
the entries

getAttributeDescsName

public java.util.HashSet<java.lang.String> getAttributeDescsName()
Returns:
the attributeDescsName

getSymbolThreshold

public int getSymbolThreshold()
Returns:
the symbolThreshold

setSymbolThreshold

public void setSymbolThreshold(int symbolThreshold)
Parameters:
symbolThreshold - the symbolThreshold to set

getMissingDescs

public java.util.Vector<Pair<java.lang.String,java.lang.Integer>> getMissingDescs()

getInvalidValues

public java.util.HashSet<Pair<java.lang.String,AttributeDesc>> getInvalidValues()

getIndexToDescMap

public java.util.HashMap<AttributeDesc,java.lang.Integer> getIndexToDescMap()

getTotalNumberOfCases

public int getTotalNumberOfCases()

isImporting

public boolean isImporting()
Returns:
true, when still importing. false otherwise

getCurrentNumberOfCases

public int getCurrentNumberOfCases()
Returns:
the number of cases currently imported

getHeader

public java.lang.String[] getHeader()
Returns the header of the CSV file as a string array. Contains the names of the attribute descriptions

Returns:
array of names of attribute descriptions in order of their appearance