You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/01/25 16:03:10 UTC

svn commit: r1063310 - /incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/

Author: joern
Date: Tue Jan 25 15:03:09 2011
New Revision: 1063310

URL: http://svn.apache.org/viewvc?rev=1063310&view=rev
Log:
OPENLP-24 Formated code to comply with conventions

Modified:
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinToAscii.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelReader.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelWriter.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelReader.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelWriter.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelReader.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelWriter.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/OldFormatGISModelReader.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/PlainTextGISModelReader.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/SuffixSensitiveGISModelReader.java

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinToAscii.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinToAscii.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinToAscii.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinToAscii.java Tue Jan 25 15:03:09 2011
@@ -36,22 +36,20 @@ import java.util.zip.GZIPOutputStream;
  */
 public class BinToAscii {
 
-	public static void main(String[] args) throws IOException {
-		PrintWriter out =
-			new PrintWriter(new OutputStreamWriter(
-				new GZIPOutputStream(
-					new FileOutputStream(args[1]))));
-		DataInputStream in =
-			new DataInputStream(new GZIPInputStream(
-				new FileInputStream(args[0])));
+  public static void main(String[] args) throws IOException {
+    PrintWriter out = new PrintWriter(new OutputStreamWriter(
+        new GZIPOutputStream(new FileOutputStream(args[1]))));
+    DataInputStream in = new DataInputStream(new GZIPInputStream(
+        new FileInputStream(args[0])));
 
-		double d;
-		try {
-			while(true)
-				out.println(in.readDouble());
-		} catch (Exception E) {}
-		out.close();
-		in.close();
-	}
+    double d;
+    try {
+      while (true)
+        out.println(in.readDouble());
+    } catch (Exception E) {
+    }
+    out.close();
+    in.close();
+  }
 
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelReader.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelReader.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelReader.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelReader.java Tue Jan 25 15:03:09 2011
@@ -28,13 +28,14 @@ import opennlp.model.BinaryFileDataReade
  */
 public class BinaryGISModelReader extends GISModelReader {
 
-    /**
-     * Constructor which directly instantiates the DataInputStream containing
-     * the model contents.
-     *
-     * @param dis The DataInputStream containing the model information.
-     */
-    public BinaryGISModelReader (DataInputStream dis) {
-      super(new BinaryFileDataReader(dis));
-    }
+  /**
+   * Constructor which directly instantiates the DataInputStream containing the
+   * model contents.
+   * 
+   * @param dis
+   *          The DataInputStream containing the model information.
+   */
+  public BinaryGISModelReader(DataInputStream dis) {
+    super(new BinaryFileDataReader(dis));
+  }
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelWriter.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelWriter.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelWriter.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/BinaryGISModelWriter.java Tue Jan 25 15:03:09 2011
@@ -33,54 +33,57 @@ import opennlp.model.AbstractModel;
 public class BinaryGISModelWriter extends GISModelWriter {
     DataOutputStream output;
 
-   /**
-     * Constructor which takes a GISModel and a File and prepares itself to
-     * write the model to that file. Detects whether the file is gzipped or not
-     * based on whether the suffix contains ".gz".
-     *
-     * @param model The GISModel which is to be persisted.
-     * @param f The File in which the model is to be persisted.
-     */
-    public BinaryGISModelWriter (AbstractModel model, File f) throws IOException {
-
-	super(model);
-	
-	if (f.getName().endsWith(".gz")) {
-	    output = new DataOutputStream(
-		         new GZIPOutputStream(new FileOutputStream(f)));
-	}
-	else {
-	    output = new DataOutputStream(new FileOutputStream(f));
-	}
-    }
-
-    /**
-     * Constructor which takes a GISModel and a DataOutputStream and prepares
-     * itself to write the model to that stream.
-     *
-     * @param model The GISModel which is to be persisted.
-     * @param dos The stream which will be used to persist the model.
-     */
-    public BinaryGISModelWriter (AbstractModel model, DataOutputStream dos) {
-      super(model);
-      output = dos;
-    }
-
-    public void writeUTF (String s) throws java.io.IOException {
-      output.writeUTF(s);
-    }
-
-    public void writeInt (int i) throws java.io.IOException {
-      output.writeInt(i);
-    }
-
-    public void writeDouble (double d) throws java.io.IOException {
-      output.writeDouble(d);
-    }
-
-    public void close () throws java.io.IOException {
-      output.flush();
-      output.close();
-    }
+  /**
+   * Constructor which takes a GISModel and a File and prepares itself to write
+   * the model to that file. Detects whether the file is gzipped or not based on
+   * whether the suffix contains ".gz".
+   * 
+   * @param model
+   *          The GISModel which is to be persisted.
+   * @param f
+   *          The File in which the model is to be persisted.
+   */
+  public BinaryGISModelWriter(AbstractModel model, File f) throws IOException {
+
+    super(model);
+
+    if (f.getName().endsWith(".gz")) {
+      output = new DataOutputStream(new GZIPOutputStream(
+          new FileOutputStream(f)));
+    } else {
+      output = new DataOutputStream(new FileOutputStream(f));
+    }
+  }
+
+  /**
+   * Constructor which takes a GISModel and a DataOutputStream and prepares
+   * itself to write the model to that stream.
+   * 
+   * @param model
+   *          The GISModel which is to be persisted.
+   * @param dos
+   *          The stream which will be used to persist the model.
+   */
+  public BinaryGISModelWriter(AbstractModel model, DataOutputStream dos) {
+    super(model);
+    output = dos;
+  }
+
+  public void writeUTF(String s) throws java.io.IOException {
+    output.writeUTF(s);
+  }
+
+  public void writeInt(int i) throws java.io.IOException {
+    output.writeInt(i);
+  }
+
+  public void writeDouble(double d) throws java.io.IOException {
+    output.writeDouble(d);
+  }
+
+  public void close() throws java.io.IOException {
+    output.flush();
+    output.close();
+  }
 
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelReader.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelReader.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelReader.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelReader.java Tue Jan 25 15:03:09 2011
@@ -32,66 +32,64 @@ import opennlp.model.DataReader;
  * Abstract parent class for readers of GISModels.
  */
 public class GISModelReader extends AbstractModelReader {
-  
-    public GISModelReader(File file) throws IOException {
-      super(file);
-    }
-    
-    public GISModelReader(DataReader dataReader) {
-      super(dataReader);
-    }
-    
-    /**
-     * Retrieve a model from disk. It assumes that models are saved in the
-     * following sequence:
-     * 
-     * <br>GIS (model type identifier)
-     * <br>1. # of parameters (int)
-     * <br>2. the correction constant (int)
-     * <br>3. the correction constant parameter (double)
-     * <br>4. # of outcomes (int)
-     * <br>  * list of outcome names (String)
-     * <br>5. # of different types of outcome patterns (int)
-     * <br>   * list of (int int[])
-     * <br>   [# of predicates for which outcome pattern is true] [outcome pattern]
-     * <br>6. # of predicates (int)
-     * <br>   * list of predicate names (String)
-     *
-     * <p>If you are creating a reader for a format which won't work with this
-     * (perhaps a database or xml file), override this method and ignore the
-     * other methods provided in this abstract class.
-     *
-     * @return The GISModel stored in the format and location specified to
-     *         this GISModelReader (usually via its the constructor).
-     */    
-    public AbstractModel constructModel() throws IOException {
-      int correctionConstant = getCorrectionConstant();
-      double correctionParam = getCorrectionParameter();
-      String[] outcomeLabels = getOutcomes();
-      int[][] outcomePatterns = getOutcomePatterns();
-      String[] predLabels = getPredicates();
-      Context[] params = getParameters(outcomePatterns);
-    
-      return new GISModel(params,
-                          predLabels,
-                          outcomeLabels,
-                          correctionConstant,
-                          correctionParam);
-    }
-
-    public void checkModelType() throws java.io.IOException {
-      String modelType = readUTF();
-      if (!modelType.equals("GIS"))
-          System.out.println("Error: attempting to load a "+modelType+
-                             " model as a GIS model."+
-                             " You should expect problems.");
-    }
+
+  public GISModelReader(File file) throws IOException {
+    super(file);
+  }
+
+  public GISModelReader(DataReader dataReader) {
+    super(dataReader);
+  }
+
+  /**
+   * Retrieve a model from disk. It assumes that models are saved in the
+   * following sequence:
+   * 
+   * <br>
+   * GIS (model type identifier) <br>
+   * 1. # of parameters (int) <br>
+   * 2. the correction constant (int) <br>
+   * 3. the correction constant parameter (double) <br>
+   * 4. # of outcomes (int) <br>
+   * * list of outcome names (String) <br>
+   * 5. # of different types of outcome patterns (int) <br>
+   * * list of (int int[]) <br>
+   * [# of predicates for which outcome pattern is true] [outcome pattern] <br>
+   * 6. # of predicates (int) <br>
+   * * list of predicate names (String)
+   * 
+   * <p>
+   * If you are creating a reader for a format which won't work with this
+   * (perhaps a database or xml file), override this method and ignore the other
+   * methods provided in this abstract class.
+   * 
+   * @return The GISModel stored in the format and location specified to this
+   *         GISModelReader (usually via its the constructor).
+   */  
+  public AbstractModel constructModel() throws IOException {
+    int correctionConstant = getCorrectionConstant();
+    double correctionParam = getCorrectionParameter();
+    String[] outcomeLabels = getOutcomes();
+    int[][] outcomePatterns = getOutcomePatterns();
+    String[] predLabels = getPredicates();
+    Context[] params = getParameters(outcomePatterns);
+
+    return new GISModel(params, predLabels, outcomeLabels, correctionConstant,
+        correctionParam);
+  }
+
+  public void checkModelType() throws java.io.IOException {
+    String modelType = readUTF();
+    if (!modelType.equals("GIS"))
+      System.out.println("Error: attempting to load a " + modelType
+          + " model as a GIS model." + " You should expect problems.");
+  }
     
   protected int getCorrectionConstant() throws java.io.IOException {
-      return readInt();
+    return readInt();
   }
 
   protected double getCorrectionParameter() throws java.io.IOException {
-      return readDouble();
+    return readDouble();
   }
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelWriter.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelWriter.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelWriter.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/GISModelWriter.java Tue Jan 25 15:03:09 2011
@@ -36,132 +36,123 @@ import opennlp.model.IndexHashTable;
  * extending class to define precisely how the data should be stored.
  */
 public abstract class GISModelWriter extends AbstractModelWriter {
-    protected Context[] PARAMS;
-    protected String[] OUTCOME_LABELS;
-    protected int CORRECTION_CONSTANT;
-    protected double CORRECTION_PARAM;
-    protected String[] PRED_LABELS;
-
-    public GISModelWriter (AbstractModel model) {
-      
-      Object[] data = model.getDataStructures();
-      
-      PARAMS = (Context[]) data[0];
-      IndexHashTable<String> pmap = (IndexHashTable<String>) data[1];
-      OUTCOME_LABELS = (String[]) data[2];
-      CORRECTION_CONSTANT = ((Integer) data[3]).intValue();
-      CORRECTION_PARAM = ((Double) data[4]).doubleValue();
-      
-      PRED_LABELS = new String[pmap.size()];
-      pmap.toArray(PRED_LABELS);
+  protected Context[] PARAMS;
+  protected String[] OUTCOME_LABELS;
+  protected int CORRECTION_CONSTANT;
+  protected double CORRECTION_PARAM;
+  protected String[] PRED_LABELS;
+
+  public GISModelWriter(AbstractModel model) {
+
+    Object[] data = model.getDataStructures();
+
+    PARAMS = (Context[]) data[0];
+    IndexHashTable<String> pmap = (IndexHashTable<String>) data[1];
+    OUTCOME_LABELS = (String[]) data[2];
+    CORRECTION_CONSTANT = ((Integer) data[3]).intValue();
+    CORRECTION_PARAM = ((Double) data[4]).doubleValue();
+
+    PRED_LABELS = new String[pmap.size()];
+    pmap.toArray(PRED_LABELS);
+  }
+
+
+  /**
+   * Writes the model to disk, using the <code>writeX()</code> methods provided
+   * by extending classes.
+   * 
+   * <p>
+   * If you wish to create a GISModelWriter which uses a different structure, it
+   * will be necessary to override the persist method in addition to
+   * implementing the <code>writeX()</code> methods.
+   */
+  public void persist() throws IOException {
+
+    // the type of model (GIS)
+    writeUTF("GIS");
+
+    // the value of the correction constant
+    writeInt(CORRECTION_CONSTANT);
+
+    // the value of the correction constant
+    writeDouble(CORRECTION_PARAM);
+
+    // the mapping from outcomes to their integer indexes
+    writeInt(OUTCOME_LABELS.length);
+
+    for (int i = 0; i < OUTCOME_LABELS.length; i++)
+      writeUTF(OUTCOME_LABELS[i]);
+
+    // the mapping from predicates to the outcomes they contributed to.
+    // The sorting is done so that we actually can write this out more
+    // compactly than as the entire list.
+    ComparablePredicate[] sorted = sortValues();
+    List compressed = compressOutcomes(sorted);
+
+    writeInt(compressed.size());
+
+    for (int i = 0; i < compressed.size(); i++) {
+      List a = (List) compressed.get(i);
+      writeUTF(a.size() + ((ComparablePredicate) a.get(0)).toString());
     }
 
+    // the mapping from predicate names to their integer indexes
+    writeInt(PARAMS.length);
 
-    /**
-     * Writes the model to disk, using the <code>writeX()</code> methods
-     * provided by extending classes.
-     *
-     * <p>If you wish to create a GISModelWriter which uses a different
-     * structure, it will be necessary to override the persist method in
-     * addition to implementing the <code>writeX()</code> methods.
-     */
-    public void persist() throws IOException {
-      
-      // the type of model (GIS)
-      writeUTF("GIS");
-      
-      // the value of the correction constant
-      writeInt(CORRECTION_CONSTANT);
-      
-      // the value of the correction constant	
-      writeDouble(CORRECTION_PARAM);
-      
-      // the mapping from outcomes to their integer indexes
-      writeInt(OUTCOME_LABELS.length);
-      
-      for (int i=0; i<OUTCOME_LABELS.length; i++)
-        writeUTF(OUTCOME_LABELS[i]); 
-      
-      // the mapping from predicates to the outcomes they contributed to.
-      // The sorting is done so that we actually can write this out more
-      // compactly than as the entire list.
-      ComparablePredicate[] sorted = sortValues();
-      List compressed = compressOutcomes(sorted);
-      
-      writeInt(compressed.size());
-      
-      for (int i=0; i<compressed.size(); i++) {
-        List a = (List)compressed.get(i);
-        writeUTF(a.size()
-            + ((ComparablePredicate)a.get(0)).toString());
-      }	
-      
-      // the mapping from predicate names to their integer indexes
-      writeInt(PARAMS.length);
-      
-      for (int i=0; i<sorted.length; i++)
-        writeUTF(sorted[i].name); 
-      
-      // write out the parameters
-      for (int i=0; i<sorted.length; i++)
-        for (int j=0; j<sorted[i].params.length; j++)
-          writeDouble(sorted[i].params[j]);
-      
-      close();
-    }
-
+    for (int i = 0; i < sorted.length; i++)
+      writeUTF(sorted[i].name);
 
-    protected ComparablePredicate[] sortValues () {
-	
-        ComparablePredicate[] sortPreds =
-            new ComparablePredicate[PARAMS.length];
-
-        int numParams = 0;	
-        for (int pid=0; pid<PARAMS.length; pid++) {
-            int[] predkeys = PARAMS[pid].getOutcomes();
-            //Arrays.sort(predkeys);
-            int numActive = predkeys.length;
-            int[] activeOutcomes = predkeys;
-            double[] activeParams = PARAMS[pid].getParameters();
-
-            numParams += numActive;
-            /*
-            double[] activeParams = new double[numActive];
-            
-            int id = 0;	   
-            for (int i=0; i < predkeys.length; i++) {
-                int oid = predkeys[i];
-                activeOutcomes[id] = oid;
-                activeParams[id] = PARAMS[pid].getParams(oid);
-                id++;
-            }
-            */
-            sortPreds[pid] = new ComparablePredicate(PRED_LABELS[pid],
-                                                     activeOutcomes,
-                                                     activeParams);
-        }
-		
-        Arrays.sort(sortPreds);
-        return sortPreds;
+    // write out the parameters
+    for (int i = 0; i < sorted.length; i++)
+      for (int j = 0; j < sorted[i].params.length; j++)
+        writeDouble(sorted[i].params[j]);
+
+    close();
+  }
+
+  protected ComparablePredicate[] sortValues() {
+
+    ComparablePredicate[] sortPreds = new ComparablePredicate[PARAMS.length];
+
+    int numParams = 0;
+    for (int pid = 0; pid < PARAMS.length; pid++) {
+      int[] predkeys = PARAMS[pid].getOutcomes();
+      // Arrays.sort(predkeys);
+      int numActive = predkeys.length;
+      int[] activeOutcomes = predkeys;
+      double[] activeParams = PARAMS[pid].getParameters();
+
+      numParams += numActive;
+      /*
+       * double[] activeParams = new double[numActive];
+       * 
+       * int id = 0; for (int i=0; i < predkeys.length; i++) { int oid =
+       * predkeys[i]; activeOutcomes[id] = oid; activeParams[id] =
+       * PARAMS[pid].getParams(oid); id++; }
+       */
+      sortPreds[pid] = new ComparablePredicate(PRED_LABELS[pid],
+          activeOutcomes, activeParams);
     }
-    
-    protected List compressOutcomes (ComparablePredicate[] sorted) {
-      ComparablePredicate cp = sorted[0];
-      List outcomePatterns = new ArrayList();
-      List newGroup = new ArrayList();
-      for (int i=0; i<sorted.length; i++) {
-        if (cp.compareTo(sorted[i]) == 0) {
-          newGroup.add(sorted[i]);
-        } else {	    
-          cp = sorted[i];
-          outcomePatterns.add(newGroup);
-          newGroup = new ArrayList();
-          newGroup.add(sorted[i]);
-        }	    
+
+    Arrays.sort(sortPreds);
+    return sortPreds;
+  }
+
+  protected List compressOutcomes(ComparablePredicate[] sorted) {
+    ComparablePredicate cp = sorted[0];
+    List outcomePatterns = new ArrayList();
+    List newGroup = new ArrayList();
+    for (int i = 0; i < sorted.length; i++) {
+      if (cp.compareTo(sorted[i]) == 0) {
+        newGroup.add(sorted[i]);
+      } else {
+        cp = sorted[i];
+        outcomePatterns.add(newGroup);
+        newGroup = new ArrayList();
+        newGroup.add(sorted[i]);
       }
-      outcomePatterns.add(newGroup);
-      return outcomePatterns;
     }
-
-    
+    outcomePatterns.add(newGroup);
+    return outcomePatterns;
+  }
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelReader.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelReader.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelReader.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelReader.java Tue Jan 25 15:03:09 2011
@@ -25,15 +25,16 @@ import opennlp.model.ObjectDataReader;
 
 public class ObjectGISModelReader extends GISModelReader {
 
-   protected ObjectInputStream input;
-  
+  protected ObjectInputStream input;
+
   /**
    * Constructor which directly instantiates the ObjectInputStream containing
    * the model contents.
-   *
-   * @param dis The DataInputStream containing the model information.
+   * 
+   * @param dis
+   *          The DataInputStream containing the model information.
    */
-  
+
   public ObjectGISModelReader(ObjectInputStream ois) {
     super(new ObjectDataReader(ois));
   }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelWriter.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelWriter.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelWriter.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/ObjectGISModelWriter.java Tue Jan 25 15:03:09 2011
@@ -40,7 +40,6 @@ public class ObjectGISModelWriter extend
     output = dos;
   }
 
-
   public void writeUTF(String s) throws IOException {
     output.writeUTF(s);
   }
@@ -57,5 +56,4 @@ public class ObjectGISModelWriter extend
     output.flush();
     output.close();
   }
-
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/OldFormatGISModelReader.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/OldFormatGISModelReader.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/OldFormatGISModelReader.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/OldFormatGISModelReader.java Tue Jan 25 15:03:09 2011
@@ -37,79 +37,85 @@ import opennlp.model.Context;
 public class OldFormatGISModelReader extends PlainTextGISModelReader {
     DataInputStream paramsInput;
 
-    /**
-     * Constructor which takes the name of the model without any suffixes,
-     * such as ".mei.gz" or ".mep.gz".
-     */
-    public OldFormatGISModelReader(String modelname)
-	throws IOException {
-	super(new File(modelname+".mei.gz"));
-	paramsInput = new DataInputStream(new GZIPInputStream(
-		          new FileInputStream(modelname+".mep.gz")));
-    }
-
-    /**
-     * Reads the parameters from a file and populates an array of context objects.
-     * @param outcomePatterns The outcomes patterns for the model.  The first index refers to which 
-     * outcome pattern (a set of outcomes that occurs with a context) is being specified.  The
-     * second index specifies the number of contexts which use this pattern at index 0, and the
-     * index of each outcomes which make up this pattern in indicies 1-n.  
-     * @return An array of context objects.
-     * @throws java.io.IOException when the model file does not match the outcome patterns or can not be read.
-     */
-    protected Context[] getParameters (int[][] outcomePatterns) throws java.io.IOException {
-      Context[] params = new Context[NUM_PREDS];
-      int pid=0;
-      for (int i=0; i<outcomePatterns.length; i++) {
-        //construct outcome pattern
-        int[] outcomePattern = new int[outcomePatterns[i].length-1];
-        for (int k=1; k<outcomePatterns[i].length; k++) {
-          outcomePattern[k-1] = outcomePatterns[i][k];
-        }
-        //populate parameters for each context which uses this outcome pattern. 
-        for (int j=0; j<outcomePatterns[i][0]; j++) {
-          double[] contextParameters = new double[outcomePatterns[i].length-1];
-          for (int k=1; k<outcomePatterns[i].length; k++) {
-            contextParameters[k-1] = readDouble();
-          }
-          params[pid] = new Context(outcomePattern,contextParameters);
-          pid++;
+  /**
+   * Constructor which takes the name of the model without any suffixes, such as
+   * ".mei.gz" or ".mep.gz".
+   */
+  public OldFormatGISModelReader(String modelname) throws IOException {
+    super(new File(modelname + ".mei.gz"));
+    paramsInput = new DataInputStream(new GZIPInputStream(new FileInputStream(
+        modelname + ".mep.gz")));
+  }
+
+  /**
+   * Reads the parameters from a file and populates an array of context objects.
+   * 
+   * @param outcomePatterns
+   *          The outcomes patterns for the model. The first index refers to
+   *          which outcome pattern (a set of outcomes that occurs with a
+   *          context) is being specified. The second index specifies the number
+   *          of contexts which use this pattern at index 0, and the index of
+   *          each outcomes which make up this pattern in indicies 1-n.
+   * @return An array of context objects.
+   * @throws java.io.IOException
+   *           when the model file does not match the outcome patterns or can
+   *           not be read.
+   */
+  protected Context[] getParameters(int[][] outcomePatterns)
+      throws java.io.IOException {
+    Context[] params = new Context[NUM_PREDS];
+    int pid = 0;
+    for (int i = 0; i < outcomePatterns.length; i++) {
+      // construct outcome pattern
+      int[] outcomePattern = new int[outcomePatterns[i].length - 1];
+      for (int k = 1; k < outcomePatterns[i].length; k++) {
+        outcomePattern[k - 1] = outcomePatterns[i][k];
+      }
+      // populate parameters for each context which uses this outcome pattern.
+      for (int j = 0; j < outcomePatterns[i][0]; j++) {
+        double[] contextParameters = new double[outcomePatterns[i].length - 1];
+        for (int k = 1; k < outcomePatterns[i].length; k++) {
+          contextParameters[k - 1] = readDouble();
         }
+        params[pid] = new Context(outcomePattern, contextParameters);
+        pid++;
       }
-      return params;
     }
+    return params;
+  }
 
-    /**
-     * Convert a model created with Maxent 1.0 to a format used with
-     * Maxent 1.2.
-     *
-     * <p>Usage: java opennlp.maxent.io.OldFormatGISModelReader model_name_prefix (new_model_name)");
-     *
-     * <p>If the new_model_name is left unspecified, the new model will be saved
-     * in gzipped, binary format as "<model_name_prefix>.bin.gz".
-     */
-    public static void main (String[] args) throws IOException {
-	if (args.length < 1) {
-	    System.out.println("Usage: java opennlp.maxent.io.OldFormatGISModelReader model_name_prefix (new_model_name)");
-	    System.exit(0);
-	}
-
-	int nameIndex = 0;
-
-	String infilePrefix = args[nameIndex];
-	String outfile;
-
-	if (args.length > nameIndex)
-	    outfile = args[nameIndex+1];
-	else
-	    outfile = infilePrefix + ".bin.gz";
-
-
-	AbstractModelReader reader = new OldFormatGISModelReader(infilePrefix);
-
-	new SuffixSensitiveGISModelWriter(reader.getModel(),
-					  new File(outfile)).persist();
-				   
+  /**
+   * Convert a model created with Maxent 1.0 to a format used with Maxent 1.2.
+   * 
+   * <p>
+   * Usage: java opennlp.maxent.io.OldFormatGISModelReader model_name_prefix
+   * (new_model_name)");
+   * 
+   * <p>
+   * If the new_model_name is left unspecified, the new model will be saved in
+   * gzipped, binary format as "<model_name_prefix>.bin.gz".
+   */
+  public static void main(String[] args) throws IOException {
+    if (args.length < 1) {
+      System.out
+          .println("Usage: java opennlp.maxent.io.OldFormatGISModelReader model_name_prefix (new_model_name)");
+      System.exit(0);
     }
-    
+
+    int nameIndex = 0;
+
+    String infilePrefix = args[nameIndex];
+    String outfile;
+
+    if (args.length > nameIndex)
+      outfile = args[nameIndex + 1];
+    else
+      outfile = infilePrefix + ".bin.gz";
+
+    AbstractModelReader reader = new OldFormatGISModelReader(infilePrefix);
+
+    new SuffixSensitiveGISModelWriter(reader.getModel(), new File(outfile))
+        .persist();
+
+  }
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/PlainTextGISModelReader.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/PlainTextGISModelReader.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/PlainTextGISModelReader.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/PlainTextGISModelReader.java Tue Jan 25 15:03:09 2011
@@ -30,24 +30,25 @@ import opennlp.model.PlainTextFileDataRe
  */
 public class PlainTextGISModelReader extends GISModelReader {
 
-    /**
-     * Constructor which directly instantiates the BufferedReader containing
-     * the model contents.
-     *
-     * @param br The BufferedReader containing the model information.
-     */
-    public PlainTextGISModelReader (BufferedReader br) {
-      super(new PlainTextFileDataReader(br));
-    }
+  /**
+   * Constructor which directly instantiates the BufferedReader containing the
+   * model contents.
+   * 
+   * @param br
+   *          The BufferedReader containing the model information.
+   */
+  public PlainTextGISModelReader(BufferedReader br) {
+    super(new PlainTextFileDataReader(br));
+  }
 
-    /**
-     * Constructor which takes a File and creates a reader for it. Detects
-     * whether the file is gzipped or not based on whether the suffix contains
-     * ".gz".
-     *
-     * @param f The File in which the model is stored.
-     */
-    public PlainTextGISModelReader (File f) throws IOException {
-      super(f);
-    }
+  /**
+   * Constructor which takes a File and creates a reader for it. Detects whether
+   * the file is gzipped or not based on whether the suffix contains ".gz".
+   * 
+   * @param f
+   *          The File in which the model is stored.
+   */
+  public PlainTextGISModelReader(File f) throws IOException {
+    super(f);
+  }
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/SuffixSensitiveGISModelReader.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/SuffixSensitiveGISModelReader.java?rev=1063310&r1=1063309&r2=1063310&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/SuffixSensitiveGISModelReader.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/io/SuffixSensitiveGISModelReader.java Tue Jan 25 15:03:09 2011
@@ -34,43 +34,48 @@ import opennlp.model.AbstractModel;
  *    <li>.bin --> the file is binary
  */
 public class SuffixSensitiveGISModelReader extends GISModelReader {
-    protected GISModelReader suffixAppropriateReader;
+  protected GISModelReader suffixAppropriateReader;
 
-    /**
-     * Constructor which takes a File and invokes the GISModelReader
-     * appropriate for the suffix.
-     *
-     * @param f The File in which the model is stored.
-     */
-    public SuffixSensitiveGISModelReader (File f) throws IOException {
-      super(f);
-    }
+  /**
+   * Constructor which takes a File and invokes the GISModelReader appropriate
+   * for the suffix.
+   * 
+   * @param f
+   *          The File in which the model is stored.
+   */
+  public SuffixSensitiveGISModelReader(File f) throws IOException {
+    super(f);
+  }
     
-    // activate this if adding another type of reader which can't read model
-    // information in the way that the default getModel() method in
-    // GISModelReader does.
-    //public GISModel getModel () throws java.io.IOException {
-    //    return suffixAppropriateReader.getModel();
-    //}
-    
-
-    /**
-     * To convert between different formats of the new style.
-     * 
-     * <p>java opennlp.maxent.io.SuffixSensitiveGISModelReader old_model_name new_model_name
-     * 
-     * <p>For example, to convert a model called "model.bin.gz" (which is thus
-     * saved in gzipped binary format) to one in (unzipped) text format:
-     * 
-     * <p>java opennlp.maxent.io.SuffixSensitiveGISModelReader model.bin.gz model.txt
-     * 
-     * <p>This particular example would of course be useful when you generally
-     * want to create models which take up less space (.bin.gz), but want to
-     * be able to inspect a few of them as plain text files.
-     */
-    public static void main(String[] args) throws IOException {
-      AbstractModel m =  new SuffixSensitiveGISModelReader(new File(args[0])).getModel();
-      new SuffixSensitiveGISModelWriter( m, new File(args[1])).persist();
-    }
+  // activate this if adding another type of reader which can't read model
+  // information in the way that the default getModel() method in
+  // GISModelReader does.
+  //public GISModel getModel () throws java.io.IOException {
+  //    return suffixAppropriateReader.getModel();
+  //}
 
+  /**
+   * To convert between different formats of the new style.
+   * 
+   * <p>
+   * java opennlp.maxent.io.SuffixSensitiveGISModelReader old_model_name
+   * new_model_name
+   * 
+   * <p>
+   * For example, to convert a model called "model.bin.gz" (which is thus saved
+   * in gzipped binary format) to one in (unzipped) text format:
+   * 
+   * <p>
+   * java opennlp.maxent.io.SuffixSensitiveGISModelReader model.bin.gz model.txt
+   * 
+   * <p>
+   * This particular example would of course be useful when you generally want
+   * to create models which take up less space (.bin.gz), but want to be able to
+   * inspect a few of them as plain text files.
+   */
+  public static void main(String[] args) throws IOException {
+    AbstractModel m = new SuffixSensitiveGISModelReader(new File(args[0]))
+        .getModel();
+    new SuffixSensitiveGISModelWriter(m, new File(args[1])).persist();
+  }
 }