<reponame>nelsonjr86/Map_Reduce
import mincemeat
import glob
import csv

text_files = glob.glob('textos\\*')

def file_contents(file_name):
    f = open(file_name)
    try:
        return f.read()
    finally:
        f.close()

source = dict((file_name, file_contents(file_name))for file_name in text_files)

def mapfn(k,v):
    print 'map ' + k
    from stopwords import allStopWords
    for line in v.splitlines():
        for word in line.split():
            yield word, 1

def reducefn(k,v):
    print 'reduce ' + k
    return v

s = mincemeat.Server()

# A fonte de dados pode ser qualquer objeto do tipo dicionario
s.datasource = source
s.mapfn = mapfn
s.reducefn = reducefn

results = s.run_server(password="<PASSWORD>")

w = csv.writer(open("Result.csv", "w"))
for k, v in results.items():
    w.writerow([k, v])



import mincemeat
import glob
import csv

text_files = glob.glob('textos\\*')

def file_contents(file_name):
    f = open(file_name)
    try:
        return f.read()
    finally:
        f.close()

source = dict((file_name, file_contents(file_name))for file_name in text_files)

def mapfn(k,v):
    print 'map ' + k
    from stopwords import allStopWords
    for line in v.splitlines():
        for word in line.split():
            yield word, 1

def reducefn(k,v):
    print 'reduce ' + k
    return v

s = mincemeat.Server()

# A fonte de dados pode ser qualquer objeto do tipo dicionario
s.datasource = source
s.mapfn = mapfn
s.reducefn = reducefn

results = s.run_server(password="<PASSWORD>")

w = csv.writer(open("Result.csv", "w"))
for k, v in results.items():
    w.writerow([k, v])
# A fonte de dados pode ser qualquer objeto do tipo dicionario