In-class notes for 03/31/2014
CS 121B (CS1), Spring 2014
Quiz returned
Submitted questions on assignments and technology
Upcoming
Instead of reading more of the WMR module, I will present some additional topics in class.
Quiz on Wednesday. See below for topics.
Exercise: Strategies for counting words
an death great I love say that the
Word counting with WMR
Question: How count word frequencies in a very large body (corpus) of text?
WMR mapper code for word frequency count
# IN keys and values: # key: holds lines of text from the corpus value: is empty # OUT keys and values: # key: one word from that text value: a string representing the number 1 def mapper(key, value): words=key.split() for word in words: Wmr.emit(word, '1')
WMR reducer code for word frequency count
# IN keys and values: # key: one word from a corpus value: a string representing the number 1 # NOTE: the values are packed into an interator iter # OUT keys and values: # key: that one word from a corpus value: the sum of the 1's from iter def reducer(key, iter): sum = 0 for s in iter: sum = sum + int(s) Wmr.emit(key, str(sum))
Try it! You can use the WMR installation at
http://www.cs.stolaf.edu/wmr
Use your St. Olaf username and password. WMR should work on any browser.
Submitted questions on readings
To study for quiz
Recursion with list arguments, including nested (non-linear) recursion
Problems similar to homework
Include
#assert
comments that describe the logical state of a computation, located on the line just before the next guard. ExampleUse recursion only, no iteration (no loops)
Tracing recursion
< >