MOA 12.03
Real Time Analytics for Data Streams
FilteredStream.java
Go to the documentation of this file.
00001 /*
00002  *    FilteredStream.java
00003  *    Copyright (C) 2007 University of Waikato, Hamilton, New Zealand
00004  *    @author Richard Kirkby (rkirkby@cs.waikato.ac.nz)
00005  *
00006  *    This program is free software; you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation; either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    This program is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  *    
00019  */
00020 package moa.streams;
00021 
00022 import moa.core.InstancesHeader;
00023 import moa.core.ObjectRepository;
00024 import moa.options.AbstractOptionHandler;
00025 import moa.options.ClassOption;
00026 import moa.options.ListOption;
00027 import moa.options.Option;
00028 import moa.options.OptionHandler;
00029 import moa.streams.filters.StreamFilter;
00030 import moa.tasks.TaskMonitor;
00031 import weka.core.Instance;
00032 
00039 public class FilteredStream extends AbstractOptionHandler implements
00040         InstanceStream {
00041 
00042     @Override
00043     public String getPurposeString() {
00044         return "A stream that is filtered.";
00045     }
00046 
00047     private static final long serialVersionUID = 1L;
00048 
00049     public ClassOption streamOption = new ClassOption("stream", 's',
00050             "Stream to filter.", InstanceStream.class,
00051             "generators.RandomTreeGenerator");
00052 
00053     public ListOption filtersOption = new ListOption("filters", 'f',
00054             "Filters to apply.", new ClassOption("filter", ' ',
00055             "Stream filter.", StreamFilter.class, "AddNoiseFilter"),
00056             new Option[0], ',');
00057 
00058     protected InstanceStream filterChain;
00059 
00060     @Override
00061     public void prepareForUseImpl(TaskMonitor monitor,
00062             ObjectRepository repository) {
00063         Option[] filterOptions = this.filtersOption.getList();
00064         StreamFilter[] filters = new StreamFilter[filterOptions.length];
00065         for (int i = 0; i < filters.length; i++) {
00066             monitor.setCurrentActivity("Materializing filter " + (i + 1)
00067                     + "...", -1.0);
00068             filters[i] = (StreamFilter) ((ClassOption) filterOptions[i]).materializeObject(monitor, repository);
00069             if (monitor.taskShouldAbort()) {
00070                 return;
00071             }
00072             if (filters[i] instanceof OptionHandler) {
00073                 monitor.setCurrentActivity("Preparing filter " + (i + 1)
00074                         + "...", -1.0);
00075                 ((OptionHandler) filters[i]).prepareForUse(monitor, repository);
00076                 if (monitor.taskShouldAbort()) {
00077                     return;
00078                 }
00079             }
00080         }
00081         InstanceStream chain = (InstanceStream) getPreparedClassOption(this.streamOption);
00082         for (int i = 0; i < filters.length; i++) {
00083             filters[i].setInputStream(chain);
00084             chain = filters[i];
00085         }
00086         this.filterChain = chain;
00087     }
00088 
00089     @Override
00090     public long estimatedRemainingInstances() {
00091         return this.filterChain.estimatedRemainingInstances();
00092     }
00093 
00094     @Override
00095     public InstancesHeader getHeader() {
00096         return this.filterChain.getHeader();
00097     }
00098 
00099     @Override
00100     public boolean hasMoreInstances() {
00101         return this.filterChain.hasMoreInstances();
00102     }
00103 
00104     @Override
00105     public boolean isRestartable() {
00106         return this.filterChain.isRestartable();
00107     }
00108 
00109     @Override
00110     public Instance nextInstance() {
00111         return this.filterChain.nextInstance();
00112     }
00113 
00114     @Override
00115     public void restart() {
00116         this.filterChain.restart();
00117     }
00118 
00119     @Override
00120     public void getDescription(StringBuilder sb, int indent) {
00121         // TODO Auto-generated method stub
00122     }
00123 }
 All Classes Namespaces Files Functions Variables Enumerations