001 package calhoun.analysis.crf.io;
002
003 import java.util.Iterator;
004
005 /** utility class to convert an iterator over training sequences into an iterator over the underlying
006 * input sequences
007 * @param <T> the type of the underlying input sequence
008 */
009 public class IteratorAdapterTrainingSequenceInput<T> implements Iterator<InputSequence<? extends T>> {
010
011 Iterator<? extends TrainingSequence<T>> trainingIterator;
012
013 /** constructs a new iterator which will extract the input sequence from the training sequences
014 * @param trainingIterator the iterator over training sequences to extract the input sequence from
015 */
016 public IteratorAdapterTrainingSequenceInput(Iterator<? extends TrainingSequence<T>> trainingIterator) {
017 this.trainingIterator = trainingIterator;
018 }
019
020 public boolean hasNext() {
021 return trainingIterator.hasNext();
022 }
023
024 public InputSequence<? extends T> next() {
025 TrainingSequence<T> trainingSeq = trainingIterator.next();
026 return trainingSeq.getInputSequence();
027 }
028
029 public void remove() {
030 throw new UnsupportedOperationException();
031 }
032 }