Esempio n. 1
0
# Example 1: Word counting

import pymr
import time

def fmap(x):
	time.sleep(1)
	print "map"
	return [x]

def freduce(vs):
	time.sleep(1)
	print "reduce"
	return sum(vs)

if __name__ == '__main__':
	print pymr.pmapreduce( fmap , freduce , [('a',1),('b',1),('a',1),('a',1)] )	
	print pymr.mapreduce( fmap , freduce , [('a',1),('b',1),('a',1),('a',1)] )
Esempio n. 2
0
# Example 2: Word counting

import pymr
import sys

def fmap((filename,nothing)):
	f = open(filename,'r')
	text = f.read()
	f.close()
	stext = text.replace('\n',' ').replace(',',' ').split(' ')
	return zip( stext , [1 for i in range(0,len(stext))] )

def freduce(vs):
	return sum(vs) # same as reduce(lambda v1,v2:v1+v2,vs)

if __name__ == '__main__':
	if len(sys.argv) != 2:
		print 'Usage: python ex02.py <filename>'
	else:
		print pymr.pmapreduce( fmap , freduce , [(sys.argv[1],-1)] )