mapreduce实现QQ好友推荐
2017-05-22 11:25
204 查看
文件
hadoop hello
hdfs world
tom cat
cat dog
hello world
hello hdfs
输出
tom dog
dog tom
hello world
world hello
hdfs world
hdfs hadoop
world hdfs
world hadoop
hadoop hdfs
hadoop world
hello hdfs
hdfs hello
hadoop hello
hdfs world
tom cat
cat dog
hello world
hello hdfs
输出
tom dog
dog tom
hello world
world hello
hdfs world
hdfs hadoop
world hdfs
world hadoop
hadoop hdfs
hadoop world
hello hdfs
hdfs hello
public class QQMapper extends Mapper<LongWritable, Text, Text, Text> { @Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String line = value.toString(); String[] ss = StringUtils.split(line, "\\s+"); context.write(new Text(ss[0]), new Text(ss[1])); context.write(new Text(ss[1]), new Text(ss[0])); } }
public class QQReducer extends Reducer<Text, Text, Text, Text> { @Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { Set<String> set = new HashSet<String>(); for (Text text : values) { set.add(text.toString()); } if (set.size() > 1) { for (Iterator j = set.iterator(); j.hasNext();) { String name = j.next(); for (Iterator i = set.iterator(); i.hasNext();) { String other = i.next(); if (!name.equals(other)) { context.write(new Text(name), new Text(other)); } } } } } }
相关文章推荐
- MapReduce实现QQ好友推荐
- MapReduce实现QQ好友推荐
- 用hadoop2.7.1 mapreduce实现QQ好友推荐功能
- MapReduce实现QQ好友推荐
- 一些算法的MapReduce实现——好友推荐
- hadoop中MapReduce多种join实现实例分析 推荐
- Hadoop 2.6 使用MapReduce实现基于用户的推荐系统
- 使用Python MrJob的MapReduce实现电影推荐系统
- MapReduce之推荐算法实现
- 使用Python MrJob的MapReduce实现电影推荐系统
- MapReduce实现推荐系统
- Hadoop应用开发--基于MapReduce推荐系统的实现
- Hadoop 2.6 使用MapReduce实现基于物品的推荐系统
- mapreduce实现推荐系统
- mapreduce实现推荐系统
- MapReduce实现推荐算法(同现矩阵*评分矩阵=推荐结果)
- 通过mapReduce实现基于项目的协同过滤推荐
- Hadoop 2.6 使用MapReduce实现基于内容的推荐系统
- 使用Python MrJob的MapReduce实现电影推荐系统
- MapReduce实现单表关联(微博关注推荐)