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:11:16 UTC

svn commit: r1063313 - in /incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model: ComparableEvent.java EventCollector.java EventCollectorAsStream.java IndexHashTable.java OnePassDataIndexer.java Sequence.java

Author: joern
Date: Tue Jan 25 15:11:15 2011
New Revision: 1063313

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

Modified:
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/ComparableEvent.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollector.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollectorAsStream.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/IndexHashTable.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/OnePassDataIndexer.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Sequence.java

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/ComparableEvent.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/ComparableEvent.java?rev=1063313&r1=1063312&r2=1063313&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/ComparableEvent.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/ComparableEvent.java Tue Jan 25 15:11:15 2011
@@ -26,87 +26,95 @@ import java.util.Arrays;
  * predicates indexes contained in the events.
  */
 public class ComparableEvent implements Comparable {
-    public int outcome;
-    public int[] predIndexes;
-    public int seen = 1;            // the number of times this event
-                                    // has been seen.
-
-    public float[] values;
-    
-    public ComparableEvent(int oc, int[] pids, float[] values) {
-        outcome = oc;
-        if (values == null) {
-          Arrays.sort(pids);
-        }
-        else {
-          sort(pids,values);
-        }
-        this.values = values; //needs to be sorted like pids
-        predIndexes = pids;
+  public int outcome;
+  public int[] predIndexes;
+  public int seen = 1; // the number of times this event
+                       // has been seen.
+
+  public float[] values;
+
+  public ComparableEvent(int oc, int[] pids, float[] values) {
+    outcome = oc;
+    if (values == null) {
+      Arrays.sort(pids);
+    } else {
+      sort(pids, values);
     }
-    
-    public ComparableEvent(int oc, int[] pids) {
-      this(oc,pids,null);
+    this.values = values; // needs to be sorted like pids
+    predIndexes = pids;
+  }
+
+  public ComparableEvent(int oc, int[] pids) {
+    this(oc, pids, null);
+  }
+
+  public int compareTo(Object o) {
+    ComparableEvent ce = (ComparableEvent) o;
+    if (outcome < ce.outcome)
+      return -1;
+    else if (outcome > ce.outcome)
+      return 1;
+
+    int smallerLength = (predIndexes.length > ce.predIndexes.length ? ce.predIndexes.length
+        : predIndexes.length);
+
+    for (int i = 0; i < smallerLength; i++) {
+      if (predIndexes[i] < ce.predIndexes[i])
+        return -1;
+      else if (predIndexes[i] > ce.predIndexes[i])
+        return 1;
+      if (values != null && ce.values != null) {
+        if (values[i] < ce.values[i])
+          return -1;
+        else if (values[i] > ce.values[i])
+          return 1;
+      } else if (values != null) {
+        if (values[i] < 1)
+          return -1;
+        else if (values[i] > 1)
+          return 1;
+      } else if (ce.values != null) {
+        if (1 < ce.values[i])
+          return -1;
+        else if (1 > ce.values[i])
+          return 1;
+      }
     }
 
-    public int compareTo(Object o) {
-        ComparableEvent ce = (ComparableEvent)o;
-        if (outcome < ce.outcome) return -1;
-        else if (outcome > ce.outcome) return 1;
-	
-        int smallerLength = (predIndexes.length > ce.predIndexes.length?
-                             ce.predIndexes.length : predIndexes.length);
-
-        for (int i=0; i<smallerLength; i++) {
-            if (predIndexes[i] < ce.predIndexes[i]) return -1;
-            else if (predIndexes[i] > ce.predIndexes[i]) return 1;
-            if (values != null && ce.values != null) {
-              if (values[i] < ce.values[i]) return -1;
-              else if (values[i] > ce.values[i]) return 1;
-            }
-            else if (values != null) {
-              if (values[i] < 1)  return -1;
-              else if (values[i] > 1) return 1;
-            }
-            else if (ce.values != null) {
-              if (1 < ce.values[i]) return -1;
-              else if (1 > ce.values[i]) return 1;
-            }
-        }
-
-
-        if (predIndexes.length < ce.predIndexes.length) return -1;
-        else if (predIndexes.length > ce.predIndexes.length) return 1;
-
-        return 0;
+    if (predIndexes.length < ce.predIndexes.length)
+      return -1;
+    else if (predIndexes.length > ce.predIndexes.length)
+      return 1;
+
+    return 0;
+  }
+
+  public String toString() {
+    StringBuffer s = new StringBuffer().append(outcome).append(":");
+    for (int i = 0; i < predIndexes.length; i++) {
+      s.append(" ").append(predIndexes[i]);
+      if (values != null) {
+        s.append("=").append(values[i]);
+      }
     }
+    return s.toString();
+  }
 
-    public String toString() {
-        StringBuffer s = new StringBuffer().append(outcome).append(":");
-        for (int i=0; i<predIndexes.length; i++) {
-          s.append(" ").append(predIndexes[i]);
-          if (values != null) {
-            s.append("=").append(values[i]);
-          }
-        }
-        return s.toString();
-    }
-    
-    private void sort(int[] pids, float[] values) {
-      for (int mi=0;mi<pids.length;mi++) {
-        int min = mi;
-        for (int pi=mi+1;pi<pids.length;pi++) {
-          if (pids[min] > pids[pi]) {
-            min = pi;
-          }
+  private void sort(int[] pids, float[] values) {
+    for (int mi = 0; mi < pids.length; mi++) {
+      int min = mi;
+      for (int pi = mi + 1; pi < pids.length; pi++) {
+        if (pids[min] > pids[pi]) {
+          min = pi;
         }
-        int pid = pids[mi];
-        pids[mi] = pids[min];
-        pids[min] = pid;
-        float val = values[mi];
-        values[mi] = values[min];
-        values[min] = val;
       }
+      int pid = pids[mi];
+      pids[mi] = pids[min];
+      pids[min] = pid;
+      float val = values[mi];
+      values[mi] = values[min];
+      values[min] = val;
     }
+  }
 }
  

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollector.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollector.java?rev=1063313&r1=1063312&r2=1063313&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollector.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollector.java Tue Jan 25 15:11:15 2011
@@ -24,22 +24,22 @@ package opennlp.model;
  */
 public interface EventCollector {
 
-    /**
-     * Return the events which this EventCollector has gathered.  It must get
-     * its data from a constructor.
-     *
-     * @return the events that this EventCollector has gathered
-     */
-    public Event[] getEvents();
+  /**
+   * Return the events which this EventCollector has gathered. It must get its
+   * data from a constructor.
+   * 
+   * @return the events that this EventCollector has gathered
+   */
+  public Event[] getEvents();
 
-    /**
-     * Return the events which this EventCollector has gathered based on
-     * whether we wish to train a model or evaluate one based on those
-     * events.
-     * 
-     * @param evalMode true if we are evaluating based on the events, false if
-     *                 we are training.
-     * @return the events that this EventCollector has gathered
-     */
-    public Event[] getEvents(boolean evalMode);
+  /**
+   * Return the events which this EventCollector has gathered based on whether
+   * we wish to train a model or evaluate one based on those events.
+   * 
+   * @param evalMode
+   *          true if we are evaluating based on the events, false if we are
+   *          training.
+   * @return the events that this EventCollector has gathered
+   */
+  public Event[] getEvents(boolean evalMode);
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollectorAsStream.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollectorAsStream.java?rev=1063313&r1=1063312&r2=1063313&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollectorAsStream.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/EventCollectorAsStream.java Tue Jan 25 15:11:15 2011
@@ -26,21 +26,21 @@ package opennlp.model;
  * application to work with Maxent 1.2 with very little recoding.
  */
 public final class EventCollectorAsStream extends AbstractEventStream {
-    final Event[] events;
-    final int numEvents;
-    int index = 0;
-    
-    public EventCollectorAsStream (EventCollector ec) {
-	events = ec.getEvents(false);
-	numEvents = events.length;
-    }
-    
-    public Event next () {
-      return events[index++];
-    }
-    
-    public boolean hasNext () {
-      return (index < numEvents);
-    }
- 
+  final Event[] events;
+  final int numEvents;
+  int index = 0;
+
+  public EventCollectorAsStream(EventCollector ec) {
+    events = ec.getEvents(false);
+    numEvents = events.length;
+  }
+
+  public Event next() {
+    return events[index++];
+  }
+
+  public boolean hasNext() {
+    return (index < numEvents);
+  }
+
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/IndexHashTable.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/IndexHashTable.java?rev=1063313&r1=1063312&r2=1063313&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/IndexHashTable.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/IndexHashTable.java Tue Jan 25 15:11:15 2011
@@ -36,110 +36,111 @@ package opennlp.model;
  */
 public class IndexHashTable<T> {
 
-	private final Object keys[];
-	private final int values[];
-	
-	private final int size;
-	
-	/**
-	 * Initializes the current instance. The specified array is copied
-	 * into the table and later changes to the array do not affect this
-	 * table in any way. 
-	 * 
-	 * @param mapping the values to be indexed, all values must be unique otherwise
-	 * a well-defined mapping of an entry to an index is not possible
-	 * @param loadfactor the load factor, usually 0.7
-	 * 
-	 * @throws IllegalArgumentException if the entries are not unique
-	 */
-	public IndexHashTable(T mapping[], double loadfactor) {
-		if (loadfactor <= 0 || loadfactor > 1)
-			throw new IllegalArgumentException("loadfactor must be larger than 0 " +
-					"and equal to or smaller than 1!");
-		
-		int arraySize = (int) (mapping.length / loadfactor) + 1;
-		
-		keys = new Object[arraySize];
-		values = new int[arraySize];
-		
-		size = mapping.length;
-		
-		for (int i = 0; i < mapping.length; i++) {
-			int startIndex = indexForHash(mapping[i].hashCode(), keys.length);
-			
-			int index = searchKey(startIndex, null, true);
-			
-			if (index == -1)
-				throw new IllegalArgumentException("Array must contain only unique keys!");
-			
-			keys[index] = mapping[i];
-			values[index] = i;
-		}
-	}
-	
-	private static int indexForHash(int h, int length) {
-		return (h & 0x7fffffff) % length;
-	}
-	
-	private int searchKey(int startIndex, Object key, boolean insert) {
-		
-		
-		for (int index = startIndex; true; index = (index+1) % keys.length) {
-			
-			// The keys array contains at least one null element, which guarantees
-			// termination of the loop
-			if (keys[index] == null) {
-				if (insert)
-					return index;
-				else
-					return -1;
-			}
-			
-			if (keys[index].equals(key)) {
-				if (!insert)
-					return index;
-				else
-					return -1;
-			}
-		}
-	}
-	
-	/**
-	 * Retrieves the index for the specified key.
-	 * 
-	 * @param key 
-	 * @return the index or -1 if there is no entry to the keys
-	 */
-	public int get(T key) {
-		
-		int startIndex = indexForHash(key.hashCode(), keys.length);
-			
-		int index = searchKey(startIndex, key, false);
-		
-		if (index != -1) {
-			return values[index];
-		}
-		else {
-			return -1;
-		}
-	}
-	
-	/**
-	 * Retrieves the size.
-	 * 
-	 * @return the number of elements in this map.
-	 */
-	public int size() {
-		return size;
-	}
+  private final Object keys[];
+  private final int values[];
+
+  private final int size;
 	
-	@SuppressWarnings("unchecked")
-	public T[] toArray(T array[]) {
-		for (int i = 0; i < keys.length; i++) {
-			if (keys[i] != null)
-				array[values[i]] = (T) keys[i];
-		}
+  /**
+   * Initializes the current instance. The specified array is copied into the
+   * table and later changes to the array do not affect this table in any way.
+   * 
+   * @param mapping
+   *          the values to be indexed, all values must be unique otherwise a
+   *          well-defined mapping of an entry to an index is not possible
+   * @param loadfactor
+   *          the load factor, usually 0.7
+   * 
+   * @throws IllegalArgumentException
+   *           if the entries are not unique
+   */
+  public IndexHashTable(T mapping[], double loadfactor) {
+    if (loadfactor <= 0 || loadfactor > 1)
+      throw new IllegalArgumentException("loadfactor must be larger than 0 "
+          + "and equal to or smaller than 1!");
+
+    int arraySize = (int) (mapping.length / loadfactor) + 1;
+
+    keys = new Object[arraySize];
+    values = new int[arraySize];
+
+    size = mapping.length;
+
+    for (int i = 0; i < mapping.length; i++) {
+      int startIndex = indexForHash(mapping[i].hashCode(), keys.length);
+
+      int index = searchKey(startIndex, null, true);
+
+      if (index == -1)
+        throw new IllegalArgumentException(
+            "Array must contain only unique keys!");
+
+      keys[index] = mapping[i];
+      values[index] = i;
+    }
+  }
+
+  private static int indexForHash(int h, int length) {
+    return (h & 0x7fffffff) % length;
+  }
+
+  private int searchKey(int startIndex, Object key, boolean insert) {
 		
-		return array;
-	}
+    for (int index = startIndex; true; index = (index + 1) % keys.length) {
+
+      // The keys array contains at least one null element, which guarantees
+      // termination of the loop
+      if (keys[index] == null) {
+        if (insert)
+          return index;
+        else
+          return -1;
+      }
+
+      if (keys[index].equals(key)) {
+        if (!insert)
+          return index;
+        else
+          return -1;
+      }
+    }
+  }
+
+  /**
+   * Retrieves the index for the specified key.
+   * 
+   * @param key
+   * @return the index or -1 if there is no entry to the keys
+   */
+  public int get(T key) {
+
+    int startIndex = indexForHash(key.hashCode(), keys.length);
+
+    int index = searchKey(startIndex, key, false);
+
+    if (index != -1) {
+      return values[index];
+    } else {
+      return -1;
+    }
+  }
+
+  /**
+   * Retrieves the size.
+   * 
+   * @return the number of elements in this map.
+   */
+  public int size() {
+    return size;
+  }
+
+  @SuppressWarnings("unchecked")
+  public T[] toArray(T array[]) {
+    for (int i = 0; i < keys.length; i++) {
+      if (keys[i] != null)
+        array[values[i]] = (T) keys[i];
+    }
+
+    return array;
+  }
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/OnePassDataIndexer.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/OnePassDataIndexer.java?rev=1063313&r1=1063312&r2=1063313&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/OnePassDataIndexer.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/OnePassDataIndexer.java Tue Jan 25 15:11:15 2011
@@ -30,142 +30,149 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-
 /**
  * An indexer for maxent model data which handles cutoffs for uncommon
  * contextual predicates and provides a unique integer index for each of the
- * predicates. 
+ * predicates.
  */
-public class OnePassDataIndexer extends AbstractDataIndexer  {
-
-    /**
-     * One argument constructor for DataIndexer which calls the two argument
-     * constructor assuming no cutoff.
-     *
-     * @param eventStream An Event[] which contains the a list of all the Events
-     *               seen in the training data.
-     */     
-    public OnePassDataIndexer(EventStream eventStream) throws IOException {
-        this(eventStream, 0);
-    }
+public class OnePassDataIndexer extends AbstractDataIndexer {
 
-    public OnePassDataIndexer(EventStream eventStream, int cutoff) throws IOException {
-      this(eventStream,cutoff,true);
+  /**
+   * One argument constructor for DataIndexer which calls the two argument
+   * constructor assuming no cutoff.
+   * 
+   * @param eventStream
+   *          An Event[] which contains the a list of all the Events seen in the
+   *          training data.
+   */
+  public OnePassDataIndexer(EventStream eventStream) throws IOException {
+    this(eventStream, 0);
+  }
+
+  public OnePassDataIndexer(EventStream eventStream, int cutoff)
+      throws IOException {
+    this(eventStream, cutoff, true);
+  }
+
+  /**
+   * Two argument constructor for DataIndexer.
+   * 
+   * @param eventStream
+   *          An Event[] which contains the a list of all the Events seen in the
+   *          training data.
+   * @param cutoff
+   *          The minimum number of times a predicate must have been observed in
+   *          order to be included in the model.
+   */
+  public OnePassDataIndexer(EventStream eventStream, int cutoff, boolean sort)
+      throws IOException {
+    Map<String, Integer> predicateIndex = new HashMap<String, Integer>();
+    LinkedList<Event> events;
+    List eventsToCompare;
+
+    System.out.println("Indexing events using cutoff of " + cutoff + "\n");
+
+    System.out.print("\tComputing event counts...  ");
+    events = computeEventCounts(eventStream, predicateIndex, cutoff);
+    System.out.println("done. " + events.size() + " events");
+
+    System.out.print("\tIndexing...  ");
+    eventsToCompare = index(events, predicateIndex);
+    // done with event list
+    events = null;
+    // done with predicates
+    predicateIndex = null;
+
+    System.out.println("done.");
+
+    System.out.print("Sorting and merging events... ");
+    sortAndMerge(eventsToCompare, sort);
+    System.out.println("Done indexing.");
+  }
+
+  /**
+   * Reads events from <tt>eventStream</tt> into a linked list. The predicates
+   * associated with each event are counted and any which occur at least
+   * <tt>cutoff</tt> times are added to the <tt>predicatesInOut</tt> map along
+   * with a unique integer index.
+   * 
+   * @param eventStream
+   *          an <code>EventStream</code> value
+   * @param predicatesInOut
+   *          a <code>TObjectIntHashMap</code> value
+   * @param cutoff
+   *          an <code>int</code> value
+   * @return a <code>TLinkedList</code> value
+   */
+  private LinkedList<Event> computeEventCounts(EventStream eventStream,
+      Map<String, Integer> predicatesInOut, int cutoff) throws IOException {
+    Set predicateSet = new HashSet();
+    Map<String, Integer> counter = new HashMap<String, Integer>();
+    LinkedList<Event> events = new LinkedList<Event>();
+    while (eventStream.hasNext()) {
+      Event ev = eventStream.next();
+      events.addLast(ev);
+      update(ev.getContext(), predicateSet, counter, cutoff);
     }
-    /**
-     * Two argument constructor for DataIndexer.
-     *
-     * @param eventStream An Event[] which contains the a list of all the Events
-     *               seen in the training data.
-     * @param cutoff The minimum number of times a predicate must have been
-     *               observed in order to be included in the model.
-     */
-    public OnePassDataIndexer(EventStream eventStream, int cutoff, boolean sort) throws IOException {
-        Map<String,Integer> predicateIndex = new HashMap<String,Integer>();
-        LinkedList<Event> events;
-        List eventsToCompare;
-
-        System.out.println("Indexing events using cutoff of " + cutoff + "\n");
-
-        System.out.print("\tComputing event counts...  ");
-        events = computeEventCounts(eventStream,predicateIndex,cutoff);
-        System.out.println("done. "+events.size()+" events");
-
-        System.out.print("\tIndexing...  ");
-        eventsToCompare = index(events,predicateIndex);
-        // done with event list
-        events = null;
-        // done with predicates
-        predicateIndex = null;
-
-        System.out.println("done.");
-
-        System.out.print("Sorting and merging events... ");
-        sortAndMerge(eventsToCompare,sort);
-        System.out.println("Done indexing.");
+    predCounts = new int[predicateSet.size()];
+    int index = 0;
+    for (Iterator pi = predicateSet.iterator(); pi.hasNext(); index++) {
+      String predicate = (String) pi.next();
+      predCounts[index] = counter.get(predicate);
+      predicatesInOut.put(predicate, index);
     }
+    return events;
+  }
 
-
-    
-    /**
-     * Reads events from <tt>eventStream</tt> into a linked list.  The
-     * predicates associated with each event are counted and any which
-     * occur at least <tt>cutoff</tt> times are added to the
-     * <tt>predicatesInOut</tt> map along with a unique integer index.
-     *
-     * @param eventStream an <code>EventStream</code> value
-     * @param predicatesInOut a <code>TObjectIntHashMap</code> value
-     * @param cutoff an <code>int</code> value
-     * @return a <code>TLinkedList</code> value
-     */
-    private LinkedList<Event> computeEventCounts(EventStream eventStream,Map<String,Integer> predicatesInOut,
-        int cutoff) throws IOException {
-      Set predicateSet = new HashSet();
-      Map<String,Integer> counter = new HashMap<String,Integer>();
-      LinkedList<Event> events = new LinkedList<Event>();
-      while (eventStream.hasNext()) {
-        Event ev = eventStream.next();
-        events.addLast(ev);
-        update(ev.getContext(),predicateSet,counter,cutoff);
-      }
-      predCounts = new int[predicateSet.size()];
-      int index = 0;
-      for (Iterator pi=predicateSet.iterator();pi.hasNext();index++) {
-        String predicate = (String) pi.next();
-        predCounts[index] = counter.get(predicate);
-        predicatesInOut.put(predicate,index);
+  protected List index(LinkedList<Event> events,
+      Map<String, Integer> predicateIndex) {
+    Map<String, Integer> omap = new HashMap<String, Integer>();
+
+    int numEvents = events.size();
+    int outcomeCount = 0;
+    List eventsToCompare = new ArrayList(numEvents);
+    List<Integer> indexedContext = new ArrayList<Integer>();
+
+    for (int eventIndex = 0; eventIndex < numEvents; eventIndex++) {
+      Event ev = (Event) events.removeFirst();
+      String[] econtext = ev.getContext();
+      ComparableEvent ce;
+
+      int ocID;
+      String oc = ev.getOutcome();
+
+      if (omap.containsKey(oc)) {
+        ocID = omap.get(oc);
+      } else {
+        ocID = outcomeCount++;
+        omap.put(oc, ocID);
       }
-      return events;
-    }
 
-    protected List index(LinkedList<Event> events, Map<String,Integer> predicateIndex) {
-        Map<String,Integer> omap = new HashMap<String,Integer>();
+      for (int i = 0; i < econtext.length; i++) {
+        String pred = econtext[i];
+        if (predicateIndex.containsKey(pred)) {
+          indexedContext.add(predicateIndex.get(pred));
+        }
+      }
 
-        int numEvents = events.size();
-        int outcomeCount = 0;
-        List eventsToCompare = new ArrayList(numEvents);
-        List<Integer> indexedContext = new ArrayList<Integer>();
-
-        for (int eventIndex=0; eventIndex<numEvents; eventIndex++) {
-            Event ev = (Event)events.removeFirst();
-            String[] econtext = ev.getContext();
-            ComparableEvent ce;
-	    
-            int ocID;
-            String oc = ev.getOutcome();
-	    
-            if (omap.containsKey(oc)) {
-                ocID = omap.get(oc);
-            } else {
-                ocID = outcomeCount++;
-                omap.put(oc, ocID);
-            }
-
-            for (int i=0; i<econtext.length; i++) {
-                String pred = econtext[i];
-                if (predicateIndex.containsKey(pred)) {
-                    indexedContext.add(predicateIndex.get(pred));
-                }
-            }
-
-            // drop events with no active features
-            if (indexedContext.size() > 0) {
-                int[] cons = new int[indexedContext.size()];
-                for (int ci=0;ci<cons.length;ci++) {
-                  cons[ci] = indexedContext.get(ci);
-                }
-                ce = new ComparableEvent(ocID, cons);
-                eventsToCompare.add(ce);
-            }
-            else {
-              System.err.println("Dropped event "+ev.getOutcome()+":"+Arrays.asList(ev.getContext()));
-            }
-            // recycle the TIntArrayList
-            indexedContext.clear();
+      // drop events with no active features
+      if (indexedContext.size() > 0) {
+        int[] cons = new int[indexedContext.size()];
+        for (int ci = 0; ci < cons.length; ci++) {
+          cons[ci] = indexedContext.get(ci);
         }
-        outcomeLabels = toIndexedStringArray(omap);
-        predLabels = toIndexedStringArray(predicateIndex);
-        return eventsToCompare;
+        ce = new ComparableEvent(ocID, cons);
+        eventsToCompare.add(ce);
+      } else {
+        System.err.println("Dropped event " + ev.getOutcome() + ":"
+            + Arrays.asList(ev.getContext()));
+      }
+      // recycle the TIntArrayList
+      indexedContext.clear();
     }
-    
+    outcomeLabels = toIndexedStringArray(omap);
+    predLabels = toIndexedStringArray(predicateIndex);
+    return eventsToCompare;
+  }
+
 }

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Sequence.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Sequence.java?rev=1063313&r1=1063312&r2=1063313&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Sequence.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Sequence.java Tue Jan 25 15:11:15 2011
@@ -25,35 +25,40 @@ package opennlp.model;
  */
 public class Sequence<T> {
 
-	private Event[] events;
-	private T source;
-	
-	/**
-	 * Creates a new sequence made up of the specified events and derived from
-	 * the specified source.
-	 * @param events The events of the sequence.
-	 * @param source The source object for this sequence.
-	 */
-	public Sequence(Event[] events, T source) {
-		this.events = events;
-		this.source = source;
-	}
-	
-	/**
-	 * Returns the events which make up this sequence.
-	 * @return the events which make up this sequence.
-	 */
-	public Event[] getEvents() {
-		return events;
-	}
-	
-	/**
-	 * Returns an object from which this sequence can be derived.
-	 * This object is used when the events for this sequence need to be
-	 * re-derived such as in a call to SequenceStream.updateContext. 
-	 * @return an object from which this sequence can be derived.
-	 */
-	public T getSource() {
-		return source;
-	}
+  private Event[] events;
+  private T source;
+
+  /**
+   * Creates a new sequence made up of the specified events and derived from the
+   * specified source.
+   * 
+   * @param events
+   *          The events of the sequence.
+   * @param source
+   *          The source object for this sequence.
+   */
+  public Sequence(Event[] events, T source) {
+    this.events = events;
+    this.source = source;
+  }
+
+  /**
+   * Returns the events which make up this sequence.
+   * 
+   * @return the events which make up this sequence.
+   */
+  public Event[] getEvents() {
+    return events;
+  }
+
+  /**
+   * Returns an object from which this sequence can be derived. This object is
+   * used when the events for this sequence need to be re-derived such as in a
+   * call to SequenceStream.updateContext.
+   * 
+   * @return an object from which this sequence can be derived.
+   */
+  public T getSource() {
+    return source;
+  }
 }