de.fu_berlin.ties.eval
Class LineShuffleGenerator

java.lang.Object
  extended by de.fu_berlin.ties.ConfigurableProcessor
      extended by de.fu_berlin.ties.TextProcessor
          extended by de.fu_berlin.ties.eval.LineShuffleGenerator
All Implemented Interfaces:
Processor

public class LineShuffleGenerator
extends TextProcessor

Randomly reshuffles the lines in a file (except for the first n lines, if configured).

Version:
$Revision: 1.4 $, $Date: 2006/10/21 16:04:11 $, $Author: siefkes $
Author:
Christian Siefkes

Field Summary
 
Fields inherited from class de.fu_berlin.ties.TextProcessor
CONFIG_POST, KEY_DIRECTORY, KEY_LOCAL_NAME, KEY_OUT_DIRECTORY, KEY_URL
 
Constructor Summary
LineShuffleGenerator(String outExt)
          Creates a new instance from the standard configuration.
LineShuffleGenerator(String outExt, int ignoredLines, TiesConfiguration conf)
          Creates a new instance.
LineShuffleGenerator(String outExt, TiesConfiguration conf)
          Creates a new instance from the provided configuration.
 
Method Summary
protected  void doProcess(Reader reader, Writer writer, ContextMap context)
          Processes the contents of a reader, writing a modified version to a writer. This implementation delegates to the static shuffleLines(Reader, Writer, int) method, using the configured number of lines to ignore.
protected static void shuffleLines(Reader reader, Writer writer, int ignoreFirst)
          Randomly reshuffles the lines in a file (except for the first ignoreFirst lines).
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class de.fu_berlin.ties.TextProcessor
getOutFileExt, process, process, process, process, process, process
 
Methods inherited from class de.fu_berlin.ties.ConfigurableProcessor
getConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LineShuffleGenerator

public LineShuffleGenerator(String outExt)
Creates a new instance from the standard configuration.

Parameters:
outExt - the extension to use for output files

LineShuffleGenerator

public LineShuffleGenerator(String outExt,
                            TiesConfiguration conf)
Creates a new instance from the provided configuration.

Parameters:
outExt - the extension to use for output files
conf - used to configure this instance; must not be null

LineShuffleGenerator

public LineShuffleGenerator(String outExt,
                            int ignoredLines,
                            TiesConfiguration conf)
Creates a new instance.

Parameters:
outExt - the extension to use for output files
ignoredLines - the number of lines at the start of a file that should be ignored, if any; must be 0 or positive
conf - passed to the superclass; if null, the standard configuration is used
Method Detail

shuffleLines

protected static void shuffleLines(Reader reader,
                                   Writer writer,
                                   int ignoreFirst)
                            throws IllegalArgumentException,
                                   IOException
Randomly reshuffles the lines in a file (except for the first ignoreFirst lines).

Parameters:
reader - reader containing the text to process; not closed by this method
writer - the writer to write the processed text to; flushed but not closed by this method
ignoreFirst - the number of lines at the start of a file that should be ignored, if any; must be 0 or positive
Throws:
IllegalArgumentException - if ignoreFirst is negative
IOException - if an I/O error occurs while reading or writing

doProcess

protected void doProcess(Reader reader,
                         Writer writer,
                         ContextMap context)
                  throws IOException
Processes the contents of a reader, writing a modified version to a writer. This implementation delegates to the static shuffleLines(Reader, Writer, int) method, using the configured number of lines to ignore.

Specified by:
doProcess in class TextProcessor
Parameters:
reader - reader containing the text to process; should not be closed by this method
writer - the writer to write the processed text to; might be flushed but not closed by this method; if this method does not use the writer, the underlying file will be deleted afterwards
context - a map of objects that are made available for processing; when called from the implemented process methods in this class, it will contain mappings from IOUtils.KEY_LOCAL_CHARSET to the character set of the output writer; from TextProcessor.KEY_OUT_DIRECTORY to the output directory (File); from ContentType.KEY_MIME_TYPE to the document's MIME type; from TextProcessor.KEY_LOCAL_NAME to the local name (String) and either from TextProcessor.KEY_DIRECTORY to the input directory (File), in case of a local file) or from TextProcessor.KEY_URL to the URL (otherwise) of the processed document
Throws:
IOException - if an I/O error occurs

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class TextProcessor
Returns:
a textual representation


Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.