double count = 0;
double total = splitDim.size();
displayPercentage = 0;
for (String newDim : splitDim.dimValues)
{
DimTable subTable = reader.dimTable.getSubTable(new DimensionMap(splitDimName + "=" + newDim));
JEXTableWriter writer = new JEXTableWriter(tableName, fileExtension);
writer.writeHeader(subTable, reader.isNumeric());
writers.put(newDim, writer);
count++;
currentPercentage = (int) (100.0 * count / total);
if(currentPercentage != displayPercentage)
{
displayPercentage = currentPercentage;
JEXStatics.statusBar.setStatusText("Preparing ARFF Files: " + displayPercentage + "%");
}
}
// Write each datapoint to a file
JEXStatics.statusBar.setStatusText("Splitting ARFFs: 0%");
Instance instance;
Pair<DimensionMap,E> pair;
count = 0;
total = reader.dimTable.mapCount();
displayPercentage = 0;
while ((instance = reader.loader.m_ArffReader.readInstance(reader.structure)) != null)
{
if(canceler.isCanceled())
{
// Exit gracefully
for (String splitDimValue : splitDim.dimValues)
{
JEXTableWriter writer = writers.get(splitDimValue);
writer.close();
}
return null;
}
pair = reader.getPair(instance);
DimensionMap map = pair.p1;
JEXTableWriter theWriter = writers.get(map.get(splitDimName));
theWriter.writeData(map, pair.p2);
count++;
currentPercentage = (int) (100.0 * count / total);
if(currentPercentage != displayPercentage)
{
displayPercentage = currentPercentage;
JEXStatics.statusBar.setStatusText("Splitting ARFF: " + displayPercentage + "%");
}
}
// Close the writers and return the filePaths
TreeMap<DimensionMap,String> filePaths = new TreeMap<DimensionMap,String>();
JEXStatics.statusBar.setStatusText("Defragging ARFFs: 0%");
count = 0;
total = splitDim.size();
displayPercentage = 0;
for (String splitDimValue : splitDim.dimValues)
{
JEXTableWriter writer = writers.get(splitDimValue);
writer.close();
String path = JEXTableWriter.defrag(writer.getPath());
filePaths.put(new DimensionMap(splitDimName + "=" + splitDimValue), path);
count++;
currentPercentage = (int) (100.0 * count / total);
if(currentPercentage != displayPercentage)
{
displayPercentage = currentPercentage;
JEXStatics.statusBar.setStatusText("Defragging ARFFs: " + displayPercentage + "%");
}
}
DimTable outputDimTable = new DimTable();
outputDimTable.add(splitDim.copy());
return new Table<String>(outputDimTable, filePaths);
}
catch (Exception e)
{
e.printStackTrace();