static void Main(string[] args) { if (args.Length == 0) { Form1 form = new Form1(); form.ShowDialog(); } else { MinerParams minerParams = null; try { minerParams = MinerParams.Parse(args); DateTime timeBefore = DateTime.Now; MineResults mineResult = null; mineResult = DoMine(minerParams); if (mineResult != null) { try { System.Console.WriteLine("Mining time : " + (DateTime.Now - timeBefore)); System.Console.WriteLine("Total found " + mineResult.Count.ToString() + " patterns"); System.Console.WriteLine(mineResult.ToString()); } catch (Exception ex) { MessageBox.Show("Exception during writing result: " + ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { mineResult.Dispose(); mineResult = null; } } } catch (ArgumentException ex) { System.Console.WriteLine("Failed to parse command line argument: " + ex.Message); System.Console.WriteLine(); System.Console.WriteLine(MinerParams.Usage()); } } }
private void buttonMine_Click(object sender, System.EventArgs e) { MinerParams minerParams = new MinerParams(); if (textBoxDatasetPath.Text == "") { MessageBox.Show("No dataset selected", "Dataset Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } minerParams.DatasetFileName = textBoxDatasetPath.Text; minerParams.InputContainsColumnHeaders = this.checkBoxInputColumnHeaders.Checked; minerParams.InputContainsRowHeaders = this.checkBoxInputRowHeaders.Checked; minerParams.WriteOutputFiles = this.checkBoxWriteOutput.Checked; minerParams.WriteAllResults = this.checkBoxWriteAllResults.Checked; minerParams.MinSupport = Int32.Parse(textBoxSupport.Text); minerParams.MinLength = Int32.Parse(textBoxMinLength.Text); minerParams.MaxLength = Int32.Parse(textBoxMaxLength.Text); minerParams.MaxErrors = Int32.Parse(textBoxMaxErrors.Text); minerParams.MinGroups = Int32.Parse(textBoxMinGroups.Text); minerParams.MaxLayerDiff = Int32.Parse(textBoxMaxLayerDiff.Text); minerParams.InCoreDualCompare = this.checkBoxUseInCoreDualCompare.Checked; if (radioButtonOPSM.Checked == true) { minerParams.Algorithm = Algorithm.OPSM; } else if (radioButtonTreePattern.Checked == true) { minerParams.Algorithm = Algorithm.TreePattern; } else if (radioButtonWithError.Checked == true) { minerParams.Algorithm = Algorithm.WithErrors; } else if (radioButtonGroups.Checked == true) { minerParams.Algorithm = Algorithm.Groups; } else if (radioButtonLayers.Checked == true) { minerParams.Algorithm = Algorithm.Layers; } else { throw new ArgumentException("Unsupported algorithm"); } buttonMine.Enabled = false; DateTime timeBefore = DateTime.Now; MineResults mineResult = null; richTextBoxResults.Clear(); mineResult = OPSMMain.DoMine(minerParams); if (mineResult != null) { try { richTextBoxResults.AppendText("Mining time : " + (DateTime.Now - timeBefore) + "\n"); richTextBoxResults.AppendText("Total found " + mineResult.Count.ToString() + " patterns\n"); richTextBoxResults.AppendText(mineResult.ToString()); } catch (Exception ex) { MessageBox.Show("Exception during writing result: " + ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { mineResult.Dispose(); mineResult = null; } } buttonMine.Enabled = true; }
public static MineResults DoMine(MinerParams minerParams) { int parameter1 = 0; OPSM.Dataset dataset = null; MineResults mineResult = null; try { dataset = new Dataset( minerParams.DatasetFileName, minerParams.InputContainsColumnHeaders, minerParams.InputContainsRowHeaders); } catch (Exception ex) { MessageBox.Show("Failed to load dataset: " + ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (dataset != null) { try { if (minerParams.Algorithm == Algorithm.WithErrors) { parameter1 = minerParams.MaxErrors; } else if (minerParams.Algorithm == Algorithm.Groups) { parameter1 = minerParams.MinGroups; } else if (minerParams.Algorithm == Algorithm.Layers) { parameter1 = minerParams.MaxLayerDiff; } OPSM.DualCompare dualCompare = null; int dualSupport = -1; if (minerParams.Algorithm == Algorithm.OPSM) { dualSupport = minerParams.MinSupport; } if (minerParams.InCoreDualCompare == true) { dualCompare = new DualCompare(dataset, dualSupport); } OPSM.Miner dfsMiner = null; if (minerParams.Algorithm == Algorithm.OPSM) { dfsMiner = new DFSLookAheadMiner(dataset, dualCompare); } else if (minerParams.Algorithm == Algorithm.TreePattern) { dfsMiner = new DFSPatternMiner(dataset, dualCompare); } else if (minerParams.Algorithm == Algorithm.WithErrors) { dfsMiner = new DFSErrorMiner(dataset, dualCompare); } else if (minerParams.Algorithm == Algorithm.Groups) { dfsMiner = new DFSGroupsMiner(dataset, dualCompare); } else if (minerParams.Algorithm == Algorithm.Layers) { dfsMiner = new DFSLayerMiner(dataset, dualCompare, minerParams.DatasetFileName); } string targetDirectory = minerParams.OutputDirectory; mineResult = new MineResults( 15, targetDirectory, minerParams.WriteAllResults && minerParams.WriteOutputFiles); dfsMiner.Mine(minerParams.MinSupport, minerParams.MinLength, minerParams.MaxLength, parameter1, mineResult); if (mineResult != null) { mineResult.WriteResults(dataset); } } catch (Exception ex) { mineResult = null; MessageBox.Show("Exception during mining: " + ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } return(mineResult); }
public static MinerParams Parse(string[] args) { if (args.Length < 2) { throw new ArgumentException("Not enough parameters"); } MinerParams minerParams = new MinerParams(); foreach (string arg in args) { if (arg.StartsWith("/") == true) { bool foundParam = false; foundParam = foundParam || GetIntParam(arg, "/s=", "MinSupport", ref minerParams.MinSupport); foundParam = foundParam || GetIntParam(arg, "/minl=", "MinLength", ref minerParams.MinLength); foundParam = foundParam || GetIntParam(arg, "/maxl=", "MaxLength", ref minerParams.MaxLength); foundParam = foundParam || GetBoolParam(arg, "/ic", "InputContainsColumnHeaders", ref minerParams.InputContainsColumnHeaders); foundParam = foundParam || GetBoolParam(arg, "/ir", "InputContainsRowHeaders", ref minerParams.InputContainsRowHeaders); foundParam = foundParam || GetBoolParam(arg, "/writeAll", "WriteAllResults", ref minerParams.WriteAllResults); foundParam = foundParam || GetBoolParam(arg, "/writeOut", "WriteOutputFiles", ref minerParams.WriteOutputFiles); if (foundParam == false) { throw new ArgumentException("Unhandled Parameters: " + arg); } } else { // Check dataset file name if (minerParams.DatasetFileName != null) { throw new ArgumentException("Two dataset files defined"); } StreamReader file = null; try { file = new StreamReader(arg, System.Text.Encoding.ASCII); } catch (IOException) { throw new ArgumentException("Failed to open dataset for reading"); } finally { if (file != null) { file.Close(); } } minerParams.DatasetFileName = arg; } } if (minerParams.MinSupport == -1) { throw new ArgumentException("MinSupport not defined"); } return(minerParams); }