2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
23
package weka.associations;
25
import weka.core.Capabilities;
26
import weka.core.CapabilitiesHandler;
27
import weka.core.Instances;
28
import weka.core.RevisionHandler;
29
import weka.core.SerializedObject;
30
import weka.core.Utils;
32
import java.io.Serializable;
35
* Abstract scheme for learning associations. All schemes for learning
36
* associations implemement this class
38
* @author Eibe Frank (eibe@cs.waikato.ac.nz)
39
* @version $Revision: 1.1 $
41
public abstract class AbstractAssociator
42
implements Cloneable, Associator, Serializable, CapabilitiesHandler, RevisionHandler {
44
/** for serialization */
45
private static final long serialVersionUID = -3017644543382432070L;
48
* Creates a new instance of a associator given it's class name and
49
* (optional) arguments to pass to it's setOptions method. If the
50
* associator implements OptionHandler and the options parameter is
51
* non-null, the associator will have it's options set.
53
* @param associatorName the fully qualified class name of the associator
54
* @param options an array of options suitable for passing to setOptions. May
56
* @return the newly created associator, ready for use.
57
* @exception Exception if the associator name is invalid, or the options
58
* supplied are not acceptable to the associator
60
public static Associator forName(String associatorName,
61
String [] options) throws Exception {
63
return (Associator)Utils.forName(Associator.class,
69
* Creates a deep copy of the given associator using serialization.
71
* @param model the associator to copy
72
* @return a deep copy of the associator
73
* @exception Exception if an error occurs
75
public static Associator makeCopy(Associator model) throws Exception {
76
return (Associator) new SerializedObject(model).getObject();
80
* Creates copies of the current associator. Note that this method
81
* now uses Serialization to perform a deep copy, so the Associator
82
* object must be fully Serializable. Any currently built model will
83
* now be copied as well.
85
* @param model an example associator to copy
86
* @param num the number of associators copies to create.
87
* @return an array of associators.
88
* @exception Exception if an error occurs
90
public static Associator[] makeCopies(Associator model,
91
int num) throws Exception {
94
throw new Exception("No model associator set");
96
Associator [] associators = new Associator [num];
97
SerializedObject so = new SerializedObject(model);
98
for(int i = 0; i < associators.length; i++) {
99
associators[i] = (Associator) so.getObject();
105
* Returns the Capabilities of this associator. Derived associators have to
106
* override this method to enable capabilities.
108
* @return the capabilities of this object
111
public Capabilities getCapabilities() {
112
return new Capabilities(this);
116
* runs the associator with the given commandline options
118
* @param associator the associator to run
119
* @param options the commandline options
121
protected static void runAssociator(Associator associator, String[] options) {
124
AssociatorEvaluation.evaluate(associator, options));
126
catch (Exception e) {
127
if ( (e.getMessage() != null)
128
&& (e.getMessage().indexOf("General options") == -1) )
131
System.err.println(e.getMessage());