cs132.markov
Class Words

java.lang.Object
  extended by cs132.markov.Words

public class Words
extends java.lang.Object

This class provides static utility methods for coverting text files to a list of words, and for printing a iterator of words in a nicely formatted manner.


Method Summary
static void addWords(java.io.Reader in, java.util.List<java.lang.String> words)
          Given an Reader, read text from it, break up according to white space, and add each word to the List passed as an argument.
static java.util.Iterator<java.lang.String> characters(java.util.Iterator<java.lang.String> wordIterator)
          Given an Iterator over words, return an Iterator over the characters in the words, adding Strings consisting of a single space to separate the words.
static void printCharacters(java.util.Iterator<java.lang.String> characters, int maxColumn, int maxCharacters)
          Given an iterator over characters, print the words with word wrapping to fit within the specified number of columns.
static void printCharacters(java.util.Iterator<java.lang.String> characters, int maxColumn, int maxCharacters, java.io.PrintStream out)
          Provides the same functionality as printCharacters(Iterator, int, int), except that is allows a PrintStream to be specified, so that output can be sent to a file.
static void printWords(java.util.Iterator<java.lang.String> words, int maxColumn, int maxWords)
          Given an iterator over words, print the words with word wrapping to fit within the specified number of columns.
static void printWords(java.util.Iterator<java.lang.String> words, int maxColumn, int maxWords, java.io.PrintStream out)
          Provides the same functionality as printWords(Iterator, int, int), except that is allows a PrintStream to be specified, so that output can be sent to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addWords

public static void addWords(java.io.Reader in,
                            java.util.List<java.lang.String> words)
                     throws java.io.IOException
Given an Reader, read text from it, break up according to white space, and add each word to the List passed as an argument. Blank lines are added a the String as "\n", but otherwise white space is not added to the list.

Parameters:
in - InputStream to read from
words - List to append to
Throws:
java.io.IOException
java.lang.Exception

characters

public static java.util.Iterator<java.lang.String> characters(java.util.Iterator<java.lang.String> wordIterator)
Given an Iterator over words, return an Iterator over the characters in the words, adding Strings consisting of a single space to separate the words.

Parameters:
wordIterator - Iterator over words
Returns:
Iterator over characters

printCharacters

public static void printCharacters(java.util.Iterator<java.lang.String> characters,
                                   int maxColumn,
                                   int maxCharacters)
Given an iterator over characters, print the words with word wrapping to fit within the specified number of columns. The number of characters is capped at the specified number if the Iterator does not end sooner. If a paragraph break is seen at a point where less than 500 addition characters are allowed, the printing is stopped at that point.

Parameters:
characters - iterator over characters to print
maxColumn - maximum number of characters per line
maxCharacters - maximum number of words

printCharacters

public static void printCharacters(java.util.Iterator<java.lang.String> characters,
                                   int maxColumn,
                                   int maxCharacters,
                                   java.io.PrintStream out)
Provides the same functionality as printCharacters(Iterator, int, int), except that is allows a PrintStream to be specified, so that output can be sent to a file.


printWords

public static void printWords(java.util.Iterator<java.lang.String> words,
                              int maxColumn,
                              int maxWords)
Given an iterator over words, print the words with word wrapping to fit within the specified number of columns. The number of words is capped at the specified number if the Iterator does not end sooner. If a paragraph break is seen at a point where less than 100 addition words are allowed, the printing is stopped at that point (to try to get the generated story to end at a paragraph break).

Parameters:
words - iterator over words to print
maxColumn - maximum number of characters per line
maxWords - maximum number of words

printWords

public static void printWords(java.util.Iterator<java.lang.String> words,
                              int maxColumn,
                              int maxWords,
                              java.io.PrintStream out)
Provides the same functionality as printWords(Iterator, int, int), except that is allows a PrintStream to be specified, so that output can be sent to a file.