name: ___________________________________ name: ___________________________________ name: ___________________________________pretty printed code, browsable and snarfable using the http://www.cs.duke.edu/courses/cps100/fall09/snarf site in Eclipse.
This is a small system ... such a system could be produced by a good programmer within a week or two.
Today, with more memory and better programming abstractions it doesn't take a week to do. As an example of a KWIC, some occurrences of love and hate from Shakespeare's Romeo and Juliet are shown below, the formatting is meant to make it easier to see the context and the key word --- there are two key words: love and hate.
talk of peace? I hate the word As I the word As I hate hell, all Montagues, and better ended by their hate Than death prorogued, wanting lives, By doing damned hate upon thyself? Why railest But thankful even for hate that is meant love.
nature. For this drivelling love is like a great my love? Nurse. Your love says, like an honest oddly thou repliest! 'Your love says, like an honest by the which your love Must climb a bird's
You'll be looking at code in a new class ContextModel that finds key words in context. The general outline of how the context is generated includes these steps:
String.splitmethod it's simple to get this array of every word in the file, in the order in which the words occur. We'll call the array
myWords, it's state in the
myWordsby storing the index of each occurrence of the word in a list of indexes. This list is the value in a map associated with the key which is the unique word. In the list of indexes each index references an occurrence of the word in
initializemethod is called and does bookkeeping that results in storing all the words in the file read.
processmethod as a String. In the code you're given, the map of key words to their indexes is constructed as needed. Then the map is used to generate contexts.
updatemethod. This is done indirectly by calling
notifyViewswhich takes care of calling m
processmethod. Why is the map's size used to determine if the map should be filled? When does the map need to be filled and when is the step of filling the map unnecessary?
processhere is removed what will happen when the user types a word that doesn't appear in the file (or has too few letters)?
continuestatement in building the context string? When will it be executed? What happens if the
StringBuilderobject is used with the method
Stringcould be used instead, either with
appendor with the overloaded concatenation/append operator
+to append strings. Using a String generates exactly the same output as a StringBuilder -- what's a possible/likely reason for using
TreeMapin the constructor of
ContextModelbe better than using a
HashMapin printing every key word in its context?
No.-Wall-street. At one end they looked upon the white the Directory. In truth they were nicknames, mutually conferred and Post Office. Also, they sent Ginger Nut very these cakes, as if they were mere wafers-indeed they they were mere wafers-indeed they sell them at the scriveners in an office, they assist each other in grin. ``You hear what they say,'' said I, turning are so called because they contain ginger as oneExplain what part of the code causes the bug to happen. Identify and describe the code that causes this problem. Describe an idea of how to fix the problem at a high-level. You don't need to write the code that fixes the problem, you need to describe what the code is, where it fits, etc. using descriptions rather than code.