11 file_name =
"../LICENSE" 13 kmr = kmr4py.KMR(
"world")
15 def read_words_from_a_file(kv, kvi, kvo, i, *_data):
16 file_ = open(file_name,
"r") 18 words = re.split(
r"\W+", line.strip())
24 def print_top_five((k, v), kvi, kvo, i, *_data):
26 if (kmr.rank == 0
and i < 5):
27 print "#%s=%d" % (v, int(0 - k))
29 def sum_counts_for_a_word(kvvec, kvi, kvo, *_data):
36 if (kmr.rank == 0):
print "Ranking words..." 38 kvs0 = kmr.emptykvs.map_once(
False, read_words_from_a_file, key=
"cstring")
40 kvs2 = kvs1.reduce(sum_counts_for_a_word, key=
"cstring", value=
"integer")
43 kvs4.map(print_top_five, output=
False, nothreading=
True)