【发布时间】:2014-12-19 21:49:41
【问题描述】:
我正在尝试为 ngram 的谷歌书籍构建一个 mapreduce 作业。我的映射器在本地测试时工作正常,但减速器不返回任何值。减速器如下所示:
#! /usr/bin/env python
import sys
current_word = ''
word_in_progress = ''
target_year_count = 0
prior_year_count = 0
target_year = 1999
for line in sys.stdin:
line = line.strip().split('\t')
if len(line) !=3:
continue
current_word, year, occurances = line
if current_word != word_in_progress:
if target_year_count > 0:
if prior_year_count ==0:
print '%s\t%s' % (word_in_progress, target_year_count)
try:
year = int(year)
except ValueError:
continue
try:
occurances = int(occurances)
except ValueError:
continue
if year == target_year:
target_year_count += occurances
if year < target_year:
prior_year_count += occurances
print '%s\t%s' % (word_in_progress, target_year_count)
if target_year_count > 0:
if prior_year_count ==0:
print '%s\t%s' % (word_in_progress, target_year_count)
当我在 Ubuntu 命令行中键入以下命令时:
hduser@bharti-desktop:~/hadoop$ cat /home/hduser/Documents/test1.1.txt | /home/hduser /hadoop/mapper-ngram.py | sort -k1,1 | /home/hduser/hadoop/reducerngram1.py| sort -k2,2n
我什么也得不到。谁能告诉我我做错了什么。
【问题讨论】:
标签: python-2.7 ubuntu mapreduce