Sha256: dbcfb19ad280f73df107b05fed0b3f3c3fc03d6bb41da54f8a30ca23bfa503a6

Contents?: true

Size: 1.33 KB

Versions: 135

Compression:

Stored size: 1.33 KB

Contents

require 'rubygems'
require 'couchrest'

couch = CouchRest.new("http://127.0.0.1:5984")
db = couch.database('word-count-example')
db.delete! rescue nil
db = couch.create_db('word-count-example')

books = {
  'outline-of-science.txt' => 'http://www.gutenberg.org/files/20417/20417.txt',
  'ulysses.txt' => 'http://www.gutenberg.org/dirs/etext03/ulyss12.txt',
  'america.txt' => 'http://www.gutenberg.org/files/16960/16960.txt',
  'da-vinci.txt' => 'http://www.gutenberg.org/dirs/etext04/7ldv110.txt'
}

books.each do |file, url|
  pathfile = File.join(File.dirname(__FILE__),file)
  `curl #{url} > #{pathfile}` unless File.exists?(pathfile)  
end


books.keys.each do |book|
  title = book.split('.')[0]
  puts title
  File.open(File.join(File.dirname(__FILE__),book),'r') do |file|
    lines = []
    chunk = 0
    while line = file.gets
      lines << line
      if lines.length > 10
        db.save({
          :title => title,
          :chunk => chunk, 
          :text => lines.join('')
        })
        chunk += 1
        puts chunk
        lines = []
      end
    end
  end
end

# puts "The books have been stored in your CouchDB. To initiate the MapReduce process, visit http://127.0.0.1:5984/_utils/ in your browser and click 'word-count-example', then select view 'words' or 'count'. The process could take about 15 minutes on an average MacBook."


Version data entries

135 entries across 135 versions & 25 rubygems

Version Path
brianmario-couchrest-0.23 examples/word_count/word_count.rb
derfred-couchrest-0.12.6.3 examples/word_count/word_count.rb
derfred-couchrest-0.12.6 examples/word_count/word_count.rb
gbuesing-couchrest-0.23 examples/word_count/word_count.rb
glasner-couchrest-0.2.2 examples/word_count/word_count.rb
gohanlonllc-couchrest-0.2.3.1 examples/word_count/word_count.rb
halfninja-couchrest-0.23.2 examples/word_count/word_count.rb
halfninja-couchrest-0.23.3 examples/word_count/word_count.rb
jchris-couchrest-0.12.4 examples/word_count/word_count.rb
jchris-couchrest-0.12.5 examples/word_count/word_count.rb
jchris-couchrest-0.12.6 examples/word_count/word_count.rb
jchris-couchrest-0.16 examples/word_count/word_count.rb
jchris-couchrest-0.17.0 examples/word_count/word_count.rb
jchris-couchrest-0.2.1 examples/word_count/word_count.rb
jchris-couchrest-0.2.2 examples/word_count/word_count.rb
jchris-couchrest-0.2 examples/word_count/word_count.rb
jchris-couchrest-0.22 examples/word_count/word_count.rb
jchris-couchrest-0.23 examples/word_count/word_count.rb
jgre-couchrest-0.12.6 examples/word_count/word_count.rb
jkestr-couchrest-0.23 examples/word_count/word_count.rb