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

教育网站开发需求分析博客 软件 wordpress

教育网站开发需求分析,博客 软件 wordpress,邯郸市城乡住房建设局网站,wd怎样建设一个网站给一个命名为#xff1a;friend.txt的文件 其中每一行中给出两个名字#xff0c;中间用空格分开。#xff08;下图为文件内容#xff09; 题目#xff1a;《查找出可能认识的人 》 代码如下#xff1a; RelationMapper#xff1a; 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 MapperLongWritable, Text, Text, Text {Overrideprotected void map(LongWritable key, Text value, MapperLongWritable, 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 ReducerText, Text, Text, IntWritable {// 真的认识private static final IntWritable trueFriend new IntWritable(1);// 可能认识private static final IntWritable fakeFriend new IntWritable(0);Overrideprotected void reduce(Text key, IterableText values, ReducerText, Text, Text, IntWritable.Context context) throws IOException, InterruptedException {// key tom// values rose jim smith lucyString name key.toString();// 迭代器values本身是一个伪迭代器只能迭代一次// 所以还需要自己定义集合来存储好友列表ListString 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 MapperLongWritable, Text, Text, LongWritable {Overrideprotected void map(LongWritable key, Text value, MapperLongWritable, 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 ReducerText, LongWritable, Text, Text {Overrideprotected void reduce(Text key, IterableLongWritable values, ReducerText, 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.dnsts.com.cn/news/133171.html

相关文章:

  • 网站开发毕设论文乐高编程培训
  • 做阿里巴巴类似的网站怎么推广自己的产品
  • 网站的访问速度百度网站建设中心
  • 会员网站建设三字型布局的网站
  • 专业推广网站梧州网站建设贝尔利
  • 网站后台管理系统框架我国企业网站的建设情况
  • 广州南沙区建设和交通局网站quick chat wordpress
  • 网站建设专利申请2021百度模拟点击工具
  • 模仿京东商城网站开发视频艺术公司网站定制
  • 在网络上做兼职的网站网站推广的方法
  • 营销网站的优势有哪些淮北做网站电话
  • 网站建设亻金手指下拉上海网络推广竞价公司
  • 手机网站平台国家企业信用信息查询官网
  • 网站做链轮会被惩罚吗网站建设管理成本估计
  • 汕头住房和城乡建设厅网站个人免费网站如何做
  • 中山网站建设价格从零开始做一个网站需要多少钱
  • 自己做网站seo成都关键词排名系统
  • 做网站设计服务商html网站设计模板下载
  • 领卷网站怎么做的seo分析工具
  • 集团网站建设服务超级推荐的关键词怎么优化
  • 很有设计感的企业网站联享品牌网站建设公司
  • 免费开源企业网站上传空间网站
  • 自己做的网站如何推广电子商城网站开发项目描述
  • 弄一个网站要多少钱wordpress 显示二级分类
  • 做网站要国外做彩票网站违法吗
  • 网站推广如何指定关键词优化备份wordpress到百度云
  • wordpress相册展示网站如何做seo优化
  • 机关局域网网站建设旅游网站建设方案之目标
  • 网站维护合同模板南通市港闸区城乡建设局网站
  • 站群网站内容网站建设与运营课程总结