Class MadlibBlanker

java.lang.Object
madlibgeneration.MadlibBlanker

class MadlibBlanker extends Object
Processes Madlib through the "blanking" process, which takes the madlib's source text and blanks out certain words to be filled in later by the user.
Author:
Adam Barnett
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Map<String,String>
    Reference to Madlib's pos list to verify correct blanking of word.
    private static final Set<String>
    Identifies where in the text file the words should be replaced with the user's new words
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    justWriteWord(edu.stanford.nlp.ling.CoreLabel token, BufferedWriter writer, boolean isFirstWord)
    Helper method for removeMadlibifiable() that writes each word to a file with a preceding space.
    removeMadlibifiables(String filepath, TextAnnotater annotatedText, int skipper)
    Removes the skipper-th word with a part of speech in the posBlocks hashset
    private void
    replaceWordWithBlock(boolean isFirstWord, BufferedWriter writer, String replacementBlock)
    Like justWriteWord but handles Strings instead of tokens to print the part of speech returned by the part of speech map inside square brackets

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • wordsToSkip

      private static final Set<String> wordsToSkip
      Identifies where in the text file the words should be replaced with the user's new words
    • posMap

      private static final Map<String,String> posMap
      Reference to Madlib's pos list to verify correct blanking of word. This is important in case the source text already has words within square brackets
  • Constructor Details

    • MadlibBlanker

      MadlibBlanker()
  • Method Details

    • removeMadlibifiables

      public List<String> removeMadlibifiables(String filepath, TextAnnotater annotatedText, int skipper) throws IOException, utility.exceptions.TextNotProcessedException
      Removes the skipper-th word with a part of speech in the posBlocks hashset
      Parameters:
      skipper - determines the frequency of madlibification (replacement of word with part-of-speech text block). Example: if skipper == 3, removeMadlibifiables will clear every third madlibifiable word
      Returns:
      returns List of parts of speech removed so user can replace the removed words when prompted by CLI
      Throws:
      IOException
      utility.exceptions.TextNotProcessedException
      See Also:
    • replaceWordWithBlock

      private void replaceWordWithBlock(boolean isFirstWord, BufferedWriter writer, String replacementBlock) throws IOException, utility.exceptions.InvalidPartOfSpeechException
      Like justWriteWord but handles Strings instead of tokens to print the part of speech returned by the part of speech map inside square brackets
      Throws:
      IOException
      utility.exceptions.InvalidPartOfSpeechException
    • justWriteWord

      private void justWriteWord(edu.stanford.nlp.ling.CoreLabel token, BufferedWriter writer, boolean isFirstWord) throws IOException
      Helper method for removeMadlibifiable() that writes each word to a file with a preceding space. Adds space before each word for simple avoidance of spaces before punctuation. Nothing is added to the punctuation character itself
      Throws:
      IOException