Mapredu ce 程序设计报告 姓名: 学号: 题目: 莎士比亚文集倒排索引算法 1、 实验环境 联想 pc机 虚拟机:VM 10
0 操作系统:Centos 6
4 Hadoop版本:hadoop 1
1 Jdk版本:jdk-7u25 Eclipse版本:eclipse-SDK-4
2-linux-gtk-x86_64 2、 实验设计及源程序 2
1 实验说明 对莎士比亚文集文档数据进行处理,对莎士比亚文集文档数据进行倒排索引 处理,结果输出到指定文件 2
2 实验设计 (1)InvertedIndexMapper 类 这个类实现 Mapper 接口中的 map 方法,输入参数中的 value 是文本文件中的一行,利用正则表达式对数据进行处理,使文本中的非字母和数字符号转换成空格,然后利用StringTokenizer 将这个字符串拆成单词,最后将输出结果,outkey 为单词+单词所在的文件名,outvalue 为 1
public static class InvertedIndexMapper extends Mapper{ private final static IntWritable one = new IntWritable(1); public void map(Object key, Text value, Context context ) throws IOException, InterruptedException { //获取文件名以及预处理 FileSplit filesplit =(FileSplit)context
getInputSplit(); String filename =filesplit
getPath()
getName(); String line=value
toString(); String s; /