Permalink
Browse files

modernized pagerank runner script

  • Loading branch information...
1 parent 4abef24 commit a16ac9382758c0357bef73467a80c455f0afa820 Philip (flip) Kromer committed Feb 1, 2011
Showing with 4 additions and 20 deletions.
  1. +4 −20 examples/pagerank/pagerank.rb
@@ -2,27 +2,19 @@
require 'rubygems'
require 'wukong/script'
-#
-#
-#
-
module PageRank
#
# Damping factor (prob. of a 'random' jump)
# 0.85 works well in practice. See http://en.wikipedia.org/wiki/Pagerank
#
DAMPING_FACTOR = 0.85
- #
# Each user's line looks like
- #
# user_a pagerank id1,id2,...,idN
- #
# we need to disperse this user's pagerank to each of id1..idN, and
# rendezvous the list of outbound links at user_a's reducer as well.
- #
module Iterating
- class Mapper < Wukong::Streamer::Base
+ class PagerankMapper < Wukong::Streamer::Base
#
# Send pagerank to each page, and send the dests list back to self
#
@@ -34,25 +26,21 @@ def process src, pagerank, dests_str, &block
yield_own_dest_list src, dests_str, &block
end
- #
# Take the source node's pagerank and distribute it among all the out-nodes
- #
def yield_pagerank_shares src, pagerank, dests
pagerank_share = pagerank.to_f / dests.length
dests.each do |dest|
yield [dest, 'p', pagerank_share]
end
end
- #
# Dispatch this user's out-node list to rendezvous with itself.
- #
def yield_own_dest_list src, dests_str
yield [src, 'd', dests_str]
end
end
- class Reducer < Wukong::Streamer::AccumulatingReducer
+ class PagerankReducer < Wukong::Streamer::AccumulatingReducer
attr_accessor :node_id, :pagerank, :dests_str
# Begin reduction with 0 accumulated pagerank and no dests as yet
def start! node_id, *args
@@ -78,11 +66,7 @@ def finalize
end
end
- class Script < Wukong::Script
- def default_options
- super.merge :extra_args => ' -jobconf io.sort.record.percent=0.25 '
- end
- end
- Script.new(Mapper, Reducer).run
+ Wukong.run(PagerankMapper, PagerankReducer,
+ :extra_args => ' -jobconf io.sort.record.percent=0.25 ')
end
end

0 comments on commit a16ac93

Please sign in to comment.