Uses the identity:
+-----------------------------------------------------------+
| newNumber = 1 + (maxRange*(number-startRange)/range) |
+-----------------------------------------------------------+
@param attNum the current attribute (column) number.
@param number the given value in the current row/column intersection in the
input data structure.
@param startRange the numeric value marking the start of the range for the
input column.
@param range the range value (for the input column)
@param rowIndex the current row index in the input data structure.
@param colIndex the current column index in the input data structure.
@return the revised attribute number.*/
private int determineBinaryOutputDouble(int attNum, double number,
double startRange, double range,
int rowIndex, int colIndex ) {
if (range > 0.0) {
// Test for missing value
if (numberTEST_TERM) {
if (noItemsInItemSetStr) {
itemSetStr = Integer.toString(itemSet[index]);
noItemsInItemSetStr = false;
}
else itemSetStr = itemSetStr + " " + itemSet[index];
}
}
// Output
textArea.append(itemSetStr);
}
/* LIST OUTPUT DATA */
/** Outputs stored normalised output data set. */
private void listOutputData() {
textArea.append("LIST OUTPUT DATA\n--------\n");
for(int index=0;index Done by processing schema array. */
private void listOutputSchema2() {
int attNum=1;
for(int colIndex=0;colIndex maxRange) {
double oldMarker = 0.0;
for (int index=1;index<=maxRange;index++) {
double marker = startRange +
(((double) (index*range))/maxRange);
if (index==1) {
outputLabel(attNum,label+"<"+marker);
oldMarker = marker;
}
else if (index==maxRange) outputLabel(attNum,label+">="+oldMarker);
else {
outputLabel(attNum,oldMarker + "<=" +label+"<"+marker);
oldMarker = marker;
}
attNum++;
}
// Return
return(attNum);
}
// Output where number is an integer and range for column is less than
// maximum.
else {
for (int index=startRange;index<=endRange;index++) {
outputLabel(attNum,label+"="+index);
attNum++;
}
// Return
return(attNum);
}
}
/* OUTPUT DOUBLES LABEL */
/** Outputs the attribute numbers and labels for an double column.
@param attNum The current attribute number.
@param label The label to be output.
@param startRange The start range for the column.
@param range the range for the integer attribute (hoe many values).
@return the new current attribute number. */
private int outputDoubleLabel(int attNum, String label,
double startRange, double range) {
if (range > 0.00) {
for (int index=1;index<=maxRange;index++) {
double marker = startRange +
(((double) index*range)/(double) maxRange);
outputLabel(attNum,label+"<"+marker);
attNum++;
}
}
else {
outputLabel(attNum,label);
attNum++;
}
// Return
return(attNum);
}
/* OUTPUT NOMINAL LABEL */
/** Produces label for nominal field.
@param attNum The current attribute number.
@param label The label to be output.
@param colIndex the index in the nominal data structure.
@return the new current attribute number. */
private int outputNominalLabel(int attNum, String label, int colIndex) {
for (int index=0;indexTEST_TERM) fileOutput.print(number + " ");
}
// Write last integer
int number = outputDataArray[index1][index2];
if (number>TEST_TERM) fileOutput.println(number);
else fileOutput.println();
}
textArea.append("File output complete\n\n");
}
else textArea.append("No data\n\n");
// End by closing file
fileOutput.close();
}
/* OPEN OUTPUT FILE */
/** Opens the output file ready to write normalised data to.
@return true if file successfully opened, and false otherwise. */
private boolean openOutputFile() {
// Display file dialog box
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(this);
// If cancel button selected return
if (result == JFileChooser.CANCEL_OPTION) return(false);
// Obtain selected file
outputFileName = fileChooser.getSelectedFile();
// Dispaly error if invalid
if (outputFileName == null || outputFileName.getName().equals("")) {
JOptionPane.showMessageDialog(this,"Invalid File name",
"Invalid File name.",JOptionPane.ERROR_MESSAGE);
return(false);
}
else {
try {
fileOutput = new PrintWriter(new FileWriter(outputFileName));
return(true);
}
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error opening File",
"Error",JOptionPane.ERROR_MESSAGE);
return(false);
}
}
}
/* ------------------------------------------------------- */
/* */
/* SAVE OUTPUT SCHEMA */
/* */
/* ------------------------------------------------------- */
/* SAVE OUTOUT SCHEMA */
/** Saves output schema (attribute labels) to file. */
private void saveOutputSchema() {
textArea.append("SAVE OUTPUT SCHEMA\n--------------------\n");
if (openOutputFile()) {
try {
outputSchemaToFile();
}
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Writing to File",
"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
/* OUTPUT SCHEMA TO FILE */
/** Commences process of outputting to the output schema to file. */
private void outputSchemaToFile() throws IOException {
// Initial output
textArea.append("File name = " + outputFileName + "\n");
// Output
outputSchemaFlag = true;
listOutputSchema2();
outputSchemaFlag = false;
// End by closing file
fileOutput.close();
}
/* ------------------------------------------------------- */
/* */
/* FILE HANDLING UTILITIES */
/* */
/* ------------------------------------------------------- */
/* OPEN INPUT FILE */
/** Opens input file. */
private void openInputFile() {
try {
// Open file
FileReader file = new FileReader(inputFileName);
fileInput = new BufferedReader(file);
}
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
}
}
/* CLOSE INPUT FILE */
/* Closes input file. */
private void closeInputFile() {
if (fileInput != null) {
try {
fileInput.close();
}
catch (IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Opening File",
"Error 4: ",JOptionPane.ERROR_MESSAGE);
}
}
}
/* CHECK FILE NAME */
/** Checks nature of input file name selected by user.
@return false if selected file is a directory, access is denied or is
not a file name and true otherwise. */
private boolean checkFileName() {
if (inputFileName.exists()) {
if (inputFileName.canRead()) {
if (inputFileName.isFile()) return(true);
else JOptionPane.showMessageDialog(null,
"FILE ERROR: File is a directory");
}
else JOptionPane.showMessageDialog(null,
"FILE ERROR: Access denied");
}
else JOptionPane.showMessageDialog(null,
"FILE ERROR: No such file!");
// Return
return(false);
}
/* ------------------------------------------------------- */
/* */
/* INSTRUCTIONS */
/* */
/* ------------------------------------------------------- */
/* INSTRUCTIONS */
/** Outputs instructions to window. */
private void instructions() {
textArea.append("\nNOTE: Before data can be nornmalised user must:\n" +
"(1) load schema file,\n" +
"(2) load data file --- either space or comma separated, " +
"and\n(3) set number of ranges value\n\n");
}
/* ------------------------------------------------------- */
/* */
/* ARM UTILITIES */
/* */
/* ------------------------------------------------------- */
/* REALLOC 1 */
/** Resizes given item set so that its length is increased by one
and append new element
@param oldItemSet the original item set
@param newElement the new element/attribute to be appended
@return the combined item set */
protected double[] realloc1(double[] oldItemSet, double newElement) {
// No old item set
if (oldItemSet == null) {
double[] newItemSet = {newElement};
return(newItemSet);
}
// Otherwise create new item set with length one greater than old
// item set
int oldItemSetLength = oldItemSet.length;
double[] newItemSet = new double[oldItemSetLength+1];
// Loop
int index;
for (index=0;index < oldItemSetLength;index++)
newItemSet[index] = oldItemSet[index];
newItemSet[index] = newElement;
// Return new item set
return(newItemSet);
}
/* ------------------------------------------------------- */
/* */
/* MAIN METHOD */
/* */
/* ------------------------------------------------------- */
/* MAIN METHOD */
/** Main method. */
public static void main(String[] args) throws IOException {
// Create instance of class AprioriTgui
LUCS_KDD_DN_ARM newFile = new LUCS_KDD_DN_ARM("Data Preparation GUI (ARM data)");
// Make window vissible
newFile.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
newFile.setSize(700,810);
newFile.setVisible(true);
}
}