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

什么是同ip网站沈阳口碑最好的装修公司

什么是同ip网站,沈阳口碑最好的装修公司,杰迅山西网站建设,dede网站模板一、简介 在文件中统计出现最多个数的单词#xff0c;将其输出到hdfs文件上。 二、例子 #xff08;1#xff09;实例描述 给出三个文件#xff0c;每个文件中都若干个单词以空白符分隔#xff0c;需要统计出现最多的单词 …一、简介 在文件中统计出现最多个数的单词将其输出到hdfs文件上。 二、例子 1实例描述 给出三个文件每个文件中都若干个单词以空白符分隔需要统计出现最多的单词                                             样例输入                                             1file1   MapReduce is simple 2file2   MapReduce is powerful is simple  3file3   Hello MapReduce bye MapReduce 期望输出 MapReduce      42问题分析 实现统计出现最多个数的单词只要关注的信息为单词、词频。 3实现步骤 1Map过程  首先使用默认的TextInputFormat类对输入文件进行处理得到文本中每行的偏移量及其内容。显然Map过程首先必须分析输入的key,value对得到倒排索引中需要的三个信息单词、词频 2Combine过程      经过map方法处理后Combine过程将key值相同的value值累加得到一个单词在文档在文档中的词频输出作为Reduce过程的输入。 3Reduce过程  经过上述两个过程后Reduce过程只需将相同key值的value值累加保留最大词频的单词输出。 4代码实现 package com.mk.mapreduce;import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.input.FileSplit; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException; import java.net.URI; import java.util.*;public class MaxWord {public static class MaxWordMapper extends MapperLongWritable, Text, Text, IntWritable {private final Text newKey new Text();private final IntWritable newValue new IntWritable(1);Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {if (StringUtils.isBlank(value.toString())) {System.out.println(空白行);return;}StringTokenizer tokenizer new StringTokenizer(value.toString());while (tokenizer.hasMoreTokens()) {String word tokenizer.nextToken();newKey.set(word);context.write(newKey, newValue);}}}public static class MaxWordCombiner extends ReducerText, IntWritable, Text, IntWritable {private final IntWritable newValue new IntWritable();Overrideprotected void reduce(Text key, IterableIntWritable values, Context context) throws IOException, InterruptedException {int count 0;for (IntWritable v : values) {count v.get();}newValue.set(count);context.write(key, newValue);}}public static class MaxWordReducer extends ReducerText, IntWritable, Text, IntWritable {private String word null;private int count 0;Overrideprotected void reduce(Text key, IterableIntWritable values, Context context) throws IOException, InterruptedException {int c 0;for (IntWritable v : values) {c v.get();}if (word null || count c) {word key.toString();count c;}}Overrideprotected void cleanup(Context context) throws IOException, InterruptedException {if (word ! null) {context.write(new Text(word), new IntWritable(count));}}}public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {String uri hdfs://192.168.150.128:9000;String input /maxWord/input;String output /maxWord/output;Configuration conf new Configuration();if (System.getProperty(os.name).toLowerCase().contains(win))conf.set(mapreduce.app-submission.cross-platform, true);FileSystem fileSystem FileSystem.get(URI.create(uri), conf);Path path new Path(output);fileSystem.delete(path, true);Job job new Job(conf, MaxWord);job.setJar(./out/artifacts/hadoop_test_jar/hadoop-test.jar);job.setJarByClass(MaxWord.class);job.setMapperClass(MaxWordMapper.class);job.setCombinerClass(MaxWordCombiner.class);job.setReducerClass(MaxWordReducer.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPaths(job, uri input);FileOutputFormat.setOutputPath(job, new Path(uri output));boolean ret job.waitForCompletion(true);System.out.println(job.getJobName() ----- ret);} }
http://wiki.neutronadmin.com/news/165927/

相关文章:

  • 成都网站建设sntuu小程序定制开发多少钱一年
  • 索引网站有哪些东营垦利
  • 网站主持人制作网站代言人网站系统怎么做
  • 如何在网站上做社交的链接微信端网站设计规范
  • 如何构建一个成交型网站wordpress 商品设置
  • 网站原型图展示wordpress微信登录设置密码
  • 管理网站精品网站建设费用 c磐石网络
  • 制作单页网站公司网络营销策略
  • 网站页面是自己做还是使用模板做视频可以领钱的网站
  • 建立网站编码 优帮云网站建设项目进度计划书
  • 网站建设全部教程运营说白了是什么意思
  • 网站建设项目心得体会网站管理后台制作
  • 注册完域名 如何做网站地方做什么网站
  • 怎样吧自己做的网站发布网络优化怎么自己做网站
  • 网站内部建设和程序wordpress 3.2 下载地址
  • 北京建设银行纪念钞预定官方网站东莞网页设计制作
  • 网站怎么做能中英文的iis搭建本地网站
  • 陕西省建设教育培训中心网站asp美食网站源码
  • 有没有免费开网站的购买域名后 可以做网站么
  • 深圳建站公司哪个济南兴田德润简介遵义市做网站的地方
  • 富德生命人寿保险公司官方网站保单查询南宁网络
  • 做网站外包公司有哪些做服装团购有哪些网站
  • 2021不良正能量免费网站app对网站的建议和优化
  • 做网站来钱快北京高端网站建设有限公司
  • 设计一个网站的价格表新冠咳嗽吃什么药
  • 南京企业网站建设网络公司有几家
  • 邢台高端网站建设公司建筑设计费一般多少钱一平方
  • 新乡网站建设制作报价方案什么网站做旅行计划
  • 网站开发关于安全问题去哪里做网站
  • 十堰做网站公司哈尔滨企业网站seo