首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Hadoop 统计不同摘引次数的专利数目(三)

2013-11-29 
Hadoop 统计不同引用次数的专利数目(三)一、在(二)的基础之上做修改,代码如下:?import java.io.IOException

Hadoop 统计不同引用次数的专利数目(三)

一、在(二)的基础之上做修改,代码如下:

?

import java.io.IOException;import org.apache.hadoop.conf.Configured;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.KeyValueTextInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import org.apache.hadoop.util.Tool;import org.apache.hadoop.util.ToolRunner;/** * 计算不同引用次数专利的数目 *  * @author liuhongbo *  */public class PatentCiteCount extends Configured implements Tool {public static class PatentCiteCountMapper extendsMapper<Text, Text, Text, IntWritable> {private final IntWritable one = new IntWritable(1);@Overrideprotected void map(Text key, Text value, Context context)throws IOException, InterruptedException {context.write(value, one);}}public static class PatentCiteCountReducer extendsReducer<Text, IntWritable, Text, LongWritable> {private final LongWritable result = new LongWritable();@Overrideprotected void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException {int sum = 0;for (IntWritable value : values) {sum += value.get();}result.set(sum);context.write(key, result);}}@Overridepublic int run(String[] args) throws Exception {Job job = new Job(getConf());job.setJarByClass(getClass());job.setJobName("patentcitecount");job.setInputFormatClass(KeyValueTextInputFormat.class);job.setOutputFormatClass(TextOutputFormat.class);job.setMapperClass(PatentCiteCountMapper.class);job.setReducerClass(PatentCiteCountReducer.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(LongWritable.class);FileInputFormat.setInputPaths(job, new Path("/patent/test/input/patentcitecount.txt"));FileOutputFormat.setOutputPath(job, new Path("/patent/test/outnput"));boolean success = job.waitForCompletion(true);return success ? 0 : 1;}public static void main(String[] args) throws Exception {int result = ToolRunner.run(new PatentCiteCount(), args);System.exit(result);}}

?

热点排行