当前位置: 首页 > news >正文

凡科网的网站建设怎么做宁德市疫情

凡科网的网站建设怎么做,宁德市疫情,跨境电商怎么做?如何从零开始学做电商赚钱,全球设计行给一个命名为:friend.txt的文件 其中每一行中给出两个名字,中间用空格分开。(下图为文件内容) 题目:《查找出可能认识的人 》 代码如下: RelationMapper: package com.fesco.friend;import or…

给一个命名为:friend.txt的文件

其中每一行中给出两个名字,中间用空格分开。(下图为文件内容)

题目:《查找出可能认识的人 》

代码如下:

RelationMapper:

package com.fesco.friend;import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;public class RelationMapper extends Mapper<LongWritable, Text, Text, Text> {@Overrideprotected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {// 拆分人名String[] arr = value.toString().split(" ");context.write(new Text(arr[0]), new Text(arr[1]));}
}

RelationReducer :

package com.fesco.friend;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;
import java.util.LinkedList;
import java.util.List;public class RelationReducer extends Reducer<Text, Text, Text, IntWritable> {// 真的认识private static final IntWritable trueFriend = new IntWritable(1);// 可能认识private static final IntWritable fakeFriend = new IntWritable(0);@Overrideprotected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {// key = tom// values = rose jim smith lucyString name = key.toString();// 迭代器values本身是一个伪迭代器,只能迭代一次// 所以还需要自己定义集合来存储好友列表List<String> fs = new LinkedList<>();// 确定真实好友关系for (Text value : values) {String f = value.toString();fs.add(f);if (name.compareTo(f) <= 0) context.write(new Text(name + "-" + f), trueFriend);else context.write(new Text(f + "-" + name), trueFriend);}// 推测好友关系for (int i = 0; i < fs.size() - 1; i++) {String f1 = fs.get(i);for (int j = i + 1; j < fs.size() ; j++) {String f2 = fs.get(j);if(f1.compareTo(f2) <= 0) context.write(new Text(f1 + "-" + f2), fakeFriend);else context.write(new Text(f2 + "-" + f1), fakeFriend);}}}
}

RelatioDriver: 

package com.fesco.friend;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class RelationDriver {public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(RelationDriver.class);job.setMapperClass(RelationMapper.class);job.setReducerClass(RelationReducer.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(Text.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPath(job, new Path("hdfs://10.16.3.181:9000/txt/friend.txt"));FileOutputFormat.setOutputPath(job, new Path("hdfs://10.16.3.181:9000/result/relation"));job.waitForCompletion(true);}
}

FriendMapper: 

package com.fesco.friend;import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;public class FriendMapper extends Mapper<LongWritable, Text, Text, LongWritable> {@Overrideprotected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {// 拆分数据String[] arr = value.toString().split("\t");context.write(new Text(arr[0]), new LongWritable(Long.parseLong(arr[1])));}
}

FriendReducer: 

package com.fesco.friend;import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class FriendReducer extends Reducer<Text, LongWritable, Text, Text> {@Overrideprotected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, Text>.Context context) throws IOException, InterruptedException {// 想要验证l两个人是否认识,验证逻辑:如果出现了数字1,说明两个人真的认识,那么就不是要找的可能认识的人// 如果遍历完成,全部都是数字0,那么说明这俩人真的是不认识,但是两个人有共同好友for (LongWritable value : values) {if (value.get() == 1) return ;}// 循环完成没有return,说明全部都是数字0String[] arr = key.toString().split("-");context.write(new Text(arr[0]), new Text(arr[1]));}
}

FriendDriver: 

package com.fesco.friend;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class FriendDriver {public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(FriendDriver.class);job.setMapperClass(FriendMapper.class);job.setReducerClass(FriendReducer.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(LongWritable.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(Text.class);FileInputFormat.addInputPath(job, new Path("hdfs://10.16.3.181:9000/result/relation"));FileOutputFormat.setOutputPath(job, new Path("hdfs://10.16.3.181:9000/result/friend"));job.waitForCompletion(true);}
}

http://www.yidumall.com/news/70565.html

相关文章:

  • 扶余网站建设aso排名优化知识
  • 做宣传单的网站百度seo服务方案
  • 广州网站设计报价seo有哪些网站
  • 美食网页制作宁波seo优化服务
  • 创意设计pc河南整站百度快照优化
  • 物流公司做网站哪家好百度快照替代
  • p2p网贷网站建设方案寻找郑州网站优化公司
  • 佛山网站建设怎样做关联词有哪些 全部
  • 企业网站的主要类型有网络服务器图片
  • 常熟网站建设哪家好关键词seo优化
  • 大庆做网站最厉害的人来客seo
  • baby做网站汽车大连企业网站建站模板
  • 衡阳电商网站建设2022年网络流行语
  • 帮网站做点击珠海百度推广优化排名
  • 自己怎么做短视频网站百度竞价推广怎么做
  • 新开的网站怎么做seo优化郑州百度公司地址
  • 深圳html5网站开发如何做品牌运营与推广
  • 南海网站推广如何做好企业网站的推广
  • 手机平台网站开发湖北短视频搜索seo
  • 北京seo网站西安百度公司
  • wordpress 产品展示 插件福州短视频seo推荐
  • 甘肃网站开发企业如何推广自己的产品
  • 深圳最新新闻seo权重优化
  • 公益平台网站怎么做东莞优化排名公司
  • 政府部门网站建设依据百度推广运营工作是什么
  • 淘宝网站开发者百度广告电话号码是多少
  • 那些网站是java做的百度基木鱼建站
  • 住房和城乡建设部网站职责百度一下百度搜索网站
  • 有做酒席酒水网站吗网站出租三级域名费用
  • 响应式网站建设公司‘国内seo公司哪家最好