📄 classifier.java
字号:
}
/**
* Remove a graph listener
*
* @param cl a <code>GraphListener</code> value
*/
public synchronized void removeGraphListener(GraphListener cl) {
m_graphListeners.remove(cl);
}
/**
* Notify all graph listeners of a graph event
*
* @param ge a <code>GraphEvent</code> value
*/
private void notifyGraphListeners(GraphEvent ge) {
Vector l;
synchronized (this) {
l = (Vector)m_graphListeners.clone();
}
if (l.size() > 0) {
for(int i = 0; i < l.size(); i++) {
((GraphListener)l.elementAt(i)).acceptGraph(ge);
}
}
}
/**
* Add a text listener
*
* @param cl a <code>TextListener</code> value
*/
public synchronized void addTextListener(TextListener cl) {
m_textListeners.addElement(cl);
}
/**
* Remove a text listener
*
* @param cl a <code>TextListener</code> value
*/
public synchronized void removeTextListener(TextListener cl) {
m_textListeners.remove(cl);
}
/**
* Notify all text listeners of a text event
*
* @param ge a <code>TextEvent</code> value
*/
private void notifyTextListeners(TextEvent ge) {
Vector l;
synchronized (this) {
l = (Vector)m_textListeners.clone();
}
if (l.size() > 0) {
for(int i = 0; i < l.size(); i++) {
((TextListener)l.elementAt(i)).acceptText(ge);
}
}
}
/**
* Add an incremental classifier listener
*
* @param cl an <code>IncrementalClassifierListener</code> value
*/
public synchronized void
addIncrementalClassifierListener(IncrementalClassifierListener cl) {
m_incrementalClassifierListeners.add(cl);
}
/**
* Remove an incremental classifier listener
*
* @param cl an <code>IncrementalClassifierListener</code> value
*/
public synchronized void
removeIncrementalClassifierListener(IncrementalClassifierListener cl) {
m_incrementalClassifierListeners.remove(cl);
}
/**
* Notify all incremental classifier listeners of an incremental classifier
* event
*
* @param ce an <code>IncrementalClassifierEvent</code> value
*/
private void
notifyIncrementalClassifierListeners(IncrementalClassifierEvent ce) {
Vector l;
synchronized (this) {
l = (Vector)m_incrementalClassifierListeners.clone();
}
if (l.size() > 0) {
for(int i = 0; i < l.size(); i++) {
((IncrementalClassifierListener)l.elementAt(i)).acceptClassifier(ce);
}
}
}
/**
* Returns true if, at this time,
* the object will accept a connection with respect to the named event
*
* @param eventName the event
* @return true if the object will accept a connection
*/
public boolean connectionAllowed(String eventName) {
/* if (eventName.compareTo("instance") == 0) {
if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier)) {
return false;
}
} */
if (m_listenees.containsKey(eventName)) {
return false;
}
return true;
}
/**
* Returns true if, at this time,
* the object will accept a connection according to the supplied
* EventSetDescriptor
*
* @param esd the EventSetDescriptor
* @return true if the object will accept a connection
*/
public boolean connectionAllowed(EventSetDescriptor esd) {
return connectionAllowed(esd.getName());
}
/**
* Notify this object that it has been registered as a listener with
* a source with respect to the named event
*
* @param eventName the event
* @param source the source with which this object has been registered as
* a listener
*/
public synchronized void connectionNotification(String eventName,
Object source) {
if (eventName.compareTo("instance") == 0) {
if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier)) {
if (m_log != null) {
m_log.logMessage("Warning : " + m_Classifier.getClass().getName()
+ " is not an updateable classifier. This "
+"classifier will only be evaluated on incoming "
+"instance events and not trained on them.");
}
}
}
if (connectionAllowed(eventName)) {
m_listenees.put(eventName, source);
/* if (eventName.compareTo("instance") == 0) {
startIncrementalHandler();
} */
}
}
/**
* Notify this object that it has been deregistered as a listener with
* a source with respect to the supplied event name
*
* @param eventName the event
* @param source the source with which this object has been registered as
* a listener
*/
public synchronized void disconnectionNotification(String eventName,
Object source) {
m_listenees.remove(eventName);
if (eventName.compareTo("instance") == 0) {
stop(); // kill the incremental handler thread if it is running
}
}
/**
* Function used to stop code that calls acceptTrainingSet. This is
* needed as classifier construction is performed inside a separate
* thread of execution.
*
* @param tf a <code>boolean</code> value
*/
private synchronized void block(boolean tf) {
if (tf) {
try {
// only block if thread is still doing something useful!
if (m_buildThread.isAlive() && m_state != IDLE) {
wait();
}
} catch (InterruptedException ex) {
}
} else {
notifyAll();
}
}
/**
* Stop any classifier action
*/
public void stop() {
// tell all listenees (upstream beans) to stop
Enumeration en = m_listenees.keys();
while (en.hasMoreElements()) {
Object tempO = m_listenees.get(en.nextElement());
if (tempO instanceof BeanCommon) {
System.err.println("Listener is BeanCommon");
((BeanCommon)tempO).stop();
}
}
// stop the build thread
if (m_buildThread != null) {
m_buildThread.interrupt();
m_buildThread.stop();
m_buildThread = null;
m_visual.setStatic();
}
}
/**
* Set a logger
*
* @param logger a <code>Logger</code> value
*/
public void setLog(Logger logger) {
m_log = logger;
}
/**
* Return an enumeration of requests that can be made by the user
*
* @return an <code>Enumeration</code> value
*/
public Enumeration enumerateRequests() {
Vector newVector = new Vector(0);
if (m_buildThread != null) {
newVector.addElement("Stop");
}
return newVector.elements();
}
/**
* Perform a particular request
*
* @param request the request to perform
* @exception IllegalArgumentException if an error occurs
*/
public void performRequest(String request) {
if (request.compareTo("Stop") == 0) {
stop();
} else {
throw new IllegalArgumentException(request
+ " not supported (Classifier)");
}
}
/**
* Returns true, if at the current time, the event described by the
* supplied event descriptor could be generated.
*
* @param esd an <code>EventSetDescriptor</code> value
* @return a <code>boolean</code> value
*/
public boolean eventGeneratable(EventSetDescriptor esd) {
String eventName = esd.getName();
return eventGeneratable(eventName);
}
/**
* Returns true, if at the current time, the named event could
* be generated. Assumes that the supplied event name is
* an event that could be generated by this bean
*
* @param eventName the name of the event in question
* @return true if the named event could be generated at this point in
* time
*/
public boolean eventGeneratable(String eventName) {
if (eventName.compareTo("graph") == 0) {
// can't generate a GraphEvent if classifier is not drawable
if (!(m_Classifier instanceof weka.core.Drawable)) {
return false;
}
// need to have a training set before the classifier
// can generate a graph!
if (!m_listenees.containsKey("trainingSet")) {
return false;
}
// Source needs to be able to generate a trainingSet
// before we can generate a graph
Object source = m_listenees.get("trainingSet");
if (source instanceof EventConstraints) {
if (!((EventConstraints)source).eventGeneratable("trainingSet")) {
return false;
}
}
}
if (eventName.compareTo("batchClassifier") == 0) {
if (!m_listenees.containsKey("testSet")) {
return false;
}
if (!m_listenees.containsKey("trainingSet") &&
m_trainingSet == null) {
return false;
}
Object source = m_listenees.get("testSet");
if (source instanceof EventConstraints) {
if (!((EventConstraints)source).eventGeneratable("testSet")) {
return false;
}
}
/* source = m_listenees.get("trainingSet");
if (source instanceof EventConstraints) {
if (!((EventConstraints)source).eventGeneratable("trainingSet")) {
return false;
}
} */
}
if (eventName.compareTo("text") == 0) {
if (!m_listenees.containsKey("trainingSet") &&
!m_listenees.containsKey("instance")) {
return false;
}
Object source = m_listenees.get("trainingSet");
if (source != null && source instanceof EventConstraints) {
if (!((EventConstraints)source).eventGeneratable("trainingSet")) {
return false;
}
}
source = m_listenees.get("instance");
if (source != null && source instanceof EventConstraints) {
if (!((EventConstraints)source).eventGeneratable("instance")) {
return false;
}
}
}
if (eventName.compareTo("incrementalClassifier") == 0) {
/* if (!(m_Classifier instanceof weka.classifiers.UpdateableClassifier)) {
return false;
} */
if (!m_listenees.containsKey("instance")) {
return false;
}
Object source = m_listenees.get("instance");
if (source instanceof EventConstraints) {
if (!((EventConstraints)source).eventGeneratable("instance")) {
return false;
}
}
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -