Hadoop倒排索引例子.doc

Hadoop倒排索引例子.doc

ID:59255043

大小:19.50 KB

页数:4页

时间:2020-09-08

Hadoop倒排索引例子.doc_第1页
Hadoop倒排索引例子.doc_第2页
Hadoop倒排索引例子.doc_第3页
Hadoop倒排索引例子.doc_第4页
资源描述:

《Hadoop倒排索引例子.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、packagecn.yws;importjava.io.IOException;importjava.util.StringTokenizer;importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.fs.Path;importorg.apache.hadoop.io.Text;importorg.apache.hadoop.mapreduce.Job;importorg.apache.hadoop.mapreduce.Mapper;importorg.apache.hado

2、op.mapreduce.Reducer;importorg.apache.hadoop.mapreduce.lib.input.FileInputFormat;importorg.apache.hadoop.mapreduce.lib.input.FileSplit;importorg.apache.hadoop.mapreduce.lib.output.FileOutputFormat;importorg.apache.hadoop.util.GenericOptionsParser;//倒排索引请在hadoopindex_in目录下放置file1

3、,file2测试文件publicclassMyInvertedIndex{publicstaticclassMapextendsMapper{privateTextkeyinfo=newText();privateTextvalueinfo=newText();privateFileSplitsplit;//映射@Overrideprotectedvoidmap(Objectkey,Textvalue,Contextcontext)throwsIOException,InterruptedException

4、{//super.map(key,value,context);//获取文件分词split=(FileSplit)context.getInputSplit();StringTokenizertokenizer=newStringTokenizer(value.toString());while(tokenizer.hasMoreTokens()){intsplitindex=split.getPath().toString().indexOf("file");keyinfo.set(tokenizer.nextToken()+":"+split.ge

5、tPath().toString().substring(splitindex));valueinfo.set("1");//file3:1;context.write(keyinfo,valueinfo);}}}publicstaticclassCombineextendsReducer{privateTextinfoText=newText();@Overrideprotectedvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOE

6、xception,InterruptedException{//super.reduce(key,values,context);intsum=0;for(Textvalue:values){sum+=Integer.parseInt(value.toString());}intsplitindex=key.toString().indexOf(":");//file2:1;file3:2;file1:1infoText.set(key.toString().substring(splitindex+1)+":"+sum);key.set(key.to

7、String().substring(0,splitindex));context.write(key,infoText);}}publicstaticclassReduceextendsReducer{privateTextresult=newText();@Overrideprotectedvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedException{//super.reduce(k

8、ey,values,context);//生成文档列表Stringfilelist=newSt

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。