Mapreduce Map Reduce程序只提供映射器输出

Mapreduce Map Reduce程序只提供映射器输出,mapreduce,Mapreduce,这是我在map/reduce中的第一个程序。代替传统的单词计数程序,我尝试在一个文件中计算元音和辅音的数量。下面是我的代码 制图员: 公共类元音转换映射器扩展映射器{ public void map(LongWritable mapKey,Text mapValue,Context context) throws IOException, InterruptedException{ String line = mapValue.toString(); String[] lett

这是我在map/reduce中的第一个程序。代替传统的单词计数程序,我尝试在一个文件中计算元音和辅音的数量。下面是我的代码

制图员:

公共类元音转换映射器扩展映射器{

public void map(LongWritable mapKey,Text mapValue,Context context) throws IOException, InterruptedException{

    String line = mapValue.toString();
    String[] letters = line.split("");

    for(String letter : letters){
        System.out.println(letter);
        if(letter!=" "){
            if(isVowel(letter))
                context.write(new Text("Vowel"), new IntWritable(1));
            else
                context.write(new Text("Consonant"), new IntWritable(1));
        }
    }
}

private boolean isVowel(String letter) {
    // TODO Auto-generated method stub
    if(letter.equalsIgnoreCase("a")||letter.equalsIgnoreCase("e")||letter.equalsIgnoreCase("i")||letter.equalsIgnoreCase("o")||letter.equalsIgnoreCase("u"))
        return true;
    else
        return false;
}
}

减速器:

public class VowelConsReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
    public void reducer(Text letterType,Iterable<IntWritable> values,Context context) throws IOException, InterruptedException{
        int sum = 0;
        for(IntWritable value:values){
            sum += value.get();
        }
        System.out.println(letterType+"     "+sum);
        context.write(letterType, new IntWritable(sum));
    }
}
}

它给出了以下o/p: 辅音1 辅音1 辅音1 ............... ............... ............... ................ ............... ............... 元音1 元音1 元音1 元音1 ............... ............... ............... ................ ...............

其中,我期望每个类别的辅音和元音总数
抱歉,如果我没有正确格式化代码…&提前谢谢

reduce is方法的签名是“
public void reduce()
”而不是“
public void reducer()
” 以上更改将为您提供预期的输出

开始的那一行

public void reducer(
                  ^
应该是

@Override
public void reduce(
您预期的reducer不会因为您而被调用,因此您得到的是。默认实现只是转储键和值:

for(VALUEIN value: values) {
    context.write((KEYOUT) key, (VALUEOUT) value);
}
在您的例子中,键/值对是
(“元音”,1)
(“辅音”,1)
,因此这解释了您的输出

这就是为什么在重写方法时应始终使用。编译器会告诉您,
reducer
实际上并没有重写任何方法

for(VALUEIN value: values) {
    context.write((KEYOUT) key, (VALUEOUT) value);
}