FMapper

package com.sxt.hadoop.mr.fof;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.StringUtils;

public class FMapper extends  Mapper<LongWritable, Text, Text, IntWritable>{
	Text mkey= new Text();
	IntWritable mval = new IntWritable();
	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		//tom hello hadoop cat
		String[] strs = StringUtils.split(value.toString(),' ');
		for (int i = 1; i < strs.length; i++) {
			mkey.set(getFof(strs[0], strs[i]));
			mval.set(0);
			context.write(mkey, mval);
			for (int j = i+1; j < strs.length; j++) {
				mkey.set(getFof(strs[i], strs[j]));
				mval.set(1);
				context.write(mkey, mval);
			}
		}
	}
	public static String getFof(String s1 , String s2){
		if(s1.compareTo(s2) < 0){
			return  s1+":"+s2;
		}
		return  s2+":"+s1;
	}
}

  

posted @ 2018-06-21 12:32  uuhh  阅读(104)  评论(0)    收藏  举报