NullFilter.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  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.
  6.  *
  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.
  11.  *
  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.
  15.  */
  16. /*
  17.  *    NullFilter.java
  18.  *    Copyright (C) 1999 Len Trigg
  19.  *
  20.  */
  21. package weka.filters;
  22. import java.io.*;
  23. import java.util.*;
  24. import weka.core.*;
  25. /** 
  26.  * A simple instance filter that allows no instances to pass
  27.  * through. Basically just for testing purposes.
  28.  *
  29.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  30.  * @version $Revision: 1.7 $
  31.  */
  32. public class NullFilter extends Filter {
  33.   /**
  34.    * Sets the format of the input instances.
  35.    *
  36.    * @param instanceInfo an Instances object containing the input instance
  37.    * structure (any instances contained in the object are ignored - only the
  38.    * structure is required).
  39.    * @return true if the outputFormat may be collected immediately
  40.    */
  41.   public boolean setInputFormat(Instances instanceInfo) throws Exception {
  42.     super.setInputFormat(instanceInfo);
  43.     setOutputFormat(instanceInfo);
  44.     return true;
  45.   }
  46.   /**
  47.    * Input an instance for filtering. Ordinarily the instance is processed
  48.    * and made available for output immediately. Some filters require all
  49.    * instances be read before producing output.
  50.    *
  51.    * @param instance the input instance
  52.    * @return true if the filtered instance may now be
  53.    * collected with output().
  54.    * @exception IllegalStateException if no input format has been set.
  55.    */
  56.   public boolean input(Instance instance) {
  57.     if (getInputFormat() == null) {
  58.       throw new IllegalStateException("No input instance format defined");
  59.     }
  60.     return false;
  61.   }
  62.   /**
  63.    * Main method for testing this class.
  64.    *
  65.    * @param argv should contain arguments to the filter: use -h for help
  66.    */
  67.   public static void main(String [] argv) {
  68.     try {
  69.       if (Utils.getFlag('b', argv)) {
  70. Filter.batchFilterFile(new NullFilter(), argv);
  71.       } else {
  72. Filter.filterFile(new NullFilter(), argv);
  73.       }
  74.     } catch (Exception ex) {
  75.       System.out.println(ex.getMessage());
  76.     }
  77.   }
  78. }