📄 examplefilter.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* web: http://yale.cs.uni-dortmund.de/
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package edu.udo.cs.yale.operator.preprocessing;
import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.IOObject;
import edu.udo.cs.yale.operator.OperatorException;
import edu.udo.cs.yale.operator.parameter.*;
import edu.udo.cs.yale.example.Example;
import edu.udo.cs.yale.example.ExampleSet;
import edu.udo.cs.yale.example.FilteredExampleSet;
import edu.udo.cs.yale.example.ConditionExampleReader;
import edu.udo.cs.yale.tools.LogService;
import java.util.List;
/** This operator takes an {@link ExampleSet} as input and returns a
* new {@link ExampleSet} including only the {@link Example}s that fulfill a
* condition.
* <br/>
* By specifying an implementation of
* {@link edu.udo.cs.yale.example.Condition}
* and a parameter string, arbitrary filters can be applied. Users can implement
* their own conditions by writing a subclass of the above class and implementing a two
* argument constructor taking an {@link ExampleSet} and a parameter string.
* This parameter string is specified by the parameter <code>parameter_string</code>.
* <br/>
* For {@link edu.udo.cs.yale.example.AttributeValueFilter} the parameter string
* must have the form <code>attribute op value</code>, where attribute is a name of
* an attribute, value is a value the attribute can take and op is one of the binary
* logical operators similar to the ones known from Java.<br/>
* For {@link edu.udo.cs.yale.example.LegalNumberCondition} the parameter string may
* be empty. This filter removes all examples containing attributes that have missing or
* illegal values.
*
* @version $Id: ExampleFilter.java,v 1.2 2004/08/27 11:57:44 ingomierswa Exp $
*/
public class ExampleFilter extends Operator {
private static final Class[] INPUT_CLASSES = { ExampleSet.class };
private static final Class[] OUTPUT_CLASSES = { ExampleSet.class };
private int dataRowType;
public IOObject[] apply() throws OperatorException {
// get the input example set
ExampleSet inputSet = (ExampleSet)getInput(ExampleSet.class);
LogService.logMessage(getName()+": input set has " + inputSet.getSize() + " examples.",
LogService.STATUS);
String className = getParameterAsString("condition_class");
String parameter = getParameterAsString("parameter_string");
logMessage("Creating condition '"+className+"' with parameter '"+parameter+"'", LogService.MINIMUM);
return new IOObject[] {
new FilteredExampleSet(inputSet,
ConditionExampleReader.createCondition(className, inputSet, parameter))
};
}
public Class[] getInputClasses() { return INPUT_CLASSES; }
public Class[] getOutputClasses() { return OUTPUT_CLASSES; }
public List getParameterTypes() {
List types = super.getParameterTypes();
ParameterType type = new ParameterTypeStringCategory("condition_class",
"Implementation of the condition.",
ConditionExampleReader.KNOWN_CONDITION_IMPLEMENTATIONS,
ConditionExampleReader.KNOWN_CONDITION_IMPLEMENTATIONS[0]);
type.setExpert(false);
types.add(type);
type = new ParameterTypeString("parameter_string", "Parameter string for the condition, e.g. 'attribute=value' for the AttributeValueFilter.", true);
type.setExpert(false);
types.add(type);
return types;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -