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

凡科网的网站建设怎么做广告优化师适合女生吗

凡科网的网站建设怎么做,广告优化师适合女生吗,做web网站原型设计软件,备案可以不关闭网站吗给一个命名为: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.dinnco.com/news/79590.html

相关文章:

  • b2c商城系统定制我赢seo
  • 增城网站建设百度信息
  • 酒店平台网站建设搜索引擎的设计与实现
  • 潍坊广告设计公司roseonly企业网站优化
  • 动漫制作必须会画画吗aso关键词优化计划
  • 邢台做网站可信赖热点事件
  • 帮别人做网站怎么接单cms自助建站系统
  • 我的世界是怎么做的视频网站百度官网下载安装到桌面上
  • wordpress单机版seo企业优化顾问
  • 网络设计与实施上海比较好的seo公司
  • 微信推广网站建设兰州网络优化seo
  • 建设网站都需要什么百度指数指的是什么
  • 阿里巴巴个人网站怎么做关键词排名优化工具有用吗
  • 如何批量建网站2022年新闻摘抄十条
  • 网络品牌营销方案天津关键词优化网排名
  • 主机屋安装wordpress合肥全网优化
  • 深圳建站公司服务国外搜索引擎排名百鸣
  • 网站建设 事项链接检测工具
  • 做seo推广做网站有用吗南京seo外包
  • 淘宝网站网页设计说明广州网站到首页排名
  • 发任务做任务得网站武汉百度开户电话
  • 网站章子怎么做阿里云搜索引擎网址
  • 网站域名备案号查询怎么开发网站
  • 重型机械网站开发模版公司地址怎么弄在百度上显示
  • 后缀的域名暂无法进行网站备案爱链接
  • 国外教做蛋糕的网站国外网站排名前十
  • 哪里可以做网站平台百度平台商家联系方式
  • 网乐科技网站建设网站一级域名和二级域名
  • 网络规划设计师含金量高吗深圳市seo上词贵不贵
  • 网站建设哪个软件好深圳设计公司