📄 runexamples.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Michael Thess
* @version 1.0
*/
package com.prudsys.pdm.Examples;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
/**
* Runs a specified set of examples and outputs some test statistics. All
* examples must inherit from BasisExample.
*
* Should be used to test the examples of the Examples package.
*/
public class RunExamples {
/** List containing the class paths of all test examples. */
private ArrayList examples = new ArrayList();
/** Number of tests that have been executed successfully. */
private int numberOfSuccessTests = 0;
/**
* Empty constructor.
*/
public RunExamples() {
// Define test of default examples:
examples.add("com.prudsys.pdm.Examples.AssociationRulesBuild");
examples.add("com.prudsys.pdm.Examples.AssociationRulesApply");
examples.add("com.prudsys.pdm.Examples.AssociationRulesDecompBuild");
examples.add("com.prudsys.pdm.Examples.AssociationRulesOlapBuild");
examples.add("com.prudsys.pdm.Examples.AssociationRulesServiceAPIBuild");
examples.add("com.prudsys.pdm.Examples.AssociationRulesTaxonomyBuild");
examples.add("com.prudsys.pdm.Examples.ClusteringBuild");
examples.add("com.prudsys.pdm.Examples.ClusteringApply");
examples.add("com.prudsys.pdm.Examples.ClusteringLocalServiceAPIBuild");
examples.add("com.prudsys.pdm.Examples.ClusteringHierarchicalBuild");
examples.add("com.prudsys.pdm.Examples.ClusteringPartitioningBuild");
examples.add("com.prudsys.pdm.Examples.CustomerSequentialBuild");
examples.add("com.prudsys.pdm.Examples.CustomerSequentialApply");
examples.add("com.prudsys.pdm.Examples.CustomerSequentialDecompBuild");
examples.add("com.prudsys.pdm.Examples.CustomerSequentialLocalServiceAPIBuild");
examples.add("com.prudsys.pdm.Examples.CwmExample");
examples.add("com.prudsys.pdm.Examples.DecisionTreeBuild");
examples.add("com.prudsys.pdm.Examples.DecisionTreeApply");
examples.add("com.prudsys.pdm.Examples.DecisionTreeServiceAPIBuild");
examples.add("com.prudsys.pdm.Examples.DecisionTreeForwardPruningBuild");
examples.add("com.prudsys.pdm.Examples.DecisionTreeBackwardPruningBuild");
examples.add("com.prudsys.pdm.Examples.FlatRulesBuild");
examples.add("com.prudsys.pdm.Examples.FlatRulesDecompBuild");
examples.add("com.prudsys.pdm.Examples.FlatRulesSelectionBuild");
examples.add("com.prudsys.pdm.Examples.NeuralNetworkBuild");
examples.add("com.prudsys.pdm.Examples.NeuralNetworkApply");
examples.add("com.prudsys.pdm.Examples.NonlinearDecisionTreeApply");
examples.add("com.prudsys.pdm.Examples.ITICollaborativeFilteringBuild");
examples.add("com.prudsys.pdm.Examples.ITICollaborativeFilteringDecompBuild");
examples.add("com.prudsys.pdm.Examples.OlapExample");
examples.add("com.prudsys.pdm.Examples.SequentialBuild");
examples.add("com.prudsys.pdm.Examples.SequentialApply");
examples.add("com.prudsys.pdm.Examples.SequentialDecompBuild");
examples.add("com.prudsys.pdm.Examples.StatisticsBuild");
examples.add("com.prudsys.pdm.Examples.SupportVectorMachineBuild");
examples.add("com.prudsys.pdm.Examples.SupportVectorMachineApply");
examples.add("com.prudsys.pdm.Examples.SupportVectorMachineBuildApply");
examples.add("com.prudsys.pdm.Examples.TimeSeriesPredictBuildApply");
examples.add("com.prudsys.pdm.Examples.Transformation");
examples.add("com.prudsys.pdm.Examples.TransformationBuild");
examples.add("com.prudsys.pdm.Examples.TransformationApply");
examples.add("com.prudsys.pdm.Examples.WekaClassificationBuildApply");
examples.add("com.prudsys.pdm.Examples.WekaClusteringBuildApply");
}
/**
* Get list of classpaths of all examples.
*
* @return list of all examples
*/
public ArrayList getExamples() {
return examples;
}
/**
* Set list of classpaths of all examples.
*
* @param examples new list of classpaths
*/
public void setExamples(ArrayList examples) {
this.examples = examples;
}
/**
* Add classpath of new example to list.
*
* @param example example to add
*/
public void addExample(String example) {
examples.add(example);
}
/**
* Remove classpath of example.
*
* @param example example to be removed
* @return true if the list contained the specified element, else false
*/
public boolean removeExample(String example) {
return examples.remove(example);
}
/**
* Returns number of examples that have passed the test successfully.
*
* @return number of successful tests
*/
public int getNumberOfSuccessTests() {
return numberOfSuccessTests;
}
/**
* Runs all examples.
*
* @throws Exception error while execution
*/
public void runExamples() throws Exception {
// Run tests:
int numberOfExamples = examples.size();
numberOfSuccessTests = 0;
long start = ( new Date() ).getTime();
for (int i = 0; i < numberOfExamples; i++) {
try {
String example = (String) examples.get(i);
System.out.println("Loading and running: " + example);
Class exClass = Class.forName(example);
Constructor exConst = exClass.getConstructor(null);
Object exObject = exConst.newInstance(null);
Method classMethod = exClass.getMethod("runExample", null);
classMethod.invoke(exObject, null);
numberOfSuccessTests++;
}
catch (Exception ex) {
}
}
long end = ( new Date() ).getTime();
double totalTime = ( end - start ) / 1000.0;
// Output test statistics:
System.out.println();
System.out.println("******************************************************");
System.out.println("Test statistics:");
System.out.println("#tests : " + numberOfExamples);
System.out.println("#tests passed: " + numberOfSuccessTests);
System.out.println("#tests failed: " + (numberOfExamples-numberOfSuccessTests) );
System.out.println("total time[s]: " + totalTime);
System.out.println("aver. time[s]: " + ((float)totalTime/numberOfExamples) );
System.out.println("******************************************************");
}
/**
* Tests a specified set of examples.
*
* @param args arguments (ignored)
*/
public static void main(String[] args) {
try {
new RunExamples().runExamples();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -