Start by snarfing 06Clwk_maps. Work in groups of up to 3.
A Map
might be used to associate student IDs with complete student records, or
words to their definitions (like a real dictionary). What other examples of
maps can you think of?
In Java, we can use the
TreeMap
class that implements the Map
interface. In the remainder of this
activity, you will use one or more
TreeMap
objects to discover several interesting properties about words in a file: how
many times a word appears, on which lines a word appears, and at which locations does a word appear.
There is one class defined for this activity: WordLines. You should start by reading over the code in this class, so you can answer the following questions.
Explain the following details about the code in a README file:
Integer
object and how is it used
in this class?printResults
work for any kind of map
Complete the method, getLineNumbers
, that creates a new Map
with
words as the key and the set of line numbers on which that word appears as
the value. This method should get the data for each word from the Scanner
passed
it.
Complete the method, getFrequencies
, that creates
a new Map
with
letters as the key and the set of words which start with that letter as
the value. This method should get the data for each word from the Scanner
passed
it.
Suppose you want to create an inverted index, mapping from words to their locations in a set of documents. Describe how you would create this structure. What are the types of the value and key in your map? How do you create this map?
Submit WordLines.java and your README using submit folder clwk06-0210.