Exemplo n.º 1
0
func (mr *MRWordCount) Map(key string, value string, emitter dmrgo.Emitter) {

	lower := strings.ToLower(string(value))

	letters := strings.Map(func(r rune) rune {
		if r >= 'a' && r <= 'z' {
			return r
		}

		return ' '
	},
		lower)

	trimmed := strings.TrimSpace(letters)
	words := strings.Fields(trimmed)

	w := uint32(0)
	for _, word := range words {
		w++
		kv := mr.protocol.MarshalKV(word, 1)
		emitter.Emit(kv.Key, kv.Value)
	}
	atomic.AddUint32(&mr.mappedWords, w)

}
Exemplo n.º 2
0
func (mr *MRWordCount) Reduce(key string, values []string, emitter dmrgo.Emitter) {

	counts := []int{}
	mr.protocol.UnmarshalKVs(key, values, &key, &counts)

	count := 0
	for _, c := range counts {
		count += c
	}

	kv := mr.protocol.MarshalKV(key, count)
	emitter.Emit(kv.Key, kv.Value)
}