/* -------------------------------------------------------------------------- */ /* */ /* TFP ARM ALGORITHM GUI CONTROL CLASS */ /* Frans Coenen */ /* Sunday 27 May 2006 */ /* */ /* -------------------------------------------------------------------------- */ /* LUCS-KDD Total From Partial (TFP) ARM algorithm demonstrator. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; public class AprioriTFPcontrol extends JFrame implements ActionListener, ItemListener { /* ------ FIELDS ------ */ // CONSTANTS /** Minimum threshold value. */ final static double MIN_THOLD = 0.0; /** Minimum threshold value. */ final static double MAX_THOLD = 100.0; /** Maximum number of T-tree nodes that can be "drawn". */ final static int MAX_NODES_IN_TREE_GRAPH = 1000; // OBJECTS /** Instance of Total Support Tree. */ private TotalSupportTree newAprioriT = null; /** Instance of Partial Support Tree. */ private PartialSupportTree newAprioriTFP = null; /** Instance of FPTree. */ private FPtree newFPtree = null; // GUI ITEMS // Menues /** File menu. */ private JMenu fileMenu; /** Threshold input menu. */ private JMenu tHoldInputMenu; /** Data pre-processing input menu. */ private JMenu dataPreProcMenu; /** ARM menu. */ private JMenu assocRuleMiningMenu; /** Generator menu. */ private JMenu generatorMenu; /** Output menu. */ private JMenu outputMenu; /** Data array output sub-menu. */ private JMenu dataArrayOutputMenu; /** P-tree output sub-menu. */ private JMenu pTreeOutputMenu; /** T-tree output sub-menu. */ private JMenu tTreeOutputMenu; /** FP-tree output sub-menu. */ private JMenu fpTreeOutputMenu; /** Frequent set output sub-menu. */ private JMenu freqSetOutputMenu; /** Association rule output sub-menu. */ private JMenu assocRuleOutputMenu; /** Diagnostic output sub-menu. */ private JMenu diagnosticOutputSubMenu; // Menu items /** File menu items. */ private JMenuItem[] fileMenuItems; /** Threshold input menu items. */ private JMenuItem[] tholdInputMenuItems; /** Data preprocessing menu items. */ private JMenuItem[] dataPreProcMenuItems; /** ARM menu items. */ private JMenuItem[] assocRuleMiningMenuItems; /** Generator menu items. */ private JMenuItem[] generatorMenuItems; /** Output menu items. */ private JMenuItem[] outputMenuItems; /** Data array output sub-menu items. */ private JMenuItem[] dataArrayOutputMenuItems; /** P-tree output sub-menu items. */ private JCheckBoxMenuItem[] pTreeOutputMenuItems; /** T-tree output sub-menu items. */ private JMenuItem[] tTreeOutputMenuItems; /** FP-tree output sub-menu items. */ private JMenuItem[] fpTreeOutputMenuItems; /** Frequent set output sub-menu items. */ private JMenuItem[] freqSetOutputMenuItems; /** Association rule output sub-menu items. */ private JMenuItem[] assocRuleOutputMenuItems; /** Diagnostic output sub-menu items. */ private JMenuItem[] diagnosticOutputMenuItems; // Menu labels /** File menu labels. */ private String fileMenuLabels[] = {"About","Load Data","Load Schema","Exit"}; /** Threshold parameter input menu labels. */ private String tHoldInputMenuLabels[] = {"Support","Confidence"}; /** Data pre-processing menu labels. */ private String dataPreProcMenuLabels[] = {"Sort","Sort & Prune"}; /** ARM menu labels. */ private String assocRuleMiningMenuLabels[] = {"TFP (with X check)", "FP Growth"}; /** Generator menu labels. */ private String generatorMenuLabels[] = {"Generate ARs (Min Conf)", "Generate ARs (Lift)"}; /** Ouput menu labels. */ private String outputMenuLables[] = {"Output Schema"}; /** Output data array sets sub-menu labels. */ private String outputDataArrayMenuLabels[] = {"Data Att. Numbers", "Data Output Schema"}; /** Output P-tree sub-menu labels. */ private String outputPtreeMenuLabels[] = {"P-tree Stats", "P-Tree (Att. Numbers)","P-tree (Graph)"}; /** Output T-tree sub-menu labels. */ private String outputTtreeMenuLabels[] = {"T-tree Stats", "T-Tree (Att. Numbers)","T-tree (Graph)"}; /** Output FP-tree sub-menu labels. */ private String outputFPtreeMenuLabels[] = {"FP-tree Stats", "FP-Tree (Att. Numbers)","FP-tree from Header Tab."}; /** Output frequent sets sub-menu labels. */ private String outputFreqSetsMenuLabels[] = {"FSs Att. Numbers", "FSs Output Schema"}; /** Output ARs sub-menu labels. */ private String outputAssocRulesMenuLabels[] = {"ARs Att. Numbers", "ARs Output Schema"}; /** Diagnostic output sub-menu labels. */ private String outputDiagnosticMenuLabels[] = {"Conversion arrays"}; // OTHER COMPONBENTS /** Credits panel */ private JPanel creditsPanel; /** Text Area. */ private JTextArea textArea; // FLAGS /** Has support threshold flag. */ private boolean hasSupportThold = false; /** Has confidence threshold flag. */ private boolean hasConfThold = false; /** Has data flag. */ private boolean hasDataFlag = false; /** Has P-tree flag. */ private boolean hasPtree = false; /** Is sorted flag. */ private boolean isSortedFlag = false; /** Has output schema flag. */ private boolean hasOutputSchema = false; /** Has frequent sets flag. */ private boolean hasFrequentSetsFlag = false; /** Has FP tree flag. */ private boolean hasFPtreeFlag = false; /** Has ARs flag. */ private boolean hasAssocRules = false; /** Using support-confidence frame work. */ private boolean usingSCfWork = false; /** Using support-lift frame work. */ private boolean usingSLfWork = false; // OTHER FIELDS /** Input data file name. */ private File outputFileName; /** Flag indicating that P-tree statistics output is desired. */ private boolean outputPtreeStatsFlag = false; /** Flag indicating that P-tree (as text) output is desired. */ public boolean outputPtreeFlag = false; /** Flag indicating that P-tree grpah output is desired. */ private boolean outputPtreeGraphFlag = false; /* --------------------------------------------------- */ /* */ /* CONSTRUCTORS */ /* */ /* --------------------------------------------------- */ /** One argument constructor to create the TFP GUI. @param newnewAprioriT new isntance of TotalSupportTree class. */ public AprioriTFPcontrol(TotalSupportTree newNewAprioriT) { super("LUCS-KDD: TFP ARM algorith demonstrator GUI"); // Set fields newAprioriT = newNewAprioriT; // Content pane getContentPane().setBackground(Color.pink); getContentPane().setLayout(new BorderLayout(5,5)); // 5 pixel gaps // Create menus createFileMenu(); createTholdInputMenu(); createDataPreProcMenu(); createAssocRuleMiningMenu(); createGeneratorMenu(); createOutputMenu(); // Create menu bar JMenuBar bar = new JMenuBar(); setJMenuBar(bar); bar.add(fileMenu); bar.add(tHoldInputMenu); bar.add(dataPreProcMenu); bar.add(assocRuleMiningMenu); bar.add(generatorMenu); bar.add(outputMenu); // Add text area textArea = new JTextArea(40,40); textArea.setEditable(false); getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER); // Credits Panel createCreditsPanel(); getContentPane().add(creditsPanel,BorderLayout.SOUTH); } /** Creates file menu */ private void createFileMenu() { // Create file menu fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); // Create file menu items fileMenuItems = new JMenuItem[fileMenuLabels.length]; for (int index=0;index0) fileMenu.addSeparator(); fileMenu.add(fileMenuItems[index]); } } /** Creates parameter input menu */ private void createTholdInputMenu() { // Create file menu tHoldInputMenu = new JMenu("Param. Input"); tHoldInputMenu.setMnemonic('P'); // Create file menu items tholdInputMenuItems = new JMenuItem[tHoldInputMenuLabels.length]; for (int index=0;index0) tHoldInputMenu.addSeparator(); tHoldInputMenu.add(tholdInputMenuItems[index]); } } /** Creates data pre-processing menu. */ private void createDataPreProcMenu() { // Create data pre-processing menu dataPreProcMenu = new JMenu("Data Pre-proc."); dataPreProcMenu.setMnemonic('D'); // Create data pre-processing menu items dataPreProcMenuItems = new JMenuItem[dataPreProcMenuLabels.length]; for (int index=0;index0) dataPreProcMenu.addSeparator(); dataPreProcMenu.add(dataPreProcMenuItems[index]); } } /** Creates ARM menu. */ private void createAssocRuleMiningMenu() { // Create data pre-processing menu assocRuleMiningMenu = new JMenu("Gen. Frequent Sets"); assocRuleMiningMenu.setMnemonic('F'); // Create file menu items assocRuleMiningMenuItems = new JMenuItem[assocRuleMiningMenuLabels.length]; for (int index=0;index0) assocRuleMiningMenu.addSeparator(); assocRuleMiningMenu.add(assocRuleMiningMenuItems[index]); } } /** Creates generator menu */ private void createGeneratorMenu() { // Create generator menu generatorMenu = new JMenu("Generator"); generatorMenu.setMnemonic('G'); // Create generator menu items generatorMenuItems = new JMenuItem[generatorMenuLabels.length]; for (int index=0;index0) generatorMenu.addSeparator(); generatorMenu.add(generatorMenuItems[index]); } } /** Creates output menu */ private void createOutputMenu() { // Create output menu outputMenu = new JMenu("Output"); outputMenu.setMnemonic('O'); // Define array of output menu items. outputMenuItems = new JMenuItem[outputMenuLables.length]; // Create output menu items outputMenuItems = new JMenuItem[outputMenuLables.length]; for (int index=0;index0) outputMenu.addSeparator(); outputMenu.add(outputMenuItems[index]); } outputMenu.addSeparator(); // Create data array sub-menu items createDataArrayOutputMenu(); dataArrayOutputMenu.setEnabled(true); outputMenu.add(dataArrayOutputMenu); outputMenu.addSeparator(); // Create output P-tree sub-menu items createPtreeOutputMenu(); pTreeOutputMenu.setEnabled(true); outputMenu.add(pTreeOutputMenu); outputMenu.addSeparator(); // Create output T-tree sub-menu items createTtreeOutputMenu(); tTreeOutputMenu.setEnabled(true); outputMenu.add(tTreeOutputMenu); outputMenu.addSeparator(); // Create output FP-tree sub-menu items createFPtreeOutputMenu(); fpTreeOutputMenu.setEnabled(true); outputMenu.add(fpTreeOutputMenu); outputMenu.addSeparator(); // Create output frequent sets sub-menu items createFreqSetsOutputMenu(); freqSetOutputMenu.setEnabled(true); outputMenu.add(freqSetOutputMenu); outputMenu.addSeparator(); // Create output association rules sub-menu items createARsOutputMenu(); assocRuleOutputMenu.setEnabled(true); outputMenu.add(assocRuleOutputMenu); outputMenu.addSeparator(); // Create output association rules sub-menu items creatediagnosticOutputSubMenu(); diagnosticOutputSubMenu.setEnabled(true); outputMenu.add(diagnosticOutputSubMenu); } /** Creates data array output sub-menu */ private void createDataArrayOutputMenu() { // Create file menu dataArrayOutputMenu = new JMenu("Data Array"); dataArrayOutputMenu.setMnemonic('D'); // Create buttons dataArrayOutputMenuItems = new JMenuItem[outputDataArrayMenuLabels.length]; for (int index=0;index0) dataArrayOutputMenu.addSeparator(); dataArrayOutputMenu.add(dataArrayOutputMenuItems[index]); } } /** Creates P-tree output sub-menu comprising check boxes. */ private void createPtreeOutputMenu() { // Create file menu pTreeOutputMenu = new JMenu("P Tree"); pTreeOutputMenu.setMnemonic('P'); // Create buttons pTreeOutputMenuItems = new JCheckBoxMenuItem[outputPtreeMenuLabels.length]; for (int index=0;index0) tTreeOutputMenu.addSeparator(); tTreeOutputMenu.add(tTreeOutputMenuItems[index]); } } /** Creates FP-tree output sub-menu */ private void createFPtreeOutputMenu() { // Create file menu fpTreeOutputMenu = new JMenu("FP Tree"); fpTreeOutputMenu.setMnemonic('F'); // Create buttons fpTreeOutputMenuItems = new JMenuItem[outputFPtreeMenuLabels.length]; for (int index=0;index0) fpTreeOutputMenu.addSeparator(); fpTreeOutputMenu.add(fpTreeOutputMenuItems[index]); } } /** Creates frequent sets output sub-menu */ private void createFreqSetsOutputMenu() { // Create file menu freqSetOutputMenu = new JMenu("Frequent Sets"); freqSetOutputMenu.setMnemonic('S'); // Create buttons freqSetOutputMenuItems = new JMenuItem[outputFreqSetsMenuLabels.length]; for (int index=0;index0) freqSetOutputMenu.addSeparator(); freqSetOutputMenu.add(freqSetOutputMenuItems[index]); } } /** Creates association rules output sub-menu */ private void createARsOutputMenu() { // Create file menu assocRuleOutputMenu = new JMenu("Association Rules"); assocRuleOutputMenu.setMnemonic('A'); // Create buttons assocRuleOutputMenuItems = new JMenuItem[outputAssocRulesMenuLabels.length]; for (int index=0;index0) assocRuleOutputMenu.addSeparator(); assocRuleOutputMenu.add(assocRuleOutputMenuItems[index]); } } /** Creates association rules output sub-menu */ private void creatediagnosticOutputSubMenu() { // Create file menu diagnosticOutputSubMenu = new JMenu("Diagnostics"); diagnosticOutputSubMenu.setMnemonic('D'); // Create buttons diagnosticOutputMenuItems = new JMenuItem[outputDiagnosticMenuLabels.length]; for (int index=0;index0) diagnosticOutputSubMenu.addSeparator(); diagnosticOutputSubMenu.add(diagnosticOutputMenuItems[index]); } } /* --------------------------------- */ /* */ /* CREATE CREDITS PANELS */ /* */ /* --------------------------------- */ /** Creates credits panel. */ private void createCreditsPanel() { // Swet up panel creditsPanel = new JPanel(); creditsPanel.setBackground(Color.pink); creditsPanel.setLayout(new GridLayout(4,1)); // Create labels Label creditLabel1 = new Label("LUCS-KDD (Liverpool University " + "Computer Science - Knowledge Discovery"); Label creditLabel2 = new Label("in Data) group Total Frpm Partial " + "(TFP) ARM demonstrator."); Label creditLabel3 = new Label(" "); Label creditLabel4 = new Label("Version 1 Created by Frans Coenen " + "(27 July 2006)"); // Add labels creditsPanel.add(creditLabel1); creditsPanel.add(creditLabel2); creditsPanel.add(creditLabel3); creditsPanel.add(creditLabel4); } /* -------------------- */ /* */ /* HANDLERS */ /* */ /* -------------------- */ /** Action performed handler. @param event the triggered event. */ public void actionPerformed(ActionEvent event) { // File menu item About if (event.getActionCommand().equals("About")) { textArea.append("ABOUT THE ARM DATA GENERATOR:\n"); aboutSoftware(); textArea.append("-------------------------------------\n"); } // File menu load data else if (event.getActionCommand().equals("Load Data")) { textArea.append("LOAD DATA FILE:\n"); loadData(); textArea.append("-------------------------------------\n"); } // File menu load output schema else if (event.getActionCommand().equals("Load Schema")) { textArea.append("READ OUTPUT SCHEMA FILE:\n"); loadOutputSchema(); textArea.append("-------------------------------------\n"); } // File menu exit else if (event.getActionCommand().equals("Exit")) { System.exit(0); } // Threshold input menu item add support threshold else if (event.getActionCommand().equals("Support")) { textArea.append("INPUT SUPPORT THRESHOLD:\n"); inputSupportThold(); textArea.append("-------------------------------------\n"); } // Threshold input menu item add confidence threshold else if (event.getActionCommand().equals("Confidence")) { textArea.append("INPUT CONFIDENCE THRESHOLDS:\n"); inputConfidenceThold(); textArea.append("-------------------------------------\n"); } // Data pre-processing menu item sort input data. */ else if (event.getActionCommand().equals("Sort")) { textArea.append("SORT INPUT DATA:\n"); sortInputData(); textArea.append("-------------------------------------\n"); } // Data pre-processing menu item sort and prune input data. */ else if (event.getActionCommand().equals("Sort & Prune")) { textArea.append("SORT AND PRUNE INPUT DATA:\n"); sortAndPruneInputData(); textArea.append("-------------------------------------\n"); } // TFP menu item TFP without X checking. */ else if (event.getActionCommand().equals("TFP (with X check)")) { textArea.append("TFP (WITH X CHECK):\n"); tfpWithXcheck(); textArea.append("-------------------------------------\n"); } // TFP menu item FP growth. */ else if (event.getActionCommand().equals("FP Growth")) { textArea.append("FP GROWTH (WITH T-TREE STORAGE):\n"); fpGrowth(); textArea.append("-------------------------------------\n"); } // Generate menu item generate ARs using confidence. else if (event.getActionCommand().equals("Generate ARs (Min Conf)")) { textArea.append("GENERATE ARs (SUPPORT AND CONFIDENCE FRAMEWORK):\n"); generateARsMinConf(); textArea.append("-------------------------------------\n"); } // Generate menu item generate ARs using lift. else if (event.getActionCommand().equals("Generate ARs (Lift)")) { textArea.append("GENERATE ARs (SUPPORT AND LIFT FRAMEWORK):\n"); generateARsLift(); textArea.append("-------------------------------------\n"); } // Output schema output sub-memu item output using attribute numbers else if (event.getActionCommand().equals("Output Schema")) { textArea.append("OUTPUT OUTPUT SCHEMA CONTENTS:\n"); outputOutputSchema(); textArea.append("-------------------------------------\n"); } // Data array output sub-memu item output using attribute numbers else if (event.getActionCommand().equals("Data Att. Numbers")) { textArea.append("OUTPUT DATA ARRAY USING ATTRIBUTE NUMBERS:\n"); outputDataArrayAtts(); textArea.append("-------------------------------------\n"); } // Frequent sets output sub-memu item output using output schema else if (event.getActionCommand().equals("Data Output Schema")) { textArea.append("OUTPUT DATA ARRAY USING OUTPUT SCHEMA:\n"); outputDataArraySchema(); textArea.append("-------------------------------------\n"); } // T-tree output sub-memu item output T-tree statistics else if (event.getActionCommand().equals("T-tree Stats")) { textArea.append("OUTPUT T-TREE STATISTICS:\n"); outputTtreeStats(); textArea.append("-------------------------------------\n"); } // T-tree output sub-memu item output T-tree in textual format else if (event.getActionCommand().equals("T-Tree (Att. Numbers)")) { textArea.append("OUTPUT T-TREE AS TEXTUAL lIST:\n"); outputTtree(); textArea.append("-------------------------------------\n"); } // T-tree output sub-memu item output T-tree graph if possible else if (event.getActionCommand().equals("T-tree (Graph)")) { textArea.append("OUTPUT T-TREE AS GRAPH IMAGE:\n"); outputTtreeGraph(); textArea.append("-------------------------------------\n"); } // FP-tree output sub-memu item output FP tree statistics else if (event.getActionCommand().equals("FP-tree Stats")) { textArea.append("OUTPUT FP-TREE STATISTICS:\n"); outputFPtreeStats(); textArea.append("-------------------------------------\n"); } // FP-tree output sub-memu item output FP-tree as textual list else if (event.getActionCommand().equals("FP-Tree (Att. Numbers)")) { textArea.append("OUTPUT FP-TREE AS TEXTUAL lIST:\n"); outputFPtree(); textArea.append("-------------------------------------\n"); } // FP-tree output prefix sub-tree graph else if (event.getActionCommand().equals("FP-tree from Header Tab.")) { textArea.append("OUTPUT FP-TREE FROM HEADER TABLE:\n"); outputPreFixSubtree(); textArea.append("-------------------------------------\n"); } // Frequent sets output sub-memu item output using attribute numbers else if (event.getActionCommand().equals("FSs Att. Numbers")) { textArea.append("OUTPUT FREQUENT SETS USING ATTRIBUTE NUMBERS:\n"); outputFreqSetsAtts(); textArea.append("-------------------------------------\n"); } // Frequent sets output sub-memu item output using output schema else if (event.getActionCommand().equals("FSs Output Schema")) { textArea.append("OUTPUT FREQUENT SETS USING OUTPUT SCHEMA:\n"); outputFreqSetsSchema(); textArea.append("-------------------------------------\n"); } // Association rules output sub-memu item output using attribute numbers else if (event.getActionCommand().equals("ARs Att. Numbers")) { textArea.append("OUTPUT ASSOCIATION RULES USING ATTRIBUTE NUMBERS:\n"); outputARsAtts(); textArea.append("-------------------------------------\n"); } // Association rules output sub-memu item output using output schema else if (event.getActionCommand().equals("ARs Output Schema")) { textArea.append("OUTPUT ASSOCIATION RULES USING OUTPUT SCHEMA:\n"); outputARsSchema(); textArea.append("-------------------------------------\n"); } // Diagnostic output sub-memu item output concersion arrays else if (event.getActionCommand().equals("Conversion arrays")) { textArea.append("OUTPUT CONVERSION AND RECOMVERSION ARRAYS:\n"); outputConversionArrays(); textArea.append("-------------------------------------\n"); } // Defualt else { JOptionPane.showMessageDialog(null,"ERROR:\n Unrecognised " + "action event, " + event.getActionCommand() + "\n"); } } /** Item state change handler. @param event the triggered event. */ public void itemStateChanged(ItemEvent event) { // Output P-tree stata if (pTreeOutputMenuItems[0].isSelected()) { if (!outputPtreeStatsFlag) { textArea.append("OUTPUT P-TREE STATISTICS:\nOn next P-tree " + "generation\n"); outputPtreeStatsFlag = true; textArea.append("-------------------------------------\n"); } } else outputPtreeStatsFlag = false; // Output P-tree (in text form) if (pTreeOutputMenuItems[1].isSelected()) { if (!outputPtreeFlag) { textArea.append("OUTPUT P-TREE AS TEXTUAL LIST:\nOn next " + "P-tree generation\n"); outputPtreeFlag = true; textArea.append("-------------------------------------\n"); } } else outputPtreeFlag = false; // Output P-tree graph if (pTreeOutputMenuItems[2].isSelected()) { if (!outputPtreeGraphFlag) { textArea.append("OUTPUT P-TREE AS GRAPH IMAGE:\nOn next " + "P-tree generation\n"); outputPtreeGraphFlag = true; textArea.append("-------------------------------------\n"); } } else outputPtreeGraphFlag = false; } /* ------------------------- */ /* */ /* ABOUT SOFTWARE */ /* */ /* ------------------------- */ /* ABOUT SOFTWARE */ /** Outputs text describing software. */ private void aboutSoftware() { textArea.append("To run the software:\n"); textArea.append("\t1. Specify input data (and if desired output " + "schema).\n"); textArea.append("\t2. Set support and (if appropriate) confidence " + "thresholds.\n"); textArea.append("\t3. Select either TFP or FP growth algorithum to be run\n"); textArea.append("\t4. When algorithm complete generate ARs if desired\n"); textArea.append("\t5. Output results\n"); } /* -------------------------------------- */ /* */ /* LOAD DATA */ /* */ /* -------------------------------------- */ /** Reads input data from file specified in command line argument and places data in inputDataArray.*/ private void loadData() { // Display file dialog so user can select file to open JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fileChooser.showOpenDialog(this); // If cancel button selected return if (result == JFileChooser.CANCEL_OPTION) { textArea.append("Operation cancelled\n"); return; } // Obtain selected file File inputFileName = fileChooser.getSelectedFile(); // Read file if readabale (i.e not a direcrory etc.). if (checkFileName(inputFileName)) { textArea.append("inputFileName = " + inputFileName + "\n"); newAprioriT.inputDataSet(textArea,inputFileName); if (hasOutputSchema) newAprioriT.checkSchemaVdata(); hasDataFlag = true; // Set is sorted flag to false (ready for sorting if desired) isSortedFlag = false; // Set minumum support value in terms of number of rows. if (hasSupportThold) { newAprioriT.setMinSupport(); outputMinSupport(); } } } /* CHECK FILE NAME */ /** Checks nature of input file name selected by user. @param fileName name of file to be checked @return false if selected file is a directory, access is denied or is not a file name and true otherwise. */ private boolean checkFileName(File fileName) { boolean fileOK = true; // Check if file name exist if (fileName.exists()) { // Check if file name is readable if (fileName.canRead()) { // Check id file name is actually a file if (fileName.isFile()) return(fileOK); 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(!fileOK); } /* ----------------------------------------------- */ /* */ /* LOAD OUTPUT SCHEMA */ /* */ /* ----------------------------------------------- */ /** Commences process of loading output schema to be used for the outpur of the generated frequent sets and ARs. */ private void loadOutputSchema() { // Display file dialog so user can select file to open JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fileChooser.showOpenDialog(this); // If cancel button selected return // If cancel button selected return if (result == JFileChooser.CANCEL_OPTION) { textArea.append("Operation cancelled\n"); return; } // Obtain selected file File inputFileName = fileChooser.getSelectedFile(); // Read file if readabale (i.e not a direcrory etc.). if (checkFileName(inputFileName)) { textArea.append("inputFileName = " + inputFileName + "\n"); newAprioriT.inputOutputSchema(textArea,inputFileName); if (hasDataFlag) newAprioriT.checkSchemaVdata(); hasOutputSchema = true; } else hasOutputSchema = false; } /* ---------------------------------------------------- */ /* */ /* INPUT SUPPORT THRESHOLD */ /* */ /* ---------------------------------------------------- */ /** Input the support threshold to be used in the identification of frequent sets. */ private void inputSupportThold() { String stNum = null; // Try catch block try{ while (true) { stNum = JOptionPane.showInputDialog("Input desired " + "support threshold (%)\n\n" ); // Check if operation cancelled if (stNum == null) { textArea.append("Operation cancelled!\n"); break; } // Process input double newSupportThold = Double.parseDouble(stNum); // Check if within range if ((newSupportThold < MIN_THOLD) || (newSupportThold > MAX_THOLD)) { JOptionPane.showMessageDialog(null,"INPUT ERROR:\n " + "support threshold input, " + newSupportThold + ",\nnot within range " + MIN_THOLD + " to " + MAX_THOLD + ".\n"); textArea.append("Try agin!\n"); } else { newAprioriT.setSupport(newSupportThold); outputSupportThold(); if (hasDataFlag) { newAprioriT.setMinSupport(); outputMinSupport(); } hasSupportThold=true; break; } } } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null,"INPUT ERROR:\n " + "Number format exception, support\nthreshold (%) " + "input = \"" + stNum + "\".\n"); textArea.append("Operation failed!\n"); } } /* ------------------------------------------------------- */ /* */ /* INPUT CONFIDENCE THRESHOLD */ /* */ /* ------------------------------------------------------- */ /** Input the confidence threshold to be used in the identification of ARs (if not using lift). */ private void inputConfidenceThold() { String stNum = null; // Try catch block try{ while (true) { stNum = JOptionPane.showInputDialog("Input desired " + "confidence threshold (%)\n\n" ); // Check if operation cancelled if (stNum == null) { textArea.append("Operation cancelled!\n"); break; } // Process input double newConfidenceThold = Double.parseDouble(stNum); // Check if within range if ((newConfidenceThold < MIN_THOLD) || (newConfidenceThold > MAX_THOLD)) { JOptionPane.showMessageDialog(null,"INPUT ERROR:\n " + "confidence threshold input, " + newConfidenceThold + ",\nnot within range " + MIN_THOLD + " to " + MAX_THOLD + ".\n"); textArea.append("Try agin!\n"); } else { newAprioriT.setConfidence(newConfidenceThold); outputConfidenceThold(); hasConfThold=true; break; } } } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null,"INPUT ERROR:\n " + "Number format exception, confidence\nthreshold (%) " + "input = \"" + stNum + "\".\n"); textArea.append("Operation failed!\n"); } } /* ------------------------------ */ /* */ /* SORT INPUT DATA */ /* */ /* ------------------------------ */ /** Commences process of sorting input data in order of support value, highest supported attributers listed first. */ private void sortInputData() { boolean okToProceed = true; // Check if data already has been preprocessed if (isSortedFlag) { JOptionPane.showMessageDialog(null,"PRE-PROCESSING ERROR:\n " + "Data has already been pre-processed.\n"); okToProceed = false; } // Check data else if (!hasDataFlag) { JOptionPane.showMessageDialog(null,"PRE-PROCESSING ERROR:\n " + "No data supplied.\n"); okToProceed = false; } // If OK to proceed reorder input data according to frequency of single // attributes if (okToProceed) { newAprioriT.idInputDataOrdering(); newAprioriT.recastInputData(); isSortedFlag = true; } else textArea.append("Operation failed!\n"); } /* ---------------------------------------- */ /* */ /* SORT AND PRUNE INPUT DATA */ /* */ /* ---------------------------------------- */ /** Commences process of sorting and pruning input data in order of support value, highest supported attributers listed first, attributes with support below support threshold deleted. */ private void sortAndPruneInputData() { boolean okToProceed = true; if (isSortedFlag) { JOptionPane.showMessageDialog(null,"PRE-PROCESSING ERROR:\n " + "Data has already been pre-processed.\n"); okToProceed = false; } else { // Check data if (!hasDataFlag) { JOptionPane.showMessageDialog(null,"PRE-PROCESSING ERROR:\n " + "No data supplied.\n"); okToProceed = false; } // Check support threshold if (!hasSupportThold) { JOptionPane.showMessageDialog(null,"PRE-PROCESSING ERROR:\n " + "No support threshold supplied.\n"); okToProceed = false; } } // If OK to proceed reorder and prune input data according to frequency // of single attributes if (okToProceed) { newAprioriT.idInputDataOrdering(); newAprioriT.recastInputDataAndPruneUnsupportedAtts(); newAprioriT.setNumOneItemSets(); isSortedFlag = true; } else textArea.append("Operation failed!\n"); } /* ---------------------------------- */ /* */ /* TFP WITH X CHECKING */ /* */ /* ---------------------------------- */ /** Commences application of TFP algorithm (with X-checking). */ private void tfpWithXcheck() { boolean okToProceed = true; newAprioriTFP = null; hasPtree = false; hasFPtreeFlag = false; hasFrequentSetsFlag = false; // Check data if (!hasDataFlag) { JOptionPane.showMessageDialog(null,"TFP ERROR:\n " + "No data supplied.\n"); okToProceed = false; } // Check support threshold if (!hasSupportThold) { JOptionPane.showMessageDialog(null,"TFP ERROR:\n " + "No support threshold supplied.\n"); okToProceed = false; } // If OK to proceed apply TFP (with X check) if (okToProceed) { // Start timer double time1 = (double) System.currentTimeMillis(); // Create instance of PartialSupportTree class newAprioriTFP = new PartialSupportTree(newAprioriT); // Set output flags newAprioriTFP.setOutputPtreeStatsFlag(outputPtreeStatsFlag); newAprioriTFP.setOutputPtreeFlag(outputPtreeFlag); newAprioriTFP.setOutputPtreeGraphFlag(outputPtreeGraphFlag, MAX_NODES_IN_TREE_GRAPH); // Generatwe P-tree newAprioriTFP.createPtree(textArea); // Create T-tree newAprioriTFP.createTotalSupportTree(textArea); // Output timer newAprioriTFP.outputDuration(textArea,time1, System.currentTimeMillis()); // Check if limit has been reached int numFsets = newAprioriTFP.getNumFreqSets(); int maxFsets = newAprioriTFP.getMaxNumFrequentSets(); if (numFsets>maxFsets) textArea.append("Number of frequent sets " + "generated so far, " + numFsets + "exceeds maximum of " + maxFsets + ".\n"); else textArea.append("Number of frequent sets = " + numFsets + ".\n"); // Copy Ttree newAprioriT = newAprioriTFP; // Set flag hasFrequentSetsFlag = true; hasPtree = true; } else textArea.append("Operation failed!\n"); } /* ----------------------------------------------- */ /* */ /* FP GROWTH (WITH T-TREE STORAGE) */ /* */ /* ----------------------------------------------- */ /** Comences FP Groeth algorithm. */ private void fpGrowth() { boolean okToProceed = true; newAprioriTFP = null; hasPtree = false; hasFPtreeFlag = false; hasFrequentSetsFlag = false; // Check data if (!hasDataFlag) { JOptionPane.showMessageDialog(null,"FP GROWTH ERROR:\n " + "No data supplied.\n"); okToProceed = false; } // Check support threshold if (!hasSupportThold) { JOptionPane.showMessageDialog(null,"FP GROWTH ERROR:\n " + "No support threshold supplied.\n"); okToProceed = false; } // If OK to proceed apply FP Grpeth if (okToProceed) { // Start timer double time1 = (double) System.currentTimeMillis(); // Create instance of class FPTree newFPtree = new FPtree(newAprioriT); // Build initial FP-tree newFPtree.createFPtree(); // Mine FP-tree newFPtree.startMining(); // Output timer newFPtree.outputDuration(textArea,time1, System.currentTimeMillis()); // Copy FPgrowth T-tree newAprioriT = newFPtree; int numFsets = newAprioriT.getNumFreqSets(); textArea.append("Number of frequent sets = " + numFsets + ".\n"); // Set flags hasFPtreeFlag = true; hasFrequentSetsFlag = true; } else { textArea.append("Operation failed!\n"); hasFrequentSetsFlag = false; } } /* ---------------------------------------------------------------------- */ /* */ /* GENERATE ASSOCIATION RULES USING SUPPORT AND CONFIDENCE FRAMEWORK */ /* */ /* ---------------------------------------------------------------------- */ /** Commences process of generating ARs using support and confidence framework by checking that system has frequent sets and confidence threshold. */ private void generateARsMinConf() { boolean okToProceed = true; // Check frequent sets if (!hasFrequentSetsFlag) { JOptionPane.showMessageDialog(null,"AR GENERATOR ERROR:\n " + "No frequent sets generated.\n"); okToProceed = false; } // Check confidence threshold if (!hasConfThold) { JOptionPane.showMessageDialog(null,"AR GENERATOR ERROR:\n " + "No confidence threshold supplied.\n"); okToProceed = false; } // Check if OK to proceed if (okToProceed) { usingSCfWork = true; usingSLfWork = false; newAprioriT.generateARs(); hasAssocRules = true; } else { textArea.append("Operation failed!\n"); hasAssocRules = false; } } /* ---------------------------------------------------------------------- */ /* */ /* GENERATE ASSOCIATION RULES USING SUPPORT AND LIFT FRAMEWORK */ /* */ /* ---------------------------------------------------------------------- */ /** Commences ARM brute force algorithm using support and lift framework by checking that system has data and support threshold . */ private void generateARsLift() { boolean okToProceed = true; // Check frequent sets if (!hasFrequentSetsFlag) { JOptionPane.showMessageDialog(null,"AR GENERATOR ERROR:\n " + "No frequent sets generated.\n"); okToProceed = false; } // Check if OK to proceed if (okToProceed) { usingSCfWork = false; usingSLfWork = true; newAprioriT.generateARsLift(); hasAssocRules = true; } else { textArea.append("Operation failed!\n"); hasAssocRules = false; } } /* -------------------------------- */ /* */ /* OUTPUT OUTPUT SCHEMA */ /* */ /* -------------------------------- */ /** Outputs output schema. */ private void outputOutputSchema() { if (hasOutputSchema) newAprioriT.outputOutputSchema(textArea); else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No output schema loaded!\n"); textArea.append("Operation failed!\n"); } } /* -------------------------------------------------- */ /* */ /* OUTPUT DATA ARRAY AS ATTRIBUTE NUMBERS */ /* */ /* -------------------------------------------------- */ /** Outputs data array using attribute number representation. */ private void outputDataArrayAtts() { if (hasDataFlag) newAprioriT.outputDataArray(textArea); else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No input data loaded!\n"); textArea.append("Operation failed!\n"); } } /* ---------------------------------------------- */ /* */ /* OUTPUT DATA ARRAY AS SCHEMA LABELS */ /* */ /* ---------------------------------------------- */ /** Outputs data array using schema label representation. */ private void outputDataArraySchema() { if (hasDataFlag) { if (hasOutputSchema) newAprioriT.outputDataArraySchema(textArea); else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No output schema loaded!\n"); textArea.append("Operation failed!\n"); } } else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No input data loaded!\n"); textArea.append("Operation failed!\n"); } } /* ------------------------------------ */ /* */ /* OUTPUT T-TREE STATISTICS */ /* */ /* ------------------------------------ */ /** Outputs T-tree statistics. */ private void outputTtreeStats() { // Check frequent sets if (hasFrequentSetsFlag) newAprioriT.outputTtreeStats(textArea); else { JOptionPane.showMessageDialog(null,"T-TREE OUTPUT ERROR:\n " + "No frequent sets generated.\n"); textArea.append("Operation failed!\n"); } } /* -------------------------- */ /* */ /* OUTPUT T-TREE */ /* */ /* -------------------------- */ /** Outputs T tree as a textual list. */ private void outputTtree() { // Check frequent sets if (hasFrequentSetsFlag) newAprioriT.outputTtree(textArea); else { JOptionPane.showMessageDialog(null,"T-TREE OUTPUT ERROR:\n " + "No frequent sets generated.\n"); textArea.append("Operation failed!\n"); } } /* ------------------------------- */ /* */ /* OUTPUT T-TREE GRAPH */ /* */ /* ------------------------------- */ /** Outputs T-tree graph. */ private void outputTtreeGraph() { // Check if T-tree generated if (!hasFrequentSetsFlag) { JOptionPane.showMessageDialog(null,"T-TREE GRAPH OUTPUT ERROR:\n " + "No frequent sets generated.\n"); textArea.append("Operation failed!\n"); return; } // If more than 1000 frequent sets return if (newAprioriT.getNumFreqSets()>MAX_NODES_IN_TREE_GRAPH) { JOptionPane.showMessageDialog(null,"TOO MANY FREQUENT SETS:\n" + "Only T-trees with less than " + MAX_NODES_IN_TREE_GRAPH + "\nlarge sets can be graphically presented.\n"); textArea.append("Operation failed!\n"); return; } // Otherwise process TtreeWindow tTreeWinApp = new TtreeWindow(newAprioriT.getNnumFreqOneItemSets(), newAprioriT.getStartOfTtree(), newAprioriT.getMinSupport()); tTreeWinApp.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); } /* ------------------------------------- */ /* */ /* OUTPUT FP-TREE STATISTICS */ /* */ /* ------------------------------------- */ /** Outputs FP tree statistics. */ private void outputFPtreeStats() { // Check frequent sets if (hasFPtreeFlag) newFPtree.outputFPtreeStats(textArea); else { JOptionPane.showMessageDialog(null,"FP-TREE OUTPUT ERROR:\n " + "No FP tree generated.\n"); textArea.append("Operation failed!\n"); } } /* --------------------------- */ /* */ /* OUTPUT FP-TREE */ /* */ /* --------------------------- */ /** Outputs FP tree as a textual list. */ private void outputFPtree() { // Check frequent sets if (hasFPtreeFlag) newFPtree.outputFPtree(textArea); else { JOptionPane.showMessageDialog(null,"FP-TREE OUTPUT ERROR:\n " + "No FP tree generated.\n"); textArea.append("Operation failed!\n"); } } /* -------------------------------------- */ /* */ /* OUTPUT FP-TREE PREFIX TREE */ /* */ /* -------------------------------------- */ /** Outputs FP tree as a textual list. */ private void outputPreFixSubtree() { // Check frequent sets if (hasFPtreeFlag) newFPtree.outputItemPrefixSubtree(textArea); else { JOptionPane.showMessageDialog(null,"FP-TREE OUTPUT ERROR:\n " + "No FP tree generated.\n"); textArea.append("Operation failed!\n"); } } /* ----------------------------------------------------- */ /* */ /* OUTPUT FREQUENT SETS AS ATTRIBUTE NUMBERS */ /* */ /* ----------------------------------------------------- */ /** Outputs frequent sets using attribute number representation. */ private void outputFreqSetsAtts() { // Check if ARM algorithm has been run. if (hasFrequentSetsFlag) newAprioriT.outputFrequentSets(textArea); else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "ARM algorirthm not run, therefore\n" + "no frequent sets generated.\n"); textArea.append("Operation failed!\n"); } } /* ------------------------------------------------- */ /* */ /* OUTPUT FREQUENT SETS AS SCHEMA LABELS */ /* */ /* ------------------------------------------------- */ /** Commences output of frequent sets using lables contained in output schema by checking that system has data and support threshold . */ private void outputFreqSetsSchema() { boolean okToProceed = true; // Check output schema exists if (!hasOutputSchema) { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No output schema provided.\n"); okToProceed = false; } // Check if ARM algorithm has been run. if (!hasFrequentSetsFlag) { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "ARM algorirthm not run, therefore\n" + "no frequent sets generated.\n"); okToProceed = false; } // Check if OK to proceed if (okToProceed) newAprioriT.outputFrequentSetsSchema(textArea); else textArea.append("Operation failed!\n"); } /* -------------------------------------------------------- */ /* */ /* OUTPUT ASSOCIAION RULES AS ATTRIBUTE NUMBERS */ /* */ /* -------------------------------------------------------- */ /** Outputs Association Rules (ARs) using attribute number representation. */ private void outputARsAtts() { // Check if ARM algorithm has been run. if (hasAssocRules) { textArea.append("(N) ANTECEDENT -> CONSEQUENT "); if (usingSCfWork) textArea.append("CONFIDENCE (%)\n"); if (usingSLfWork) textArea.append("LIFT\n"); newAprioriT.outputRules(textArea); } else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "no association rules generated\n" + "(select generate option).\n"); textArea.append("Operation failed!\n"); } } /* ---------------------------------------------------- */ /* */ /* OUTPUT ASSOCIAION RULES AS SCHEMA LABELS */ /* */ /* ---------------------------------------------------- */ /** Commences output Association Rules (ARs) using lables contained in output schema by checking that system has data and support threshold . */ private void outputARsSchema() { // Check output schema exists if (!hasOutputSchema) { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No output schema provided.\n"); textArea.append("Operation failed!\n"); } else { // Check if ARM algorithm has been run. if (!hasAssocRules) { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "ARM algorirthm not run, therefore\n" + "no association rules generated.\n"); textArea.append("Operation failed!\n"); } // Check if OK to proceed else { textArea.append("(N) ANTECEDENT -> CONSEQUENT "); if (usingSCfWork) textArea.append("CONFIDENCE (%)\n"); if (usingSLfWork) textArea.append("LIFT\n"); newAprioriT.outputRulesSchema(textArea); } } } /* ------------------------------------ */ /* */ /* OUTPUT CONVERSION ARRAYS */ /* */ /* ------------------------------------ */ /** Outputs conversion (and reconversion) arrays. */ private void outputConversionArrays() { if (isSortedFlag) newAprioriT.outputConversionArrays(textArea); // Error output of no data else { if (!hasDataFlag) { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "No input data loaded!\n"); textArea.append("Operation failed!\n"); } else { JOptionPane.showMessageDialog(null,"OUTPUT ERROR:\n " + "Data has not been sorted!\n"); textArea.append("Operation failed!\n"); } } } /* ----------------------------------- */ /* */ /* OUTPUT */ /* */ /* ----------------------------------- */ /** Outputs the support tyhreshold to the text area. */ private void outputSupportThold() { textArea.append("Support threshold (%) = " + newAprioriT.getSupport() + "\n"); } /** Outputs the confidence threshold to the text area. */ private void outputConfidenceThold() { textArea.append("Confidence threshold (%) = " + newAprioriT.getConfidence() + "\n"); } /** Outputs the minimum support value to the text area. */ private void outputMinSupport() { textArea.append("Minimum support (# records) = " + newAprioriT.getMinSupport() + "\n"); } /* -------------------------------- */ /* */ /* OUTPUT UTILITIES */ /* */ /* -------------------------------- */ /* TWO DECIMAL PLACES */ /** Converts given real number to real number rounded up to two decimal places. @param number the given number. @return the number to two decimal places. */ protected double twoDecPlaces(double number) { int numInt = (int) ((number+0.005)*100.0); number = ((double) numInt)/100.0; return(number); } }