Tuesday, January 28, 2014

Because I Promised

Here is a very rough first run of the word_count script.

input_text = "The quick brown fox jumped over the lazy dog. And then the sun shone down on everyone and the little girl smiled. This is the end of this story, this is the end of this story."

words = input_text.split(" ")
word_count = {}

words.each do |word|
  if word_count.has_key?(word)
    word_count[word] += 1
    word_count[word] = 1

puts word_count.inspect

My next steps will be to turn it into a separate method and open a file and count the contents. After that, I want to be able to strip out the text from and html document. I'll need to create tokens for tags to ignore things like <p>, etc. Or I can just count them and then ignore things at the end that have a < as the first letter. We'll see when we get there. I may also go back and refactor the logic so that the `if` is when the key does not already exist (it's a little more human-logical that way, I think.)

Tomorrow's a new day. Good night for now.

No comments:

Post a Comment

Comments? Questions? Complaints? Coladas?