📄 datamining.java
字号:
/**
*
* AgentAcademy - an open source Data Mining framework for
* training intelligent agents
*
* Copyright (C) 2001-2003 AA Consortium.
*
* This library is open source software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.0 of the License, or (at your option) any later
* version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
package org.agentacademy.modules.dataminer.main;
/**
* <p>Title: The Data Miner prototype</p>
* <p>Description: A prototype for the DataMiner (DM), the Agent Academy (AA) module responsible for performing data mining on the contents of the Agent Use Repository (AUR). The extracted knowledge is to be sent back to the AUR in the form of a PMML document.</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: CERTH</p>
* @author asymeon
* @version 0.3
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Enumeration;
import java.util.Vector;
import org.agentacademy.modules.dataminer.association.Apriori;
import org.agentacademy.modules.dataminer.classifiers.J48;
import org.agentacademy.modules.dataminer.classifiers.evaluation.Evaluation;
import org.agentacademy.modules.dataminer.classifiers.flnmap.SigmaFlnmap;
import org.agentacademy.modules.dataminer.clusterers.ClusterEvaluation;
import org.agentacademy.modules.dataminer.clusterers.KMeans;
import org.agentacademy.modules.dataminer.core.Instances;
import org.agentacademy.modules.dataminer.core.Option;
import org.agentacademy.modules.dataminer.core.Utils;
import org.agentacademy.modules.dataminer.misc.InstanceQuery;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
public class DataMining {
public static void main(String args []){
try{
System.out.println();
System.out.println();
System.out.println();
System.out.println("---------***---------***------------------------------ *** ----------------------------****------**-------**------------");
System.out.println("--------*****-------*****-----------Welcome to the Agent Academy draft Data Miner------** **---**** ****------------");
System.out.println("-------** **-----** **------------------- *************** -------------------** **--** *** **------------");
System.out.println("------*********---*********------------------- ************* --------------------** **--** ** **------------");
System.out.println("----- ** **---** **-------------------- ********* ----------------------** **---** **------------");
System.out.println("---- ** **---** **--------------- Author: asymeon@CERTH -----------------*****-----** **------------");
System.out.println();
System.out.println();
System.out.println();
System.out.println(" Where do you keep your data? ");
System.out.println();
System.out.println(" 1: An arff file 2: A database 3:An XML file ");
BufferedReader inputOption = new BufferedReader(new InputStreamReader (System.in));
System.out.println();
String inputOptionString = inputOption.readLine();
/* Choose from file or database */
System.out.println();
if (inputOptionString.equalsIgnoreCase("1")){
System.out.println("Please select data mining technique:");
System.out.println("A: Decision Trees B: Clustering C: Association Rules D: HyperBoxes");
BufferedReader techniqueOption = new BufferedReader (new InputStreamReader (System.in));
String techniqueOptionString = "";
techniqueOptionString = techniqueOption.readLine();
if (techniqueOptionString.equalsIgnoreCase("A")){
System.out.println(" Please give input parameters, one at a time. When you finish type 'exit'. ");
System.out.println(" In case you do not know the type of input parameters to be used, just type 'help' in order to view available options ");
BufferedReader inputParameters = new BufferedReader(new InputStreamReader (System.in));
Vector v=new Vector();
String params="";
while (!params.equalsIgnoreCase("exit")&&!params.equalsIgnoreCase("help")){
params=inputParameters.readLine();
v.addElement(params);
}
int size=v.size();
String [] parameters=new String [size-1];
for (int i=0; i<v.size()-1; i++){
parameters[i]=(String) v.elementAt(i);
}
// To kommati gia ta decision trees
// System.out.println(Evaluation.evaluateModelPercentage(new J48(), parameters, 66));
System.out.println(Evaluation.evaluateModel(new J48(), parameters));
// Ws edw decision trees
}
else if (techniqueOptionString.equalsIgnoreCase("B")){
System.out.println(" Please give input parameters, one at a time. When you finish type 'exit'. ");
System.out.println(" In case you do not know the type of input parameters to be used, just type 'help' in order to view available options ");
BufferedReader inputParameters = new BufferedReader(new InputStreamReader (System.in));
Vector v=new Vector();
String params="";
while (!params.equalsIgnoreCase("exit")&&!params.equalsIgnoreCase("help")){
params=inputParameters.readLine();
v.addElement(params);
}
int size=v.size();
String [] parameters=new String [size-1];
for (int i=0; i<v.size()-1; i++){
parameters[i]=(String) v.elementAt(i);
}
// To kommati gia to Clustering
System.out.println(ClusterEvaluation.evaluateClusterer(new KMeans (),parameters));
// Ws edw gia Clustering
}
else if (techniqueOptionString.equalsIgnoreCase("C")){
System.out.println(" Please give input parameters, one at a time. When you finish type 'exit'. ");
System.out.println(" In case you do not know the type of input parameters to be used, just type 'help' in order to view available options ");
BufferedReader inputParameters = new BufferedReader(new InputStreamReader (System.in));
Vector v=new Vector();
String params="";
String trainFileString = "";
while (!params.equalsIgnoreCase("exit")&&!params.equalsIgnoreCase("help")){
params=inputParameters.readLine();
v.addElement(params);
}
int size=v.size();
String [] parameters=new String [size-1];
for (int i=0; i<v.size()-1; i++){
parameters[i]=(String) v.elementAt(i);
}
if (v.elementAt(0).equals("-t")){
trainFileString = (String) v.elementAt(1);
}
else {
System.out.println("OpenFileException e: Cannot Open Train File name");
}
// To kommati gia ta Association Rules
StringBuffer text = new StringBuffer();
Apriori apriori = new Apriori();
Reader reader;
apriori.setOptions(parameters);
reader = new BufferedReader(new FileReader(trainFileString));
apriori.buildAssociations(new Instances(reader));
System.out.println(apriori);
//Ws edw association rules....
}
else if (techniqueOptionString.equalsIgnoreCase("D")){
System.out.println(" Please give input parameters, one at a time. When you finish type 'exit'. ");
System.out.println(" In case you do not know the type of input parameters to be used, just type 'help' in order to view available options ");
BufferedReader inputParameters = new BufferedReader(new InputStreamReader (System.in));
Vector v=new Vector();
String params="";
while (!params.equalsIgnoreCase("exit")&&!params.equalsIgnoreCase("help")){
params=inputParameters.readLine();
v.addElement(params);
}
int size=v.size();
String [] parameters=new String [size-1];
for (int i=0; i<v.size()-1; i++){
parameters[i]=(String) v.elementAt(i);
}
// To kommati gia ta HyperBoxes
System.out.println(Evaluation.evaluateModel(new SigmaFlnmap (),parameters));
}
else {
System.out.println("Unknown option :Please reload the program and try again");
System.exit(1);
}
}
else if (inputOptionString.equalsIgnoreCase("2")){
InstanceQuery iq=new InstanceQuery();
String query = Utils.getOption('Q', args);
System.out.println(query);
if (query.length() == 0) {
System.out.println("Please insert the SQL query in order to define selected attributes");
BufferedReader inputQuery = new BufferedReader(new InputStreamReader (System.in));
String inputQueryString =inputQuery.readLine();
iq.setQuery(inputQueryString);
}
else {
iq.setQuery(query);
}
iq.setOptions(args);
try {
Utils.checkForRemainingOptions(args);
}
catch (Exception e) {
System.err.println("Options for DataMiner.InstanceQuery:\n");
Enumeration en = iq.listOptions();
while (en.hasMoreElements()) {
Option o = (Option)en.nextElement();
System.err.println(o.synopsis()+"\n"+o.description());
}
System.exit(1);
}
Instances aha = iq.retrieveInstances();
System.out.println();
iq.disconnectFromDatabase();
System.out.println();
System.out.println("Please select data mining technique:");
System.out.println("A: Decision Trees B: Clustering C: Association Rules D: HyperBoxes");
BufferedReader techniqueOption = new BufferedReader (new InputStreamReader (System.in));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -