2014-12-19 91 views
0

我正在努力为谷歌书籍的ngrams建立一个mapreduce工作。我的mapper在本地测试时工作正常,但reducer没有返回任何值。减速机是类似下面的东西:python ngram reducer没有返回任何输出?

#! /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的命令行下面的命令:

[email protected]:~/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 

我什么也没得到。有人能告诉我我正在做什么错。

回答

0

我会检查第一件事:

cat /home/hduser/Documents/test1.1.txt | /home/hduser /hadoop/mapper-ngram.py | sort -k1,1 | /home/hduser/hadoop/reducerngram1.py| sort -k2,2n 
                ^# Is this space a typo? 

是这个空间在您的文章错字,还是你真正运行的命令呀?如果这是您的命令的准确表示,我猜测输入实际上并没有到达您的映射器(因此没有任何内容会到达您的映射器)。