{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lab13 - CS 61A Week 13 Lab Solutions 1 We make two changes...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61A Week 13 Lab Solutions 1. We make two changes: First, change the mapper function so that the intermediate pairs use the play names as keys. This will result in a separate reduce instance for each play. Then, we do an ordinary non-parallel stream-accumulate to combine those results into a single count. (Shakespeare didn't write so many plays that we can't accumulate the results of the different plays on a single processor.) (STREAM-ACCUMULATE (LAMBDA (NEW OLD) (+ (KV-VALUE NEW) OLD)) 0 (mapreduce (lambda (kv-pair) (list (make-kv-pair (KV-KEY KV-PAIR) 1))) + 0 "/gutenberg/shakespeare")) 2(a). The mapper gets a line as input, but wants to output a separate key-value pair for each word in the line. (define gutenberg-wordcounts (mapreduce (lambda (line-pair) (map (lambda (wd) (make-kv-pair wd 1)) (kv-value line-pair))) + 0 "/gutenberg/shakespeare")) 2(b). We want to reduce gutenberg-wordcounts by comparing the counts of two words at a time, keeping the one with the larger count. But there are a lot of words in English, so we'd like to parallelize that reduction.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}