Mapreduce Map reduce-以字母a-z开头的单词数

Mapreduce Map reduce-以字母a-z开头的单词数,mapreduce,Mapreduce,我想得到以字母a-z开头的字数,我正在尝试这段代码,但它只是打印以字母z开头的字数 public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String line = value.toString(); StringTokenizer itr = new StringTokenizer(line);

我想得到以字母a-z开头的字数,我正在尝试这段代码,但它只是打印以字母z开头的字数

public void map(LongWritable key, Text value, Context context)

         throws IOException, InterruptedException {

     String line = value.toString();
     StringTokenizer itr = new StringTokenizer(line);

     while( itr.hasMoreTokens()){
         String token= itr.nextToken();

         if(token.startsWith("a-z")){
             word.set("A_Count");
             //word.set("Z_Count");
             context.write(word, ONE);
    }
  }
}

我已经试过了,运行良好

 public class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
            private final IntWritable VALUE = new IntWritable(1);
            private final Text KEY = new Text("COUNT");

            public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
                String line = value.toString();
                StringTokenizer tokenizer = new StringTokenizer(line);
                while (tokenizer.hasMoreTokens()) {
                    String token = tokenizer.nextToken();
                    if(token.startsWith("a-z")){
                    context.write(KEY, VALUE);
                }
            }
         } 
我的减速机看起来像

public class Reduce extends Reducer<Text, IntWritable, IntWritable, NullWritable> {
    public void reduce(Text key, Iterable<IntWritable> values, Context context) 
              throws IOException, InterruptedException {
                int sum = 0;
                for (IntWritable val : values) {
                    sum += val.get();
                }
                context.write(new IntWritable(sum),NullWritable.get());
            }
    }

也从输入文件中发布一行。这个代码看起来不错。您的逻辑是,将有一个称为_Count的单键,在reducer中,您将计算值列表中1的数量。对的当地图遇到一个以A-z开头的单词,比如A-zdfdgj,A-zererwui等,它就会发出一个_计数,1。但是什么让你确定它只计算以z开头的单词呢?