require_relative 'markov-dictionary'

class TwoWordDictionary < MarkovDictionary
  def parse_file
    # Special case for last word in source file as it has no words following it.
    @contents = open_file(@filename)
    (@contents.length-3).times do |i|
      rootword = "#{@contents[i]} #{@contents[i+1]}"
      self.add_word(rootword, @contents[i+2])
    end
  end
end

require_relative 'markov-dictionary'

class TwoWordDictionary < MarkovDictionary
  def parse_source(source)
    @contents = open_source(source)
    (@contents.length-3).times do |i|
      rootword = "#{@contents[i]} #{@contents[i+1]}"
      self.add_word(rootword, @contents[i+2])
    end
    @dictionary[@contents.last(2).join(' ')] ||= Hash.new(0)
  end
end

Add last two words of source into dictionary.
Add last two words of source into dictionary.
