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) 2002 University of Waikato, Hamilton, New Zealand
23
package weka.gui.beans;
25
import weka.classifiers.rules.ZeroR;
26
import weka.core.Instances;
27
import weka.gui.Logger;
29
import java.awt.BorderLayout;
30
import java.beans.EventSetDescriptor;
31
import java.io.Serializable;
32
import java.util.Enumeration;
33
import java.util.Hashtable;
34
import java.util.Vector;
36
import javax.swing.JPanel;
39
* Bean that wraps around weka.classifiers
41
* @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
42
* @version $Revision: 1.25 $
49
* @see UserRequestAcceptor
50
* @see TrainingSetListener
51
* @see TestSetListener
53
public class Classifier
55
implements BeanCommon, Visible,
56
WekaWrapper, EventConstraints,
57
Serializable, UserRequestAcceptor,
58
TrainingSetListener, TestSetListener,
61
/** for serialization */
62
private static final long serialVersionUID = 659603893917736008L;
64
protected BeanVisual m_visual =
65
new BeanVisual("Classifier",
66
BeanVisual.ICON_PATH+"DefaultClassifier.gif",
67
BeanVisual.ICON_PATH+"DefaultClassifier_animated.gif");
69
private static int IDLE = 0;
70
private static int BUILDING_MODEL = 1;
71
private static int CLASSIFYING = 2;
73
private int m_state = IDLE;
75
private Thread m_buildThread = null;
78
* Global info for the wrapped classifier (if it exists).
80
protected String m_globalInfo;
83
* Objects talking to us
85
private Hashtable m_listenees = new Hashtable();
88
* Objects listening for batch classifier events
90
private Vector m_batchClassifierListeners = new Vector();
93
* Objects listening for incremental classifier events
95
private Vector m_incrementalClassifierListeners = new Vector();
98
* Objects listening for graph events
100
private Vector m_graphListeners = new Vector();
103
* Objects listening for text events
105
private Vector m_textListeners = new Vector();
108
* Holds training instances for batch training. Not transient because
109
* header is retained for validating any instance events that this
110
* classifier might be asked to predict in the future.
112
private Instances m_trainingSet;
113
private transient Instances m_testingSet;
114
private weka.classifiers.Classifier m_Classifier = new ZeroR();
115
private IncrementalClassifierEvent m_ie =
116
new IncrementalClassifierEvent(this);
119
* If the classifier is an incremental classifier, should we
120
* update it (ie train it on incoming instances). This makes it
121
* possible incrementally test on a separate stream of instances
122
* without updating the classifier, or mix batch training/testing
123
* with incremental training/testing
125
private boolean m_updateIncrementalClassifier = true;
127
private transient Logger m_log = null;
130
* Event to handle when processing incremental updates
132
private InstanceEvent m_incrementalEvent;
133
private Double m_dummy = new Double(0.0);
136
* Global info (if it exists) for the wrapped classifier
138
* @return the global info
140
public String globalInfo() {
145
* Creates a new <code>Classifier</code> instance.
147
public Classifier() {
148
setLayout(new BorderLayout());
149
add(m_visual, BorderLayout.CENTER);
150
setClassifier(m_Classifier);
154
* Set the classifier for this wrapper
156
* @param c a <code>weka.classifiers.Classifier</code> value
158
public void setClassifier(weka.classifiers.Classifier c) {
159
boolean loadImages = true;
160
if (c.getClass().getName().
161
compareTo(m_Classifier.getClass().getName()) == 0) {
164
// classifier has changed so any batch training status is now
166
m_trainingSet = null;
169
String classifierName = c.getClass().toString();
170
classifierName = classifierName.substring(classifierName.
172
classifierName.length());
174
if (!m_visual.loadIcons(BeanVisual.ICON_PATH+classifierName+".gif",
175
BeanVisual.ICON_PATH+classifierName+"_animated.gif")) {
179
m_visual.setText(classifierName);
181
if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier) &&
182
(m_listenees.containsKey("instance"))) {
184
m_log.logMessage("WARNING : "+m_Classifier.getClass().getName()
185
+" is not an incremental classifier (Classifier)");
189
m_globalInfo = KnowledgeFlowApp.getGlobalInfo(m_Classifier);
193
* Returns true if this classifier has an incoming connection that is
196
* @return true if has an incoming connection that is an instance stream
198
public boolean hasIncomingStreamInstances() {
199
if (m_listenees.size() == 0) {
202
if (m_listenees.containsKey("instance")) {
209
* Returns true if this classifier has an incoming connection that is
210
* a batch set of instances
212
* @return a <code>boolean</code> value
214
public boolean hasIncomingBatchInstances() {
215
if (m_listenees.size() == 0) {
218
if (m_listenees.containsKey("trainingSet") ||
219
m_listenees.containsKey("testSet")) {
226
* Get the classifier currently set for this wrapper
228
* @return a <code>weka.classifiers.Classifier</code> value
230
public weka.classifiers.Classifier getClassifier() {
235
* Sets the algorithm (classifier) for this bean
237
* @param algorithm an <code>Object</code> value
238
* @exception IllegalArgumentException if an error occurs
240
public void setWrappedAlgorithm(Object algorithm)
243
if (!(algorithm instanceof weka.classifiers.Classifier)) {
244
throw new IllegalArgumentException(algorithm.getClass()+" : incorrect "
245
+"type of algorithm (Classifier)");
247
setClassifier((weka.classifiers.Classifier)algorithm);
251
* Returns the wrapped classifier
253
* @return an <code>Object</code> value
255
public Object getWrappedAlgorithm() {
256
return getClassifier();
259
public boolean getUpdateIncrementalClassifier() {
260
return m_updateIncrementalClassifier;
263
public void setUpdateIncrementalClassifier(boolean update) {
264
m_updateIncrementalClassifier = update;
267
// public void acceptDataSet(DataSetEvent e) {
268
// // will wrap up data in a TrainingSetEvent and call acceptTrainingSet
269
// // then will do same for TestSetEvent
270
// acceptTrainingSet(new TrainingSetEvent(e.getSource(), e.getDataSet()));
274
* Accepts an instance for incremental processing.
276
* @param e an <code>InstanceEvent</code> value
278
public void acceptInstance(InstanceEvent e) {
279
/* if (m_buildThread == null) {
280
System.err.println("Starting handler ");
281
startIncrementalHandler();
283
// if (m_Classifier instanceof weka.classifiers.UpdateableClassifier) {
284
/* synchronized(m_dummy) {
285
m_state = BUILDING_MODEL;
286
m_incrementalEvent = e;
290
// if (m_state == BUILDING_MODEL && m_buildThread != null) {
293
} catch (Exception ex) {
296
m_incrementalEvent = e;
297
handleIncrementalEvent();
302
* Handles initializing and updating an incremental classifier
304
private void handleIncrementalEvent() {
305
if (m_buildThread != null) {
306
String messg = "Classifier is currently batch training!";
308
m_log.logMessage(messg);
310
System.err.println(messg);
315
if (m_incrementalEvent.getStatus() == InstanceEvent.FORMAT_AVAILABLE) {
316
// Instances dataset = m_incrementalEvent.getInstance().dataset();
317
Instances dataset = m_incrementalEvent.getStructure();
318
// default to the last column if no class is set
319
if (dataset.classIndex() < 0) {
320
// System.err.println("Classifier : setting class index...");
321
dataset.setClassIndex(dataset.numAttributes()-1);
324
// initialize classifier if m_trainingSet is null
325
// otherwise assume that classifier has been pre-trained in batch
326
// mode, *if* headers match
327
if (m_trainingSet == null || (!dataset.equalHeaders(m_trainingSet))) {
328
if (!(m_Classifier instanceof
329
weka.classifiers.UpdateableClassifier)) {
331
String msg = (m_trainingSet == null)
332
? "ERROR : "+m_Classifier.getClass().getName()
333
+" has not been batch "
334
+"trained; can't process instance events."
335
: "ERROR : instance event's structure is different from "
337
+ "was used to batch train this classifier; can't continue.";
338
m_log.logMessage(msg);
342
if (m_trainingSet != null &&
343
(!dataset.equalHeaders(m_trainingSet))) {
345
m_log.logMessage("Warning : structure of instance events differ "
346
+"from data used in batch training this "
347
+"classifier. Resetting classifier...");
349
m_trainingSet = null;
351
if (m_trainingSet == null) {
352
// initialize the classifier if it hasn't been trained yet
353
m_trainingSet = new Instances(dataset, 0);
354
m_Classifier.buildClassifier(m_trainingSet);
357
} catch (Exception ex) {
358
ex.printStackTrace();
360
// Notify incremental classifier listeners of new batch
361
System.err.println("NOTIFYING NEW BATCH");
362
m_ie.setStructure(dataset);
363
m_ie.setClassifier(m_Classifier);
365
notifyIncrementalClassifierListeners(m_ie);
368
if (m_trainingSet == null) {
369
// simply return. If the training set is still null after
370
// the first instance then the classifier must not be updateable
371
// and hasn't been previously batch trained - therefore we can't
372
// do anything meaningful
378
// test on this instance
379
int status = IncrementalClassifierEvent.WITHIN_BATCH;
380
/* if (m_incrementalEvent.getStatus() == InstanceEvent.FORMAT_AVAILABLE) {
381
status = IncrementalClassifierEvent.NEW_BATCH; */
382
/* } else */ if (m_incrementalEvent.getStatus() ==
383
InstanceEvent.BATCH_FINISHED) {
384
status = IncrementalClassifierEvent.BATCH_FINISHED;
387
m_ie.setStatus(status); m_ie.setClassifier(m_Classifier);
388
m_ie.setCurrentInstance(m_incrementalEvent.getInstance());
390
notifyIncrementalClassifierListeners(m_ie);
392
// now update on this instance (if class is not missing and classifier
393
// is updateable and user has specified that classifier is to be
395
if (m_Classifier instanceof weka.classifiers.UpdateableClassifier &&
396
m_updateIncrementalClassifier == true &&
397
!(m_incrementalEvent.getInstance().
398
isMissing(m_incrementalEvent.getInstance().
399
dataset().classIndex()))) {
400
((weka.classifiers.UpdateableClassifier)m_Classifier).
401
updateClassifier(m_incrementalEvent.getInstance());
403
if (m_incrementalEvent.getStatus() ==
404
InstanceEvent.BATCH_FINISHED) {
405
if (m_textListeners.size() > 0) {
406
String modelString = m_Classifier.toString();
407
String titleString = m_Classifier.getClass().getName();
409
titleString = titleString.
410
substring(titleString.lastIndexOf('.') + 1,
411
titleString.length());
412
modelString = "=== Classifier model ===\n\n" +
413
"Scheme: " +titleString+"\n" +
414
"Relation: " + m_trainingSet.relationName() + "\n\n"
416
titleString = "Model: " + titleString;
417
TextEvent nt = new TextEvent(this,
420
notifyTextListeners(nt);
423
} catch (Exception ex) {
425
m_log.logMessage(ex.toString());
427
ex.printStackTrace();
434
private void startIncrementalHandler() {
435
if (m_buildThread == null) {
436
m_buildThread = new Thread() {
439
synchronized(m_dummy) {
442
} catch (InterruptedException ex) {
443
// m_buildThread = null;
444
// System.err.println("Here");
448
Classifier.this.handleIncrementalEvent();
454
m_buildThread.setPriority(Thread.MIN_PRIORITY);
455
m_buildThread.start();
456
// give thread a chance to start
459
} catch (InterruptedException ex) {
465
* Accepts a training set and builds batch classifier
467
* @param e a <code>TrainingSetEvent</code> value
469
public void acceptTrainingSet(final TrainingSetEvent e) {
470
if (e.isStructureOnly()) {
471
// no need to build a classifier, instead just generate a dummy
472
// BatchClassifierEvent in order to pass on instance structure to
473
// any listeners - eg. PredictionAppender can use it to determine
474
// the final structure of instances with predictions appended
475
BatchClassifierEvent ce =
476
new BatchClassifierEvent(this, m_Classifier,
477
new DataSetEvent(this, e.getTrainingSet()),
478
new DataSetEvent(this, e.getTrainingSet()),
479
e.getSetNumber(), e.getMaxSetNumber());
481
notifyBatchClassifierListeners(ce);
484
if (m_buildThread == null) {
486
if (m_state == IDLE) {
487
synchronized (this) {
488
m_state = BUILDING_MODEL;
490
m_trainingSet = e.getTrainingSet();
491
final String oldText = m_visual.getText();
492
m_buildThread = new Thread() {
495
if (m_trainingSet != null) {
496
if (m_trainingSet.classIndex() < 0) {
497
// assume last column is the class
498
m_trainingSet.setClassIndex(m_trainingSet.numAttributes()-1);
500
m_log.logMessage("Classifier : assuming last "
501
+"column is the class");
504
m_visual.setAnimated();
505
m_visual.setText("Building model...");
507
m_log.statusMessage("Classifier : building model...");
511
if (m_Classifier instanceof weka.core.Drawable &&
512
m_graphListeners.size() > 0) {
514
((weka.core.Drawable)m_Classifier).graph();
515
int grphType = ((weka.core.Drawable)m_Classifier).graphType();
516
String grphTitle = m_Classifier.getClass().getName();
517
grphTitle = grphTitle.substring(grphTitle.
520
grphTitle = "Set " + e.getSetNumber() + " ("
521
+e.getTrainingSet().relationName() + ") "
524
GraphEvent ge = new GraphEvent(Classifier.this,
528
notifyGraphListeners(ge);
531
if (m_textListeners.size() > 0) {
532
String modelString = m_Classifier.toString();
533
String titleString = m_Classifier.getClass().getName();
535
titleString = titleString.
536
substring(titleString.lastIndexOf('.') + 1,
537
titleString.length());
538
modelString = "=== Classifier model ===\n\n" +
539
"Scheme: " +titleString+"\n" +
540
"Relation: " + m_trainingSet.relationName() +
541
((e.getMaxSetNumber() > 1)
542
? "\nTraining Fold: "+e.getSetNumber()
546
titleString = "Model: " + titleString;
548
TextEvent nt = new TextEvent(Classifier.this,
551
notifyTextListeners(nt);
554
} catch (Exception ex) {
555
ex.printStackTrace();
557
m_visual.setText(oldText);
558
m_visual.setStatic();
560
if (isInterrupted()) {
561
// prevent any classifier events from being fired
562
m_trainingSet = null;
564
m_log.logMessage("Build classifier interrupted!");
565
m_log.statusMessage("OK");
569
//m_trainingSet = new Instances(m_trainingSet, 0);
572
m_log.statusMessage("OK");
578
m_buildThread.setPriority(Thread.MIN_PRIORITY);
579
m_buildThread.start();
580
// make sure the thread is still running before we block
581
// if (m_buildThread.isAlive()) {
584
m_buildThread = null;
587
} catch (Exception ex) {
588
ex.printStackTrace();
594
* Accepts a test set for a batch trained classifier
596
* @param e a <code>TestSetEvent</code> value
598
public void acceptTestSet(TestSetEvent e) {
600
if (m_trainingSet != null) {
602
if (m_state == IDLE) {
604
m_state = CLASSIFYING;
607
m_testingSet = e.getTestSet();
608
if (m_testingSet != null) {
609
if (m_testingSet.classIndex() < 0) {
610
m_testingSet.setClassIndex(m_testingSet.numAttributes()-1);
613
if (m_trainingSet.equalHeaders(m_testingSet)) {
615
BatchClassifierEvent ce =
616
new BatchClassifierEvent(this, m_Classifier,
617
new DataSetEvent(this, m_trainingSet),
618
new DataSetEvent(this, e.getTestSet()),
619
e.getSetNumber(), e.getMaxSetNumber());
621
// System.err.println("Just before notify classifier listeners");
622
notifyBatchClassifierListeners(ce);
623
// System.err.println("Just after notify classifier listeners");
627
} catch (Exception ex) {
628
ex.printStackTrace();
634
private void buildClassifier() throws Exception {
635
m_Classifier.buildClassifier(m_trainingSet);
639
* Sets the visual appearance of this wrapper bean
641
* @param newVisual a <code>BeanVisual</code> value
643
public void setVisual(BeanVisual newVisual) {
644
m_visual = newVisual;
648
* Gets the visual appearance of this wrapper bean
650
public BeanVisual getVisual() {
655
* Use the default visual appearance for this bean
657
public void useDefaultVisual() {
658
// try to get a default for this package of classifiers
659
String name = m_Classifier.getClass().toString();
660
String packageName = name.substring(0, name.lastIndexOf('.'));
662
packageName.substring(packageName.lastIndexOf('.')+1,
663
packageName.length());
664
if (!m_visual.loadIcons(BeanVisual.ICON_PATH+"Default_"+packageName
666
BeanVisual.ICON_PATH+"Default_"+packageName
667
+"Classifier_animated.gif")) {
668
m_visual.loadIcons(BeanVisual.
669
ICON_PATH+"DefaultClassifier.gif",
671
ICON_PATH+"DefaultClassifier_animated.gif");
676
* Add a batch classifier listener
678
* @param cl a <code>BatchClassifierListener</code> value
680
public synchronized void
681
addBatchClassifierListener(BatchClassifierListener cl) {
682
m_batchClassifierListeners.addElement(cl);
686
* Remove a batch classifier listener
688
* @param cl a <code>BatchClassifierListener</code> value
690
public synchronized void
691
removeBatchClassifierListener(BatchClassifierListener cl) {
692
m_batchClassifierListeners.remove(cl);
696
* Notify all batch classifier listeners of a batch classifier event
698
* @param ce a <code>BatchClassifierEvent</code> value
700
private void notifyBatchClassifierListeners(BatchClassifierEvent ce) {
702
synchronized (this) {
703
l = (Vector)m_batchClassifierListeners.clone();
706
for(int i = 0; i < l.size(); i++) {
707
((BatchClassifierListener)l.elementAt(i)).acceptClassifier(ce);
713
* Add a graph listener
715
* @param cl a <code>GraphListener</code> value
717
public synchronized void addGraphListener(GraphListener cl) {
718
m_graphListeners.addElement(cl);
722
* Remove a graph listener
724
* @param cl a <code>GraphListener</code> value
726
public synchronized void removeGraphListener(GraphListener cl) {
727
m_graphListeners.remove(cl);
731
* Notify all graph listeners of a graph event
733
* @param ge a <code>GraphEvent</code> value
735
private void notifyGraphListeners(GraphEvent ge) {
737
synchronized (this) {
738
l = (Vector)m_graphListeners.clone();
741
for(int i = 0; i < l.size(); i++) {
742
((GraphListener)l.elementAt(i)).acceptGraph(ge);
748
* Add a text listener
750
* @param cl a <code>TextListener</code> value
752
public synchronized void addTextListener(TextListener cl) {
753
m_textListeners.addElement(cl);
757
* Remove a text listener
759
* @param cl a <code>TextListener</code> value
761
public synchronized void removeTextListener(TextListener cl) {
762
m_textListeners.remove(cl);
766
* Notify all text listeners of a text event
768
* @param ge a <code>TextEvent</code> value
770
private void notifyTextListeners(TextEvent ge) {
772
synchronized (this) {
773
l = (Vector)m_textListeners.clone();
776
for(int i = 0; i < l.size(); i++) {
777
((TextListener)l.elementAt(i)).acceptText(ge);
783
* Add an incremental classifier listener
785
* @param cl an <code>IncrementalClassifierListener</code> value
787
public synchronized void
788
addIncrementalClassifierListener(IncrementalClassifierListener cl) {
789
m_incrementalClassifierListeners.add(cl);
793
* Remove an incremental classifier listener
795
* @param cl an <code>IncrementalClassifierListener</code> value
797
public synchronized void
798
removeIncrementalClassifierListener(IncrementalClassifierListener cl) {
799
m_incrementalClassifierListeners.remove(cl);
803
* Notify all incremental classifier listeners of an incremental classifier
806
* @param ce an <code>IncrementalClassifierEvent</code> value
809
notifyIncrementalClassifierListeners(IncrementalClassifierEvent ce) {
811
synchronized (this) {
812
l = (Vector)m_incrementalClassifierListeners.clone();
815
for(int i = 0; i < l.size(); i++) {
816
((IncrementalClassifierListener)l.elementAt(i)).acceptClassifier(ce);
822
* Returns true if, at this time,
823
* the object will accept a connection with respect to the named event
825
* @param eventName the event
826
* @return true if the object will accept a connection
828
public boolean connectionAllowed(String eventName) {
829
/* if (eventName.compareTo("instance") == 0) {
830
if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier)) {
834
if (m_listenees.containsKey(eventName)) {
841
* Returns true if, at this time,
842
* the object will accept a connection according to the supplied
845
* @param esd the EventSetDescriptor
846
* @return true if the object will accept a connection
848
public boolean connectionAllowed(EventSetDescriptor esd) {
849
return connectionAllowed(esd.getName());
853
* Notify this object that it has been registered as a listener with
854
* a source with respect to the named event
856
* @param eventName the event
857
* @param source the source with which this object has been registered as
860
public synchronized void connectionNotification(String eventName,
862
if (eventName.compareTo("instance") == 0) {
863
if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier)) {
865
m_log.logMessage("Warning : " + m_Classifier.getClass().getName()
866
+ " is not an updateable classifier. This "
867
+"classifier will only be evaluated on incoming "
868
+"instance events and not trained on them.");
873
if (connectionAllowed(eventName)) {
874
m_listenees.put(eventName, source);
875
/* if (eventName.compareTo("instance") == 0) {
876
startIncrementalHandler();
882
* Notify this object that it has been deregistered as a listener with
883
* a source with respect to the supplied event name
885
* @param eventName the event
886
* @param source the source with which this object has been registered as
889
public synchronized void disconnectionNotification(String eventName,
891
m_listenees.remove(eventName);
892
if (eventName.compareTo("instance") == 0) {
893
stop(); // kill the incremental handler thread if it is running
898
* Function used to stop code that calls acceptTrainingSet. This is
899
* needed as classifier construction is performed inside a separate
900
* thread of execution.
902
* @param tf a <code>boolean</code> value
904
private synchronized void block(boolean tf) {
908
// only block if thread is still doing something useful!
909
if (m_buildThread.isAlive() && m_state != IDLE) {
912
} catch (InterruptedException ex) {
921
* Stop any classifier action
924
// tell all listenees (upstream beans) to stop
925
Enumeration en = m_listenees.keys();
926
while (en.hasMoreElements()) {
927
Object tempO = m_listenees.get(en.nextElement());
928
if (tempO instanceof BeanCommon) {
929
System.err.println("Listener is BeanCommon");
930
((BeanCommon)tempO).stop();
934
// stop the build thread
935
if (m_buildThread != null) {
936
m_buildThread.interrupt();
937
m_buildThread.stop();
938
m_buildThread = null;
939
m_visual.setStatic();
946
* @param logger a <code>Logger</code> value
948
public void setLog(Logger logger) {
953
* Return an enumeration of requests that can be made by the user
955
* @return an <code>Enumeration</code> value
957
public Enumeration enumerateRequests() {
958
Vector newVector = new Vector(0);
959
if (m_buildThread != null) {
960
newVector.addElement("Stop");
962
return newVector.elements();
966
* Perform a particular request
968
* @param request the request to perform
969
* @exception IllegalArgumentException if an error occurs
971
public void performRequest(String request) {
972
if (request.compareTo("Stop") == 0) {
975
throw new IllegalArgumentException(request
976
+ " not supported (Classifier)");
981
* Returns true, if at the current time, the event described by the
982
* supplied event descriptor could be generated.
984
* @param esd an <code>EventSetDescriptor</code> value
985
* @return a <code>boolean</code> value
987
public boolean eventGeneratable(EventSetDescriptor esd) {
988
String eventName = esd.getName();
989
return eventGeneratable(eventName);
993
* @param name of the event to check
994
* @return true if eventName is one of the possible events
995
* that this component can generate
997
private boolean generatableEvent(String eventName) {
998
if (eventName.compareTo("graph") == 0
999
|| eventName.compareTo("text") == 0
1000
|| eventName.compareTo("batchClassifier") == 0
1001
|| eventName.compareTo("incrementalClassifier") == 0) {
1008
* Returns true, if at the current time, the named event could
1009
* be generated. Assumes that the supplied event name is
1010
* an event that could be generated by this bean
1012
* @param eventName the name of the event in question
1013
* @return true if the named event could be generated at this point in
1016
public boolean eventGeneratable(String eventName) {
1017
if (!generatableEvent(eventName)) {
1020
if (eventName.compareTo("graph") == 0) {
1021
// can't generate a GraphEvent if classifier is not drawable
1022
if (!(m_Classifier instanceof weka.core.Drawable)) {
1025
// need to have a training set before the classifier
1026
// can generate a graph!
1027
if (!m_listenees.containsKey("trainingSet")) {
1030
// Source needs to be able to generate a trainingSet
1031
// before we can generate a graph
1032
Object source = m_listenees.get("trainingSet");
1033
if (source instanceof EventConstraints) {
1034
if (!((EventConstraints)source).eventGeneratable("trainingSet")) {
1040
if (eventName.compareTo("batchClassifier") == 0) {
1041
if (!m_listenees.containsKey("testSet")) {
1044
if (!m_listenees.containsKey("trainingSet") &&
1045
m_trainingSet == null) {
1048
Object source = m_listenees.get("testSet");
1049
if (source instanceof EventConstraints) {
1050
if (!((EventConstraints)source).eventGeneratable("testSet")) {
1054
/* source = m_listenees.get("trainingSet");
1055
if (source instanceof EventConstraints) {
1056
if (!((EventConstraints)source).eventGeneratable("trainingSet")) {
1062
if (eventName.compareTo("text") == 0) {
1063
if (!m_listenees.containsKey("trainingSet") &&
1064
!m_listenees.containsKey("instance")) {
1067
Object source = m_listenees.get("trainingSet");
1068
if (source != null && source instanceof EventConstraints) {
1069
if (!((EventConstraints)source).eventGeneratable("trainingSet")) {
1073
source = m_listenees.get("instance");
1074
if (source != null && source instanceof EventConstraints) {
1075
if (!((EventConstraints)source).eventGeneratable("instance")) {
1081
if (eventName.compareTo("incrementalClassifier") == 0) {
1082
/* if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier)) {
1085
if (!m_listenees.containsKey("instance")) {
1088
Object source = m_listenees.get("instance");
1089
if (source instanceof EventConstraints) {
1090
if (!((EventConstraints)source).eventGeneratable("instance")) {