2014-02-11 42 views
0

很抱歉的混亂冠軍,這是很難定義...在一行中兩次降低Hadoop中

我希望做的是採取單詞作爲輸入序列一個Hadoop作業和輸出線如下:

小寫字母序列頻率的小寫字母序序列頻率的序列

我想到一個例子是最好的解釋:

假設我輸入的數據是:

the sun 
the sun 
the sun 
The sun 
The sun 
The Sun 

我想

the sun 6 the sun 3 
the sun 6 The sun 2 
the sun 6 The Sun 1 

結束了,我怎樣才能減少兩個小寫序列頻和原序列頻?

回答

1

在地圖功能: 輸出鍵: sequence.toLowerCase() 輸出值: 序列(按原樣)

在用於每個值的降低功能:

Map<String, Integer> occurrences = new HashMap<String, Integer>(); 
occurrences.put(key, occurrences.get(key) + 1); 
if(!key.equals(value)){ 
occurrences.put(value, occurrences.get(key) + 1); 
} 

這只是僞代碼。您將收到NPE,因爲occurrences.get(key/value)將返回null首次。只需爲此添加檢查。 因此,您將得到您的出現次數和不同大小寫不同的相同序列的地圖。

+0

謝謝@安德魯。我做了一些非常類似的事情,結果很好。 – antares