Name: _____________________ Netid: _________________ Name: _____________________ Netid: _________________ Name: _____________________ Netid: _________________
main
method below to launch/run the program:
According to the instructions for the
assignment you will implement a new class
MapMarkovModel
that is a subclass of
the class
AbstractModel
.
The new subclass will generate random
text more efficiently -- but it doesn't change that random
text is generated, just how the text is generated.
To use this new class you'll change
the main
method to what's shown below (there's only one change!)
In a few words, why is this change in main
enough -- that
is why will the view call the methods in the new class you've
created,
MapMarkovModel
and why don't you need to modify the view so
this happens?
(Questions follow about the code in MarkovModel class)
brute
in MarkovModel
is reproduced below.
This code constructs random
text. In the code in the class and below,
the instance variable myString
is the entire file
read by the initialize
method and stored as a
String
value:
String
methods:
pos
(whose
initial value is zero) in the call to
String.indexOf
in the code above and why is
pos
incremented as the last statement of the loop? Two Answers.
wrapAroundString
is used to find matches for the
seed generating random text (the seed is variable str
above) rather than using myString
to find
matches?
MapMarkovModel
you'll create a map similar to the
following:
You might write code similar to the following to store values in the map for an order-k Markov model.
containsKey
and
the put
statement it guards?
ngram
takes on the value of every
k-length substring in the file for which a Markov model is generated.
Why is wrapAroundString
used instead of
myString
?
"anthem theatre tithe"the 3-gram key "the" should be mapped to the three substrings
"hem" "hea" "hea"Explain why the string "hea" is listed twice.
substring
what is that code?
WordNgram
class. Some questions about that task to help understand that part of
the project.
WordNgram
where each object that is an instance of the
class stores N words (or k words for an order-k Markov Model). You're
given part of the class definition and must fill in several methods. One
version of equals
is shown below --- it
works correctly!. Each
WordNGram
object will store the same number of words in
your program -- that number of words is the k in an order-k Word Markov Model.
Object
and why is it cast
to a WordNGram
?
equals
method returns false.
other.myList
to be accessed
when
myList
is private?
hashCode
works correctly, but it results
in a poorly performing hashmap. In a few words, why would the
performance
be poor?
Complete a version of
hashCode
that
simply adds the individual values of the Strings in myList
and
returns the result:
hashCode
as the body of the loop rather than what's shown
above. In answering the question consider hashCode
values
for the 4-gram "jump big dog jump" and "jump jump big dog"
String.substring
method is used to
extract characters from a string and the
String.charAt
method is used to extract an individual
character. For the WordNGram
class a
wordAt
method might be useful. What would it
return -- it's analagous to charAt
?
compareTo
method
should return and how that can be accomplished. You shouldn't write
code, but a few word description.