Hi all,

I have a text file with phrases that I'm looking to split into chunks.

The following keyword list:

the brown fox jumped,
over the fence,

Which should produce the following output:

the,
the brown,
the brown fox,
the brown fox jumped,
brown fox,
brown fox jumped,
fox,
fox jumped,
jumped,
over,
over the,
over the fence,
the,
the fence,
fence

I'm currently using the following code which splits after each space:

  def count_frequency
   the_file='D:/Ruby/projects/data.txt'
   h = Hash.new
   f = File.open(the_file, "r")
   f.each_line { |line|
   words = line.split
   words.each { |w|
    if h.has_key?(w)
      h[w] = h[w] + 1
    else
      h[w] = 1
    end
  }
}

# sort the hash by value, and then print it in this sorted order
h.sort{|a,b| a[1]<=>b[1]}.each { |elem|
  puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
}

end

By the look of this I just need to append to the words array more words
with a different slice?

Many thanks in advance,

Ryan

-- 
Posted via http://www.ruby-forum.com/.