AllFilter.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.  *    AllFilter.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 passes all instances directly
  27.  * through. Basically just for testing purposes.
  28.  *
  29.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  30.  * @version $Revision: 1.8 $
  31.  */
  32. public class AllFilter extends Filter {
  33.   /**
  34.    * Returns a string describing this filter
  35.    *
  36.    * @return a description of the filter suitable for
  37.    * displaying in the explorer/experimenter gui
  38.    */
  39.   public String globalInfo() {
  40.     return "An instance filter that passes all instances through unmodified."
  41.       + " Primarily for testing purposes.";
  42.   }
  43.   /**
  44.    * Sets the format of the input instances.
  45.    *
  46.    * @param instanceInfo an Instances object containing the input instance
  47.    * structure (any instances contained in the object are ignored - only the
  48.    * structure is required).
  49.    * @return true if the outputFormat may be collected immediately
  50.    */
  51.   public boolean setInputFormat(Instances instanceInfo) throws Exception {
  52.     super.setInputFormat(instanceInfo);
  53.     setOutputFormat(instanceInfo);
  54.     return true;
  55.   }
  56.   /**
  57.    * Input an instance for filtering. Ordinarily the instance is processed
  58.    * and made available for output immediately. Some filters require all
  59.    * instances be read before producing output.
  60.    *
  61.    * @param instance the input instance
  62.    * @return true if the filtered instance may now be
  63.    * collected with output().
  64.    * @exception IllegalStateException if no input format has been defined.
  65.    */
  66.   public boolean input(Instance instance) {
  67.     if (getInputFormat() == null) {
  68.       throw new IllegalStateException("No input instance format defined");
  69.     }
  70.     if (m_NewBatch) {
  71.       resetQueue();
  72.       m_NewBatch = false;
  73.     }
  74.     push((Instance)instance.copy());
  75.     return true;
  76.   }
  77.   /**
  78.    * Main method for testing this class.
  79.    *
  80.    * @param argv should contain arguments to the filter: use -h for help
  81.    */
  82.   public static void main(String [] argv) {
  83.     
  84.     try {
  85.       if (Utils.getFlag('b', argv)) {
  86. Filter.batchFilterFile(new AllFilter(), argv);
  87.       } else {
  88. Filter.filterFile(new AllFilter(), argv);
  89.       }
  90.     } catch (Exception ex) {
  91.       System.out.println(ex.getMessage());
  92.     }
  93.   }
  94. }