本文主要是介绍向MapReduce转换:计算共现关系,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
分两部分:
<strong><span style="font-size:18px;">/**** @author YangXin* @info 计算共现关系的Mapper*/
package unitSix;import java.io.IOException;
import java.util.Iterator;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.mahout.math.VarLongWritable;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;public class UserVectorToCooccurrenceMapper extends Mapper<VarLongWritable, VectorWritable, IntWritable, IntWritable>{public void map(VarLongWritable userID, VectorWritable userVector, Context context) throws IOException, InterruptedException{Iterator<Vector.Element> it = userVector.get().nonZeroes().iterator();//双重循环遍历非零元素while(it.hasNext()){int index1 = it.next().index();Iterator<Vector.Element> it2 = userVector.get().
这篇关于向MapReduce转换:计算共现关系的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!