lineNo = same as key to the mapper (the first parameter to the above function)
letter = your desired letter
m = <total number of letters in the line (the 2nd parameter to the above function) input to the mapper>
n = <number of occurrence of letter in the line (the 2nd parameter to the above function) mapper input line>
``` `c_` 以及 `a_` 只是识别计数类型的前缀。 `c` 表示字母出现的次数;而 `t` 表示发生的总数。
基本上,这里我们利用的概念是,您可以从mapper/reducer中编写任意多的键值。
现在减速机会得到类似钥匙的东西: `<lineNo_letter>` 价值: `ListOf[c_m, t_n]` 现在,只需迭代列表,用分隔符将其拆分 `_` 在标识符前缀的帮助下( `t` 以及 `c` ); 在减速器中有所需的值。即
Total number of letter in the sentence = m Total number of occurrence of the letter = n
-- Output length of the Text Value against each letter context.write("1_h", "t_9"); context.write("1_o", "t_9"); context.write("1_w", "t_9"); context.write("1_a", "t_9"); context.write("1_r", "t_9"); context.write("1_e", "t_9"); context.write("1_y", "t_9"); context.write("1_u", "t_9");
3条答案
按热度按时间ffx8fchx1#
我自己解决的:使用全局计数器访问map\u output\u记录,得到reducer中mapper输出的总数。
代码:
qgzx9mmu2#
假设您的Map器得到了一个完整的句子,其中您正在尝试查找频率,并且您正在使用javaapi,那么您可以通过从Map器输出两个键
context.write(...)
功能:Map器的java语法:
public void map(LongWritable key, Text value, Context context)
密钥:<lineNo_Letter>
; 价值:c_m
密钥:<lineNo_Letter>
; 价值:t_n
哪里Total number of letter in the sentence = m
Total number of occurrence of the letter = n
LongWritable key = 1
Text value = howareyou
-- Output length of the Text Value against each letter
context.write("1_h", "t_9");
context.write("1_o", "t_9");
context.write("1_w", "t_9");
context.write("1_a", "t_9");
context.write("1_r", "t_9");
context.write("1_e", "t_9");
context.write("1_y", "t_9");
context.write("1_u", "t_9");
-- Output individual letter count in the input text as
context.write("1_h", "c_1");
context.write("1_o", "c_2");
context.write("1_w", "c_1");
context.write("1_a", "c_1");
context.write("1_r", "c_1");
context.write("1_e", "c_1");
context.write("1_y", "c_1");
context.write("1_u", "c_1");
key: "1_h" value: ListOf["t_9", "c_1"]
key: "1_o" value: ListOf["t_9", "c_2"]
key: "1_w" value: ListOf["t_9", "c_1"]
key: "1_a" value: ListOf["t_9", "c_1"]
key: "1_r" value: ListOf["t_9", "c_1"]
key: "1_e" value: ListOf["t_9", "c_1"]
key: "1_y" value: ListOf["t_9", "c_1"]
key: "1_u" value: ListOf["t_9", "c_1"]
nwlqm0z13#
不要一看到信就马上写。数一数所有的字符,然后把总数和字符一起写下来。
然后根据您编写值的方式,您的reducer将看到
求1的和,从9中抽取任意一个,然后除以