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

网站建设优化推广排名郑州文明网

网站建设优化推广排名,郑州文明网,如何建设招聘网站,如何做好网站关键词布局倒排索引是文档检索系统中最常用的数据结构#xff0c;被广泛地应用于全文搜索引擎。它主要是用来存储某个单词#xff08;或词组#xff09;在一个文档或一组文档中存储位置的映射#xff0c;即提供了一种根据内容来查找文档的方式。由于不是根据文档来确定文档所包含的内…  倒排索引是文档检索系统中最常用的数据结构被广泛地应用于全文搜索引擎。它主要是用来存储某个单词或词组在一个文档或一组文档中存储位置的映射即提供了一种根据内容来查找文档的方式。由于不是根据文档来确定文档所包含的内容而是进行相反的操作因而称为倒排索引Inverted Index。 一、实例描述   倒排索引简单地就是根据单词返回它在哪个文件中出现过而且频率是多少的结果。这就像百度里的搜索你输入一个关键字那么百度引擎就迅速的在它的服务器里找到有该关键字的文件并根据频率和其他的一些策略如页面点击投票率等来给你返回结果。这个过程中倒排索引就起到很关键的作用。   样例输入      样例输出    二、设计思路   倒排索引涉及几个过程Map过程Combine过程Reduce过程。   Map过程    当你把需要处理的文档上传到hdfs时首先默认的TextInputFormat类对输入的文件进行处理得到文件中每一行的偏移量和这一行内容的键值对偏移量内容做为map的输入。在改写map函数的时候我们就需要考虑怎么设计key和value的值来适合MapReduce框架从而得到正确的结果。由于我们要得到单词,所属的文档URL,词频而key,value只有两个值那么就必须得合并其中得两个信息了。这里我们设计key单词URLvalue词频。即map得输出为单词URL词频之所以将单词URL做为key时利用MapReduce框架自带得Map端进行排序。   Combine过程   Combine过程将key值相同得value值累加得到一个单词在文档上得词频。但是为了把相同得key交给同一个reduce处理我们需要设计为key单词valueURL词频。   Reduce过程   Reduce过程其实就是一个合并的过程了只需将相同的key值的value值合并成倒排索引需要的格式即可。 三、程序代码   程序代码如下 1 import java.io.IOException;2 import java.util.StringTokenizer;3 4 import org.apache.hadoop.conf.Configuration;5 import org.apache.hadoop.fs.Path;6 import org.apache.hadoop.io.LongWritable;7 import org.apache.hadoop.io.Text;8 import org.apache.hadoop.mapreduce.Job;9 import org.apache.hadoop.mapreduce.Mapper; 10 import org.apache.hadoop.mapreduce.Reducer; 11 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 12 import org.apache.hadoop.mapreduce.lib.input.FileSplit; 13 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 14 import org.apache.hadoop.util.GenericOptionsParser; 15 16 17 public class InvertedIndex { 18 19 public static class Map extends MapperLongWritable, Text, Text, Text{ 20 private static Text word new Text(); 21 private static Text one new Text(); 22 23 Override 24 protected void map(LongWritable key, Text value,MapperLongWritable, Text, Text, Text.Context context) 25 throws IOException, InterruptedException { 26 // super.map(key, value, context); 27 String fileName ((FileSplit)context.getInputSplit()).getPath().getName(); 28 StringTokenizer st new StringTokenizer(value.toString()); 29 while (st.hasMoreTokens()) { 30 word.set(st.nextToken()\tfileName); 31 context.write(word, one); 32 } 33 } 34 } 35 36 public static class Combine extends ReducerText, Text, Text, Text{ 37 private static Text word new Text(); 38 private static Text index new Text(); 39 40 Override 41 protected void reduce(Text key, IterableText values,ReducerText, Text, Text, Text.Context context) 42 throws IOException, InterruptedException { 43 // super.reduce(arg0, arg1, arg2); 44 String[] splits key.toString().split(\t); 45 if (splits.length ! 2) { 46 return ; 47 } 48 long count 0; 49 for(Text v:values){ 50 count; 51 } 52 word.set(splits[0]); 53 index.set(splits[1]:count); 54 context.write(word, index); 55 } 56 } 57 58 public static class Reduce extends ReducerText, Text, Text, Text{ 59 private static StringBuilder sub new StringBuilder(256); 60 private static Text index new Text(); 61 62 Override 63 protected void reduce(Text word, IterableText values,ReducerText, Text, Text, Text.Context context) 64 throws IOException, InterruptedException { 65 // super.reduce(arg0, arg1, arg2); 66 for(Text v:values){ 67 sub.append(v.toString()).append(;); 68 } 69 index.set(sub.toString()); 70 context.write(word, index); 71 sub.delete(0, sub.length()); 72 } 73 } 74 75 public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { 76 Configuration conf new Configuration(); 77 String[] otherArgs new GenericOptionsParser(conf,args).getRemainingArgs(); 78 if(otherArgs.length!2){ 79 System.out.println(Usage:wordcount in out); 80 System.exit(2); 81 } 82 Job job new Job(conf,Invert Index ); 83 job.setJarByClass(InvertedIndex.class); 84 85 job.setMapperClass(Map.class); 86 job.setCombinerClass(Combine.class); 87 job.setReducerClass(Reduce.class); 88 89 job.setMapOutputKeyClass(Text.class); 90 job.setMapOutputValueClass(Text.class); 91 job.setOutputKeyClass(Text.class); 92 job.setOutputValueClass(Text.class); 93 94 FileInputFormat.addInputPath(job,new Path(args[0])); 95 FileOutputFormat.setOutputPath(job, new Path(args[1])); 96 System.exit(job.waitForCompletion(true)?0:1); 97 } 98 99 }  转载于:https://www.cnblogs.com/xiaoyh/p/9361356.html
http://www.pierceye.com/news/771133/

相关文章:

  • 郑州网站优化网络建设有限公司网站建设 交单流程
  • 网站搬家内页打不开重庆市建设工程信息网怎么进不去
  • 深圳 做公司网站网站用什么建设
  • 网站更换空间对优化的影响营销号视频生成器手机版
  • 南宁大型网站推广公司昆山网站制作哪家好
  • 格尔木哪里有做网站的wordpress编辑器排版
  • 怎样开电商襄阳抖音seo找哪家
  • 个人网站 域名舞阳专业做网站
  • 做国外购物网站凤山网站seo
  • 苏州制作网站的有几家WordPress文章编辑链接
  • 免费看电视剧的网站2021网站建设坂田
  • 网站建设中 目录怎么做更好wordpress最好用的虚拟主机
  • 网站百度网盘南京市建设局网站
  • 让别人做网站多久开始注册域名公司注册地址提供
  • 手机网站 设计趋势建设银行暑期招聘网站
  • 兰山做网站专业深圳网站定制开发
  • 做与食品安全有关的网站徐州企业网站设计
  • 番禺网站建设策划江阴市建设局官网站
  • 建设网站模块需要哪些内容石家庄城乡建设厅网站
  • 公司网站后台管理网络公司名字大全三字
  • 广西住房建设厅网站广州seo工作
  • 做分销商城网站的wordpress 知更鸟 网格
  • 推销商务网站的途径有哪些爱网站查询挖掘工具
  • 苏州现代建设公司网站备案的域名做电影网站
  • 长沙seo网站优化公司wordpress5.1下载
  • 七星彩网投网站建设鹤壁公司做网站
  • 多语言企业网站建设费用怎么自己做购物网站
  • 中国网站排名前100线上网站开发相关书籍
  • 网站制作图书网站建设指南
  • 网站备案简单吗优化关键词排名软件