Loader.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 6k
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.  *    Loader.java
  18.  *    Copyright (C) 2000 Mark Hall
  19.  *
  20.  */
  21. package weka.core.converters;
  22. import java.io.File;
  23. import java.io.InputStream;
  24. import java.io.IOException;
  25. import java.io.Serializable;
  26. import weka.core.Instances;
  27. import weka.core.Instance;
  28. /** 
  29.  * Interface to something that can load Instances from an input source in some
  30.  * format.
  31.  *
  32.  * @author Mark Hall (mhall@cs.waikato.ac.nz)
  33.  * @version $Revision: 1.5 $
  34.  */
  35. public interface Loader extends Serializable {
  36.   /*@ public model instance boolean model_structureDetermined
  37.     @   initially: model_structureDetermined == false;
  38.     @*/
  39.   /*@ public model instance boolean model_sourceSupplied
  40.     @   initially: model_sourceSupplied == false;
  41.     @*/
  42.   /**
  43.    * Resets the Loader object and sets the source of the data set to be 
  44.    * the supplied File object.
  45.    *
  46.    * @param file the File
  47.    * @exception IOException if an error occurs
  48.    * support loading from a File.
  49.    *
  50.    * <pre><jml>
  51.    *    public_normal_behavior
  52.    *      requires: file != null
  53.    *                && (* file exists *);
  54.    *      modifiable: model_sourceSupplied, model_structureDetermined;
  55.    *      ensures: model_sourceSupplied == true 
  56.    *               && model_structureDetermined == false;
  57.    *  also
  58.    *    public_exceptional_behavior
  59.    *      requires: file == null
  60.    *                || (* file does not exist *);
  61.    *    signals: (IOException);
  62.    * </jml></pre>
  63.    */
  64.   void setSource(File file) throws IOException;
  65.   /**
  66.    * Resets the Loader object and sets the source of the data set to be 
  67.    * the supplied InputStream.
  68.    *
  69.    * @param input the source InputStream
  70.    * @exception IOException if this Loader doesn't
  71.    * support loading from a File.
  72.    */
  73.   void setSource(InputStream input) throws IOException;
  74.   /**
  75.    * Determines and returns (if possible) the structure (internally the 
  76.    * header) of the data set as an empty set of instances.
  77.    *
  78.    * @return the structure of the data set as an empty set of Instances
  79.    * @exception IOException if there is no source or parsing fails
  80.    *
  81.    * <pre><jml>
  82.    *    public_normal_behavior
  83.    *      requires: model_sourceSupplied == true
  84.    *                && model_structureDetermined == false
  85.    *                && (* successful parse *);
  86.    *      modifiable: model_structureDetermined;
  87.    *      ensures: result != null
  88.    *               && result.numInstances() == 0
  89.    *               && model_structureDetermined == true;
  90.    *  also
  91.    *    public_exceptional_behavior
  92.    *      requires: model_sourceSupplied == false
  93.    *                || (* unsuccessful parse *);
  94.    *      signals: (IOException);
  95.    * </jml></pre>
  96.    */
  97.   Instances getStructure() throws IOException;
  98.   /**
  99.    * Return the full data set. If the structure hasn't yet been determined
  100.    * by a call to getStructure then the method should do so before processing
  101.    * the rest of the data set.
  102.    *
  103.    * @return the full data set as an Instances object
  104.    * @exception IOException if there is an error during parsing or if 
  105.    * getNextInstance has been called on this source (either incremental
  106.    * or batch loading can be used, not both).
  107.    *
  108.    * <pre><jml>
  109.    *    public_normal_behavior
  110.    *      requires: model_sourceSupplied == true
  111.    *                && (* successful parse *);
  112.    *      modifiable: model_structureDetermined;
  113.    *      ensures: result != null
  114.    *               && result.numInstances() >= 0
  115.    *               && model_structureDetermined == true;
  116.    *  also
  117.    *    public_exceptional_behavior
  118.    *      requires: model_sourceSupplied == false
  119.    *                || (* unsuccessful parse *);
  120.    *      signals: (IOException);
  121.    * </jml></pre>
  122.    */
  123.   Instances getDataSet() throws IOException;
  124.   /**
  125.    * Read the data set incrementally---get the next instance in the data 
  126.    * set or returns null if there are no
  127.    * more instances to get. If the structure hasn't yet been 
  128.    * determined by a call to getStructure then method should do so before
  129.    * returning the next instance in the data set.
  130.    *
  131.    * If it is not possible to read the data set incrementally (ie. in cases
  132.    * where the data set structure cannot be fully established before all
  133.    * instances have been seen) then an exception should be thrown.
  134.    *
  135.    * @return the next instance in the data set as an Instance object or null
  136.    * if there are no more instances to be read
  137.    * @exception IOException if there is an error during parsing or if
  138.    * getDataSet has been called on this source (either incremental
  139.    * or batch loading can be used, not both).
  140.    *
  141.    * <pre><jml>
  142.    *    public_normal_behavior
  143.    *    {|
  144.    *       requires: model_sourceSupplied == true
  145.    *                 && (* successful parse *);
  146.    *       modifiable: model_structureDetermined;
  147.    *       ensures: model_structureDetermined == true
  148.    *                && result != null;
  149.    *     also
  150.    *       requires: model_sourceSupplied == true
  151.    *                 && (* no further input *);
  152.    *       modifiable: model_structureDetermined;
  153.    *       ensures: model_structureDetermined == true
  154.    *                && result == null;
  155.    *    |}
  156.    *  also
  157.    *    public_exceptional_behavior
  158.    *    {|
  159.    *       requires: model_sourceSupplied == false
  160.    *                 || (* unsuccessful parse *);
  161.    *       signals: (IOException);
  162.    *     also
  163.    *       requires: (* unable to process data set incrementally *);
  164.    *       signals: (IOException);
  165.    *    |}
  166.    * </jml></pre>
  167.    */
  168.   Instance getNextInstance() throws IOException;
  169. }