【问题标题】:python ngram reducer not returning any output?python ngram减速器不返回任何输出?
【发布时间】: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


    【解决方案1】:

    我要检查的第一件事:

    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?
    

    这个空间是您帖子中的错字,还是您真的以这种方式运行命令?如果这是您命令的准确表示,我猜输入实际上并没有到达您的映射器(因此没有任何东西会到达您的减速器)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 2012-02-04
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多