⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 artoolbox.java

📁 数据挖掘中
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
       "Records starting with a comment character are\n"      +"ignored/skipped when the data file is read.");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    help = new JTextArea((String)null);    help.setFont(small);    help.setBackground(this.getBackground());    rc.weighty = 1.0;    g.setConstraints(help, rc); grid.add(help);    rc.weighty = 0.0;    /* --- options --- */    grid = new JPanel(g);    grid.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    tab.addTab("Options", null, grid, null);    lbl = new JLabel("Item sorting:");    g.setConstraints(lbl, rc);       grid.add(lbl);    sort = new JComboBox(sortnames); sort.setSelectedIndex(3);    g.setConstraints(sort, rc);      grid.add(sort);    lbl = new JLabel("Load transactions:");    g.setConstraints(lbl, lc);       grid.add(lbl);    load = new JCheckBox("", true);    g.setConstraints(load, rc);      grid.add(load);    lbl = new JLabel("Transactions as prefix tree:");    g.setConstraints(lbl, lc);       grid.add(lbl);    prefix = new JCheckBox("", true);    g.setConstraints(prefix, rc);    grid.add(prefix);    lbl = new JLabel("Quicksort instead of heapsort:");    g.setConstraints(lbl, lc);       grid.add(lbl);    quick = new JCheckBox("", false);    g.setConstraints(quick, rc);     grid.add(quick);    lbl = new JLabel("Minimize memory usage:");    g.setConstraints(lbl, lc);       grid.add(lbl);    memory = new JCheckBox("", false);    g.setConstraints(memory, rc);    grid.add(memory);    help = new JTextArea(       "Changing any of the above options\n"      +"usually increases the execution time.");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    lbl = new JLabel("Number output format:");    g.setConstraints(lbl, lc);       grid.add(lbl);    outfmt = new JTextField("");     outfmt.setFont(font);    g.setConstraints(outfmt, rc);    grid.add(outfmt);    help = new JTextArea(       "The number format has to be specified according to\n"      +"the rules for the C function \"printf\" (print formatted).\n"      +"Default: \"%1.f%%\" (percentage, one decimal place).");    help.setFont(small);    help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    help = new JTextArea((String)null);    help.setFont(small); help.setBackground(this.getBackground());    help.setPreferredSize(new Dimension(0,0));    rc.weighty = 1.0;    g.setConstraints(help, rc); grid.add(help);    rc.weighty = 0.0;    /* --- about --- */    grid = new JPanel(g);    grid.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    tab.addTab("About", null, grid, null);    help = new JTextArea(       "Association Rule Induction Toolbox");    help.setFont(font); help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    help = new JTextArea(       "A simple user interface for the apriori program.\n\n"      +"Version 1.1, 2005.01.25\n"      +"written by Christian Borgelt\n"      +"Otto-von-Guericke-University of Magdeburg\n"      +"Universitatsplatz 2, D-39106 Magdeburg\n"      +"e-mail: borgelt@iws.cs.uni-magdeburg.de\n\n"      +"This program is free software;\n"      +"you can redistribute it and/or modify it under\n"      +"the terms of the GNU Lesser General Public License\n"      +"as published by the Free Software Foundation.\n\n"      +"This program is distributed in the hope that\n"      +"it will be useful, but WITHOUT ANY WARRANTY;\n"      +"without even the implied warranty of MERCHANTABILITY\n"      +"or FITNESS FOR A PARTICULAR PURPOSE. See the\n"      +"GNU Lesser General Public License for more details.");    help.setFont(small); help.setBackground(this.getBackground());    g.setConstraints(help, rc); grid.add(help);    /* --- buttons --- */    lc.weightx = rc.weightx = 0.5;    bbar = new JPanel(new GridLayout(1, 2, 5, 5));    bbar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));    exec = new JButton("Execute");    g.setConstraints(exec, lc); bbar.add(exec);    exec.addActionListener(new AbstractAction () {      public void actionPerformed (ActionEvent e) {        start(tab.getSelectedIndex()); } } );    btn = new JButton("Close");    g.setConstraints(btn, rc); bbar.add(btn);    if (isProg) {               /* terminate the program */      btn.addActionListener(new AbstractAction () {        public void actionPerformed (ActionEvent e) {          System.exit(0); } } );}    else {                      /* only close the dialog box */      btn.addActionListener(new AbstractAction () {        public void actionPerformed (ActionEvent e) {          ARToolbox.this.setVisible(false); } } );    }    grid = new JPanel(new BorderLayout());    grid.add(bbar, BorderLayout.NORTH);    stat = new JTextField("association rule induction tools");    stat.setEditable(false);    grid.add(stat, BorderLayout.SOUTH);    this.getContentPane().add(tab,  BorderLayout.NORTH);    this.getContentPane().add(grid, BorderLayout.SOUTH);    this.setTitle("Association Rule Induction Toolbox");    this.setDefaultCloseOperation(isProg      ? JFrame.EXIT_ON_CLOSE : JFrame.HIDE_ON_CLOSE);    if (owner != null) this.setLocationRelativeTo(owner);    this.setLocation(50, 50);    this.pack();  }  /* ARToolbox() */  /*------------------------------------------------------------------*/  public ARToolbox (Component owner) { this(owner, false); }  /*------------------------------------------------------------------*/  public void setPath (String path) { this.path = path; }  /*------------------------------------------------------------------*/  private void showCmd (String[] cmd)  {                             /* --- show command to be executed */    for (int i = 0; i < cmd.length; i++)      if (cmd[i] != null) System.err.print(cmd[i] +" ");    System.err.println();       /* print the command line */  }  /* showCmd() */  /*------------------------------------------------------------------*/  private void start (int index)  {                             /* --- start the apriori program */    int      i;                 /* argument index */    String[] cmd;               /* command and arguments */    String   com, app;          /* comment chars, appearences file */    String   fmt, s;            /* number format, buffer */    int      add;               /* additional evaluation measure */    if (running) {              /* if a thread is running, */      running = false;          /* stop the thread and */      while (!stopped) {        /* wait for termination */        try { Thread.currentThread().sleep(100); }        catch (InterruptedException ex) { }      }      JOptionPane.showMessageDialog(this, "Current task aborted");      stat.setText("Aborted."); /* report successful abortion, */      exec.setText("Execute");  /* set status line and button text, */      return;                   /* and abort the function */    }                             i   = 12;                   /* get and check optional arguments */    com = comment.getText();       if (!com.equals("")) i++;    add = arem.getSelectedIndex(); if (add > 0)         i++;    app = f_app.getText();         if (!app.equals("")) i++;    fmt = outfmt.getText();        if (!fmt.equals("")) i++;    cmd = new String[i];        /* build the command to be executed */    cmd[0] = ((path != null) ? path +"/" : "") +"apriori";    cmd[1] = "-r" +recseps.getText();    cmd[2] = "-f" +fldseps.getText();    cmd[3] = "-b" +blanks.getText();    cmd[4] = "-m" +mincnt.getText();    cmd[5] = "-n" +maxcnt.getText();    cmd[6] = "-"  +(orig.isSelected() ? "o" : "")           +  "s" +minsupp.getText();    cmd[7] = "-S" +maxsupp.getText();    cmd[8] = "-c" +minconf.getText(); i = 9;    if (add > 0) { s = minarem.getText();      cmd[i++] = "-e" +add +(!s.equals("") ? "-d" +s : ""); }    if (!com.equals("")) cmd[i++] = "-i" +com;    if (!fmt.equals("")) cmd[i++] = "-p" +fmt;    cmd[i++] = "-" +(load.isSelected()   ? ""  : "l")                   +(prefix.isSelected() ? ""  : "h")                   +(quick.isSelected()  ? "j" : "")                   +(memory.isSelected() ? "z" : "")           +  "gavyq" +sort.getSelectedIndex();    cmd[i++] = f_tra.getText();    cmd[i++] = f_rul.getText();    if (!app.equals("")) cmd[i] = app;    // showCmd(cmd);               /* debug: show the command */    try { process = Runtime.getRuntime().exec(cmd); }    catch (IOException ex) {    /* start the process */      JOptionPane.showMessageDialog(this,        "Cannot start the apriori program.",        "Error", JOptionPane.ERROR_MESSAGE); return;    }    stat.setText("Running... ");    exec.setText("Abort");      /* set status line and button text */    running = true;             /* set the flag for a running thread */    new Thread(this).start();   /* create a new thread */  }  /* start() */  /*------------------------------------------------------------------*/  public void run ()  {                             /* --- execution function */    int               e = 0;    /* exit code of the process */    int               c = 0;    /* character for stream reading */    InputStreamReader isr, esr; /* to read the process streams */    StringBuffer      buf;      /* string buffer for error stream */    String            msg, t;   /* error message on failure */    buf = new StringBuffer(""); /* create stream readers */    isr = new InputStreamReader(process.getInputStream());    esr = new InputStreamReader(process.getErrorStream());    while (running) {           /* while not finished and not aborted */      try {                     /* wait for some time (0.1 sec) */        Thread.currentThread().sleep(100);        if (process != null) e = process.exitValue();        running = false; }      /* check for termination */      catch (InterruptedException ex) { break; }      catch (IllegalThreadStateException ex) {        if (!running) process.destroy(); }      try {                     /* copy the streams of the process */        while (isr.ready()) System.out.print((char)isr.read());        while (esr.ready()) {          if ((c == '\n') || (c == ':')) buf.setLength(0);          System.err.print((char)(c = esr.read()));          if ((c != '\n') && ((buf.length() > 0) || (c != ' ')))            buf.append((char)c);/* copy error stream to output */        } }                     /* and note last line in buffer */      catch (IOException ex) { }    }    process = null;             /* delete the process */    if (e != 0) {               /* check for failure */      if (buf.length() > 0) buf.append('\n');      msg = "Process failed with exit code " +e +":\n"          + buf.toString() +"(see terminal window for details)"; }    else {                      /* if domains or tree generation */      c = buf.length();         /* trim message to relevant part */      while (buf.charAt(--c) != ']');      while (buf.charAt(--c) != ']');      while (buf.charAt(--c) != ' '); buf.setLength(c);      while (buf.charAt(--c) != '['); buf.delete(0, c+1);      msg = "Found " +buf.toString() +" association rule(s).";    }                           /* generate the message */    if (e == 0) JOptionPane.showMessageDialog(this, msg);    else        JOptionPane.showMessageDialog(this, msg,                  "Error", JOptionPane.ERROR_MESSAGE);    stat.setText("Finished.");  /* set status line */    exec.setText("Execute");    /* and button text */    stopped = true;             /* signal termination */  }  /* run() */  /*------------------------------------------------------------------*/  public static void main (String args[])  {                             /* --- main function */    ARToolbox tb = new ARToolbox(null, true);    tb.setVisible(true);        /* create a toolbox dialog */  }  /* main() */}  /* class ATToolbox */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -