2

私のマッパー python スクリプトは次のような出力を生成[2323223,[{'word':'hi'},{'charcount':'2'}]2323223ます2323223

私のマッパースクリプトの一部:

 analysis = {}
 wordanalysis = {}
 found = True

 for line in sys.stdin:
 (n1,n6) = re.split("\t+",line.strip())
 #n6 are the words and n1 is id
 words= re.split("\s+", n6.strip().lower())


 for i in range(0, len(words)):
  #adding id to a dictionary
   #n1 is id
    analysis[n1] = wordanalysis
    wordanalysis["word"] = words[i]
    wordanalysis["charcount"]= len(words[i])

    if len(words[i]) > 7:
       wordanalysis["longword"] = found
    else:
       wordanalysis["longword"] = not(found)

そんな感じ。私のレデューサーは、単語数などをカウントするように動作する必要がありますが、そこにある辞書をどのように解釈するのでしょうか..レデューサーのように: sys.stdinの行の場合:

マッパーからの出力:

['34324242'] [{'word': 'hi','charcount': 2}]
['897924242'] [{'word': 'hello','charcount': 5}]

これが私の出力です。この値をマッパー スクリプトからレデューサー スクリプトに渡します。レデューサーは、上記の o/p を入力として受け取り、charcount の合計などのデータ分析を行います。それを行う方法はありますか?
主な課題は、マッパー出力から dict 値を取得することと、dict からキーに従ってそれらを取得する方法です。

ありがとうございます。</p>

4

0 に答える 0