package jp.ac.nii;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

	public static class TokenizerMapper extends
			Mapper<LongWritable, Text, Text, IntWritable> {

		private final static IntWritable one = new IntWritable(1);
		private Text wordText = new Text();

		public void map(LongWritable key, Text value, Context context)
				throws IOException, InterruptedException {
			// Stringに変換した上で、小文字にする
			String line = value.toString().toLowerCase();
			String[] words = line.split(" ");
			for (String word : words) {
				if (isWord(word)) {
					// String方の文字列をHadoopが扱う文字列型（Text）に変換する
					wordText.set(word);
					context.write(wordText, one);
				}
			}
		}

		private boolean isWord(String word) {
			for (int i = 0; i < word.length(); i++) {
				if (!Character.isAlphabetic(word.charAt(i))) {
					return false;
				}
			}
			return word.length() > 0;
		}
	}

	public static class IntSumReducer extends
			Reducer<Text, IntWritable, Text, IntWritable> {
		private IntWritable result = new IntWritable();

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

	public static void main(String[] args) throws Exception {
		if (args.length < 2) {
			System.out.println("hadoop jar MapReduceExcercise1-0.0.1-SNAPSHOT-jar-with-dependencies.jar jp.ac.nii.WordCount <input_hdfs_file> <output_hdfs_dir>");
			return;
		}
		Configuration conf = new Configuration();
		Job job = Job.getInstance(conf, "word count");
		job.setJarByClass(WordCount.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(IntWritable.class);

		job.setMapperClass(TokenizerMapper.class);
		job.setReducerClass(IntSumReducer.class);
		
		job.setInputFormatClass(TextInputFormat.class);
		job.setOutputFormatClass(TextOutputFormat.class);
		
		FileInputFormat.addInputPath(job, new Path(args[0]));
		FileOutputFormat.setOutputPath(job, new Path(args[1]));
		
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}
@@ -963,28 +963,53 @@
 %09// 
-String%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%97%E3%81%9F%E4%B8%8A%E3%81%A7%E3%80%81%E5%B0%8F%E6%96%87%E5%AD%97%E3%81%AB%E3%81%99%E3%82%8B
+Convert Text to String and make it lower case
 %0A%09%09%09
@@ -1158,44 +1158,41 @@
 %09// 
-String%E6%96%B9%E3%81%AE%E6%96%87%E5%AD%97%E5%88%97%E3%82%92Hadoop%E3%81%8C%E6%89%B1%E3%81%86%E6%96%87%E5%AD%97%E5%88%97%E5%9E%8B%EF%BC%88Text%EF%BC%89%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B
+Convert String to Text for Hadoop
 %0A%09%09%09
@@ -2716,8 +2716,9 @@
 1);%0A%09%7D%0A%7D
+%0A

Update WordCount.java