CS 106 Winter 2016
Lab 09: Text processing
Question 1 Word trivia
One of the benefits of learning some basic text processing skills is the ability to cheat at word puzzles (if you're of that disposition). If you're looking for a word with some particular property, you can write a sketch that loads in a dictionary of words, walks over every word in the list, and checks those words for the property in question.
Download the starter code and open the sketch WordPuzzles. When you run it, it will load in a file called sowpods.txt (a standard word list used to play the board game Scrabble). The sketch is written to solve six separate word puzzles in the functions getWords_0() ... getWords_5() (a bit like the Dancers sketch in Lab 05). The first puzzle (i.e., getWords_0()) is solved for you so that you can see the general approach. Your job is to solve the other word puzzles. A few notes on this process:
- There's a comment at the start of each getWords() function that tells you what words you're looking for.
- In case it's not obvious, you can't look up the list of words that answers the puzzle online and return an array with the explicit answer. Even if you know, say, that "facetiously" is a word containing the vowels a, e, i, o, u and y in order, you still have to find that word in the word list. Looked at another way, if I removed that word from the dictionary, or I invented a new word with the same property, you would discover that change via your algorithm.
- You are only required to fill in the spots labeled TODO in the provided code. It's possible to complete the sketch doing exactly that. But if you want to write additional helper functions or global variables that make the job of coding easier, feel free to do so.
- Several of the functions include hints or suggested approaches, which you should follow. In the cases of getWords_4() and getWords_5(), you are required to use regular expressions. One of the two regular expressions you'll need is provided for you.
- Use the Processing function match() to work with regular expressions.
- It may occasionally be helpful to consult the online documentation for the String class, which is part of the Java language that powers Processing. You don't have to memorize everything in the long list of string features, but you can sometimes try scanning through the methods to see if there's one that does what you want.
Save your work in a sketch titled WordPuzzles.
Submission
Remember to review the Code Style Guide and use Processing's built-in auto format tool. Then review the How To Submit document. At the top of all of your source files, be sure to include a comment with your name and student ID number. When you're ready, zip up your L09 folder, which contains the WordPuzzles sketch. Upload the file L09.zip to LEARN.